Android系统预装第三方apk

对于android系统预装第三方apk,分两种情况:
一、不包含so库的简单apk:
完全可以预装到system/app目录下(也就是系统app),运行时不会有找不到so库的错误;
二、包含so库的apk:
如果按照普通的apk一样预装到system/app目录(因为不做任何处理,一般都会预装到这个目录),则会报错:
java.lang.UnsatisfiedLinkError: Couldn't load libXXX from loader  .........findLibrary returned null;

对于发生这种情况的原因是system app在系统启动加载时不会加载so;要解决这个问题,目前在项目中有两种方法:

方法1:

抽取apk的so库,然后使用以下Android.mk:

LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)

$(shell mkdir -p $(PRODUCT_OUT)/system/lib)
$(shell cp -rf $(LOCAL_PATH)/lib/arm/*  $(PRODUCT_OUT)/system/lib)

#LOCAL_MODULE_TAGS := optional

LOCAL_MODULE := facebook
LOCAL_PRIVILEGED_MODULE := true
LOCAL_MULTILIB := 32
LOCAL_MODULE_CLASS := APPS
LOCAL_MODULE_SUFFIX := $(COMMON_ANDROID_PACKAGE_SUFFIX)
LOCAL_CERTIFICATE := PRESIGNED
LOCAL_PROGUARD_ENABLED := disabled
LOCAL_SRC_FILES := $(LOCAL_MODULE)$(COMMON_ANDROID_PACKAGE_SUFFIX)
include $(BUILD_PREBUILT)


# ==============================================================================

include $(call all-makefiles-under,$(LOCAL_PATH))

方法二:

不需要手动抽取so库,使用以下Android.mk:

LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)

LOCAL_MODULE := facebook
LOCAL_MODULE_CLASS := APPS
LOCAL_MODULE_TAGS := optional
LOCAL_MODULE_SUFFIX := $(COMMON_ANDROID_PACKAGE_SUFFIX)
LOCAL_SRC_FILES := $(LOCAL_MODULE).apk
LOCAL_PREBUILT_JNI_LIBS := \
@lib/armeabi/libcwatchdog.so \
@lib/armeabi/libmp3lame.so \
@lib/armeabi/libttsnotemsc.so \
@lib/armeabi/libopustoolvn.so

LOCAL_CERTIFICATE := PRESIGNED
include $(BUILD_PREBUILT)

你可能感兴趣的:(日常记录)