Android预制应用

Android Intel平台预制APK:确保APK是x86版本 ,用压缩软件打开apk,拉出lib文件

例如,AdobeFlashPlayer.apk可以如下集成

1.预制APk到system分区

LOCAL_PATH := $(call my-dir)
# AdobeFlashPlayer
##########################################################################
include $(CLEAR_VARS)
LOCAL_MODULE := AdobeFlashPlayer
LOCAL_MODULE_TAGS := optional
LOCAL_SRC_FILES := $(LOCAL_MODULE).apk
LOCAL_MODULE_CLASS := APPS
LOCAL_MODULE_SUFFIX := $(COMMON_ANDROID_PACKAGE_SUFFIX)
LOCAL_CERTIFICATE := PRESIGNED
#LOCAL_PRIVILEGED_MODULE := true
#LOCAL_OVERRIDES_PACKAGES := Launcher2
#LOCAL_MODULE_PATH := $(TARGET_OUT_DATA_APPS)
LOCAL_REQUIRED_MODULES := libflashplayer \
                          libstagefright_froyo \
                          libstagefright_honeycomb \
                          libysshared
include $(BUILD_PREBUILT)
###########################################################################
include $(CLEAR_VARS)
LOCAL_PREBUILT_LIBS := libflashplayer.so \
                       libstagefright_froyo.so \
                       libstagefright_honeycomb.so \
                       libysshared.so
LOCAL_MODULE_TAGS := optional
include $(BUILD_MULTI_PREBUILT)

在项目mk文件中添加:
PRODUCT_PACKAGES += \
    AdobeFlashPlayer

其中:
LOCAL_MODULE_PATH := $(TARGET_OUT_DATA_APPS) 放置到data/app下面
TARGET_OUT_DATA_APPS,是在build/core/envsetup.mk中定义的。
LOCAL_OVERRIDES_PACKAGES := Launcher2 可以覆盖Launcher2
LOCAL_PRIVILEGED_MODULE := true 放置到system/priv-app下面
如果APP需要system level的permission,则需要放到priv-app下面。比如:
关于获取副SD卡的写入权限的案例,App需要在AndroidManifest.xml申明WRITE_MEDIA_STORAGE permission获取副卡的写入权限
<uses-permission android:name="android.permission.WRITE_MEDIA_STORAGE" />

2.预制APK到可以卸载data分区

按照以前经验使用LOCAL_MODULE_PATH := $(TARGET_OUT_DATA_APPS)可以解决此问题,但是在实际使用中,如果apk在data/app下没有直接放到data/app下,而是在比如模块名的文件夹下,在使用过程中,会crash,提示找不到odex。所以,使用方法二。

LOCAL_PATH := $(call my-dir)
# AdobeFlashPlayer
##########################################################################
include $(CLEAR_VARS)
LOCAL_MODULE := AdobeFlashPlayer
LOCAL_MODULE_TAGS := optional
LOCAL_SRC_FILES := $(LOCAL_MODULE).apk
LOCAL_MODULE_CLASS := APPS
LOCAL_MODULE_SUFFIX := $(COMMON_ANDROID_PACKAGE_SUFFIX)
LOCAL_CERTIFICATE := PRESIGNED
#LOCAL_PRIVILEGED_MODULE := true
LOCAL_MODULE_PATH := $(TARGET_OUT_DATA_APPS)
LOCAL_REQUIRED_MODULES := libflashplayer \
                          libstagefright_froyo \
                          libstagefright_honeycomb \
                          libysshared
include $(BUILD_PREBUILT)

方法二:
直接copy文件到data/app下。

在项目mk文件中添加:
$(shell (vendor/bluebank/qinghuatongfang/copy_file.sh))

copy_file.sh文件:

#!/bin/bash

mkdir -p out/target/product/${TARGET_PRODUCT}/data/app
cp -r vendor/bluebank/qinghuatongfang/app/ out/target/product/${TARGET_PRODUCT}/data/

方法三:
此方法预制的APP可以通过手动安装覆盖掉原来的APP。

使用mk中的PRODUCT_COPY_FILES

PRODUCT_COPY_FILES += \
    $(call find-copy-subdir-files,*.apk,$(LOCAL_PATH)/backupapp,system/backupapp)

会提示如下错误,

build/core/Makefile:34: *** Prebuilt apk found in PRODUCT_COPY_FILES:
vendor/bluebank/qinghuatongfang/app/backupapp/cajviewer.apk:
system/backupapp/cajviewer.apk, use BUILD_PREBUILT instead!.  Stop.

修改build/core/Makefile

#define check-product-copy-files
#$(if $(filter %.apk, $(1)),$(error \
# Prebuilt apk found in PRODUCT_COPY_FILES: $(1), use BUILD_PREBUILT #instead!))
#endef

3.预制APK到可以卸载,可以恢复

copy apk到system/vendor/backupapp

#!/bin/bash

mkdir -p out/target/product/${TARGET_PRODUCT}/data/app
mkdir -p out/target/product/${TARGET_PRODUCT}/system/vendor/
cp -r vendor/bluebank/qinghuatongfang/app/dataapp/app out/target/product/${TARGET_PRODUCT}/data/
cp -r vendor/bluebank/qinghuatongfang/app/backupapp/ out/target/product/${TARGET_PRODUCT}/system/vendor/

在init.rc中添加Service

service loadbackupapk /system/bin/loadbackupapk.sh
    user system
    group system
    oneshot

并且在post-fs-data下启动这个Service

on post-fs-data
    mkdir /data/app 0771 system system
    start loadbackupapk

在项目mk文件中添加:

PRODUCT_COPY_FILES += \
    vendor/bluebank/qinghuatongfang/loadbackupapk.sh:system/bin/loadbackupapk.sh

loadbackupapk.sh文件实现在onboot中开机从system/vendor/backupapp中copy apk到/data/app下面。
loadbackupapk.sh:

#!/system/bin/sh
PRELOAD_DEST=/data/app
PRELOAD_FLAG=${PRELOAD_DEST}/backupapp_state
PRELOAD_SOURCE=/system/vendor/backupapp

if [ ! -d ${PRELOAD_DEST} ]
then
    mkdir -p ${PRELOAD_DEST}
fi

if [ ! -f ${PRELOAD_FLAG} ]
then
    files=$(ls ${PRELOAD_SOURCE}/)
    for i in ${files};do
        cp ${PRELOAD_SOURCE}/${i} ${PRELOAD_DEST}/${i}
        chmod 755 ${PRELOAD_DEST}/${i}
    done
    echo "installed" > ${PRELOAD_FLAG}
fi

results matching ""

    No results matching ""