Update升级包中内置第三方app案例


Update升级包中内置第三方app案例

1. 介绍

Amlogic MX8726 5iHome项目,客户提出需求在固件中预制第三方app
请列出开发的项目,项目简单背景,使用的平台,待总结的内容简述

2. 总结内容

2.1 问题现象:

客户提供第三方app直接使用U盘pm install YouKu_CIBN.apk ,app正常运行
app放在patch preinstall/app 目录下,编译system/app/YouKu_CIBN.apk
YouKu_CIBN 闪退

2.2 原因分析:

logcat -v time 查看打印

java.lang.UnsatisfiedLinkError: 
Couldn‘t load mono from loader dalvik.system.PathClassLoader[DexPathList[[zip file "/system/app/5iHomeBadminton.apk"],
nativeLibraryDirectories=[/vendor/lib, /system/lib]]]: findLibrary returned null

缺少库文件,但pm insatll安装可以正常运行,咨询同事system/app/目录下apk安装模式不是pm install方式,其具体采用的哪种模式….下次填坑

2.3 解决方案:

既然Youku_CIBN.apk使用pm install 模式可以正常运行,可以在系统在刷机后第一次启动后,可以尝试后台运行service安装一次Youku.apk

youku.apk放置到目录vendor\amlogic\prebuilt\preinstallation并修改Android.mk与Preinstall.sh

Android.mk

LOCAL_PATH:= $(call my-dir)

include $(CLEAR_VARS)
LOCAL_MODULE := preinstall.sh
LOCAL_SRC_FILES := preinstall.sh
LOCAL_MODULE_TAGS := optional
LOCAL_MODULE_CLASS := ETC
LOCAL_MODULE_PATH := $(TARGET_OUT)/bin
include $(BUILD_PREBUILT)


#manager_apk := $(patsubst $(LOCAL_PATH)/%,%,$(wildcard $(LOCAL_PATH)/*.apk))
manager_apk := youku_cibn.apk

$(foreach t,$(manager_apk), $(eval include $(CLEAR_VARS)) $(eval LOCAL_MODULE     := $(notdir $(t))) $(eval LOCAL_MODULE_TAGS := optional) $(eval LOCAL_MODULE_CLASS := ETC) $(eval LOCAL_MODULE_PATH := $(TARGET_OUT)/preinstall) $(eval LOCAL_SRC_FILES   := $(t)) $(eval LOCAL_CERTIFICATE := shared) $(eval include $(BUILD_PREBUILT)) )

$(LOCAL_INSTALLED_MODULE): $(notdir $(manager_apk))

preinstall.sh

#!/system/bin/sh

//标记文件symbol_preinstall_apks_installed
MARK=/data/local/symbol_preinstall_apks_installed
PKGS=/system/preinstall/

//判断标记文件symbol_preinstall_apks_installed是否存在
if [ ! -e $MARK ]; then
echo "booting the first time, so pre-install some APKs."

    apk_list=$(busybox find $PKGS -name "*\.apk")
    echo $apk_list
    for apk in $apk_list
    do 
        echo "install: " $apk
        mkdir -p /data/app
        cp -f $apk /data/app/app_to_install.apk
        chmod 644 /data/app/app_to_install.apk
        /system/bin/pm install -r /data/app/app_to_install.apk
        rm /data/app/app_to_install.apk
    done

# NO NEED to delete these APKs since we keep a mark under data partition.
# And the mark will be wiped out after doing factory reset, so you can install
# these APKs again if files are still there.
# busybox rm -rf $PKGS

touch $MARK
echo "OK, installation complete."
fi

2.4 后续工作中须注意细节:

  • Android.mk与preinstall.sh编码格式必须使用UNIX
  • update.zip升级时必须恢复出厂设置,原因,开机执行preinstal.sh 会先判断MARK=/data/local/symbol_preinstall_apks_installed标志文件是否存在,如存在会退出执行,但客户提出update.zip升级恢复出厂设置给用户带来不便利,只需修改 MARK=/data/local/(*)

3. 扩展阅读

开机执行preinstall.sh,需在开机init.amlogic.board.rc中注册与start

start preinstall

service preinstall /system/bin/preinstall.sh
    user root       //改变用户归属
    group root      //改变用户归属
    disabled        //服务必须显式启动
    oneshot         //指明不能重启服务

编译出来app在不同的目录区别

  • system/app 内置app放置目录
  • system/priv-app系统核心app放置目录,权限最高 (Android 4.4才有)
  • system/preinstall 预安装第三方app

system/preinstall目录中app,默认刷机后第一次启动安装,与U盘直接安装效果相同,安装后app位置在data/app

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。