Xcode 5.1 编译 Android 源码错误

升级Xcode后,在编译android 4.4.2是出现如下错误:

SyntaxError: Unable to find any JNI methods for org/chromium/ui/gfx/BitmapHelper.

解决方法有两个:

  • 回退xcode版本

  • 修改文件external/base/android/jni_generator/jni_generator.py :

    +import platform
    -p = subprocess.Popen(args=[‘cpp’, ‘-fpreprocessed’],
    +system = platform.system()
    +if system == ‘Darwin’:
    + cpp_args = [‘cpp’]
    +else:
    + cpp_args = [‘cpp’, ‘-fpreprocessed’]
    +p = subprocess.Popen(args=cpp_args,
    + stdin=subprocess.PIPE,
    + stdout=subprocess.PIPE,
    + stderr=subprocess.PIPE)
    

OSX 切换 JAVA 版本

OSX 10.9.4

查看当前Java版本

java -version
java version "1.7.0_51"
Java(TM) SE Runtime Environment (build 1.7.0_51-b13)
Java HotSpot(TM) 64-Bit Server VM (build 24.51-b03, mixed mode)

查看系统可用的Java版本

/usr/libexec/java_home -v "1.6*"
/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home

导出JAVA HOME

export JAVA_HOME=`/usr/libexec/java_home -v '1.6*'`

查看更改后的JAVA版本

java -version

java version "1.6.0_65"
Java(TM) SE Runtime Environment (build 1.6.0_65-b14-466.1-11M4716)
Java HotSpot(TM) 64-Bit Server VM (build 20.65-b04-466.1, mixed mode)

AOSP 使用 GMS Location Service

AOSP现在跟GMS真是一毛钱关系都没有了。但是如果没有GMS,在AOSP上就用不了网络定位功能(当然在国内最好还是baidu、高德,既快又准)。当你在AOSP上安装了完整的GMS以后,会发现网络定位还是不能用,查看log是因为签名不正确导致Network Location service无法启动。对这个问题的解决方案如下: 打开frameworks/base/core/res/res/values/config.xml配置文件,定位到<string-array name=”config_locationProviderPackageNames” translatable=”false”>。这个文件的原始内容为:

<string-array name="config_locationProviderPackageNames" translatable="false">
          <!-- The standard AOSP fused location provider -->
          <item>com.android.location.fused</item>
</string-array>

系统只会调用在这里注册过的Location Provider,所以需要把GMS的Location Provider在这里注册一下,修改后的内容如下:

<string-array name="config_locationProviderPackageNames" translatable="false">
          <!-- GMS location provider -->                                                                                                           
          <item>com.google.android.gms</item>
          <!-- The standard AOSP fused location provider -->
          <item>com.android.location.fused</item>
</string-array>

修改完成后重新编译framework然后push到机器。 Done!

PS:经测试发现,GMS Location Provider只需要GmsCore.apk,GoogleServicesFramework.apk这两个apk即可。你可以把他们放在vender/google/gms目录下,建立一个Android.mk,内容如下:

LOCAL_PATH:= $(call my-dir) 

include $(CLEAR_VARS)
LOCAL_MODULE_TAGS := optional
LOCAL_MODULE := GmsCore.apk
LOCAL_MODULE_CLASS := APPS
LOCAL_PRIVILEGED_MODULE := true
LOCAL_CERTIFICATE := PRESIGNED
LOCAL_MODULE_PATH := $(TARGET_OUT)/priv-app
LOCAL_SRC_FILES := GmsCore.apk
include $(BUILD_PREBUILT)
 
include $(CLEAR_VARS)
LOCAL_MODULE_TAGS := optional
LOCAL_MODULE := GoogleServicesFramework.apk
LOCAL_MODULE_CLASS := APPS
LOCAL_PRIVILEGED_MODULE := true
LOCAL_CERTIFICATE := PRESIGNED
LOCAL_MODULE_PATH := $(TARGET_OUT)/priv-app
LOCAL_SRC_FILES := GoogleServicesFramework.apk
include $(BUILD_PREBUILT)              

这样以后编译image的时候就会自动预装了。

Google 搜索高级技巧

Alt none

Alt none

Alt none

Android 获取当前活动activity的信息

PackageManager mPackageManager = getApplication().getPackageManager();
ActivityManager mActivityManager = (ActivityManager) getApplicationContext()
                .getSystemService(Context.ACTIVITY_SERVICE);

//get current active activity for user
List<RunningTaskInfo> runningTaskInfos = mActivityManager.getRunningTasks(1);
        RunningTaskInfo taskInfo = runningTaskInfos.get(0);
        ComponentName cn = taskInfo.topActivity;

try {
     ActivityInfo activityInfo = mPackageManger.getActivityInfo(cn, 0);
     //here: something other activity attributes you want
     if((activityInfo.flags & ActivityInfo.FLAG_EXCLUDE_FROM_RECENTS) != 0) {
         return 0;
     }
} catch (NameNotFoundException e) {
            e.printStackTrace();
}