android预装应用找不到so库问题

时间:2024-10-08 09:50:02

近日接到需求,产品大佬想要在平板上预装第三方应用

接到这个平平无奇的需求的时候内心毫无波动

我直接给他装到/system/app下吧,毫无难度········紧接着就开始了写 然后编译,然后就:

连系统都起不来·······   log如下:

10-17 08:52:30.107  2747  2747 V PackageManager: reconcileAppsData for null u0 0x3 migrateAppData=true               

10-17 08:52:30.160  2747  2747 V PackageManager: reconcileAppsData finished 22 packages                              

10-17 08:52:30.161  2747  2796 D SystemServerInitThreadPool: Started executing prepareAppData                        

10-17 08:52:30.163  2747  2796 D SystemServerTimingAsync: AppDataFixup took to complete: 2ms                         

10-17 08:52:30.212  2747  2747 E System  : ******************************************                                

10-17 08:52:30.213  2747  2747 E System  : ************ Failure starting system services                             

10-17 08:52:30.213  2747  2747 E System  : : There must be exactly one installer; found [ResolveInfo{70a2edd /.InstallStart m=0x608000}, ResolveInfo{58b7a52 .phoenix2/com..install. m=0x608000}]                                                

10-17 08:52:30.213  2747  2747 E System  :      at (:3617)                                                                                    

10-17 08:52:30.213  2747  2747 E System  :      at .<init>(:3265)                                                                                                     

10-17 08:52:30.213  2747  2747 E System  :      at (:2360)                                                                                                       

10-17 08:52:30.213  2747  2747 E System  :      at (:648)                                                                                                           

10-17 08:52:30.213  2747  2747 E System  :      at (:443)        

10-17 08:52:30.213  2747  2747 E System  :      at (:304)       

10-17 08:52:30.213  2747  2747 E System  :      at (Native Method)                    

10-17 08:52:30.213  2747  2747 E System  :      at $(:493)                                                                                                       

10-17 08:52:30.213  2747  2747 E System  :      at (:891)      

10-17 08:52:30.213  2747  2747 D SystemServerTiming: StartPackageManagerService took to complete: 3524ms             

10-17 08:52:30.213  2747  2747 E AndroidRuntime: *** FATAL EXCEPTION IN SYSTEM PROCESS: main            

                                           //逼迫二选一            

10-17 08:52:30.213  2747  2747 E AndroidRuntime: : There must be exactly one installer; found [ResolveInfo{70a2edd /.InstallStart m=0x608000}, ResolveInfo{58b7a52  .phoenix2/com..install. m=0x608000}]

10-17 08:52:30.213  2747  2747 E AndroidRuntime:        at (:3617)                                                                            

10-17 08:52:30.213  2747  2747 E AndroidRuntime:        at .<init>(:3265)                                                                                             

10-17 08:52:30.213  2747  2747 E AndroidRuntime:        at (:2360)                                                                                               

10-17 08:52:30.213  2747  2747 E AndroidRuntime:        at (:648)                                                                                                   

10-17 08:52:30.213  2747  2747 E AndroidRuntime:        at (:443)

10-17 08:52:30.213  2747  2747 E AndroidRuntime:        at (:304)10-17 08:52:30.213  2747  2747 E AndroidRuntime:        at (Native Method)            

10-17 08:52:30.213  2747  2747 E AndroidRuntime:        at $(:493)                                                                                               

10-17 08:52:30.213  2747  2747 E AndroidRuntime:        at (:891)                                                                                                                    

10-17 08:52:30.214  2747  2747 E AndroidRuntime: Error reporting crash                                               

10-17 08:52:30.214  2747  2747 E AndroidRuntime: : Attempt to invoke interface method 'void (, $ParcelableCrashInfo)' on a null object reference                                                                            

10-17 08:52:30.214  2747  2747 E AndroidRuntime:        at $(:143)                                                                              

10-17 08:52:30.214  2747  2747 E AndroidRuntime:        at (:1068)                                                                                                                  

10-17 08:52:30.214  2747  2747 E AndroidRuntime:        at (:1063)                                                                                                                  

10-17 08:52:30.214  2747  2747 E AndroidRuntime:        at (:1955)

 

没想到android也搞当年3Q大战二选一的套路······  豌豆荚这个流氓声明了installer, 所以系统不允许有两个。  但是我们不可能放弃原生的packageinstaller,所以不能装在/system/app目录下

 

 

那装在/data目录下吧,然后就去搜索了五花八门预装到/data分区的方法,都要改系统代码·······   想想还是算了,太麻烦了。那就预装到/vendor目录下吧。

所以就在中添加:

LOCAL_MODULE_PATH := $(TARGET_OUT_VENDOR)/app

然后编译,烧录,紧接着····

 

????????

然后看了代码发现:

// Collect ordinary vendor packages.

File vendorAppDir = new File((), "app");

try {

    vendorAppDir = ();

catch (IOException e) {

    // failed to look up canonical path, continue with original one

}

scanDirTracedLI(vendorAppDir,

        mDefParseFlags

        | PackageParser.PARSE_IS_SYSTEM_DIR,

        scanFlags

        | SCAN_AS_SYSTEM   //系统应用属性

        | SCAN_AS_VENDOR,

        0);

预装到/vendor/app目录下 仍然算是系统应用·····   所以还会和原生的packageinstaller冲突。本着不改系统代码的原则,只能再换其他目录了·······    之后就发现了:

if (( & ApplicationInfo.FLAG_SYSTEM) == 0) {

   // M:operator app also is removable and not system flag

   if ((!())) {

   continue;

   }

}

如上所说在operator目录下的应用非系统应用并且可以卸载,这不就是我们想要的结果吗??  android 9 预装apk可卸载

修改:

 

/*

scanDirTracedLI(privilegedVendorAppDir,

        mDefParseFlags

        | PackageParser.PARSE_IS_SYSTEM_DIR,

        scanFlags

        | SCAN_AS_SYSTEM

        | SCAN_AS_VENDOR

        | SCAN_AS_PRIVILEGED,

        0);

*/

 scanDirTracedLI(privilegedVendorAppDir,

        mDefParseFlags

        | PackageParser.PARSE_IS_SYSTEM_DIR,

        scanFlags                   

        | SCAN_AS_VENDOR

        | SCAN_AS_PRIVILEGED,

        0);

这样,将apk预放在  android9-8mm\out\target\product\evk_8mm\vendor\priv-app 下,整编后烧录,

apk已经在系统里面了,而且可以卸载,可以卸载,可以卸载!!!

 

参考资料:

/p/992766525cf1

 

今晚打老唬:mtk 可以放在vendor/operator/app 里面就可以卸载了。需要在如下文件中配置下。 P版本需要添加vendor/mediatek/proprietary/frameworks/base / data/etc/pms_sysapp_removable_vendor_list.txt

 

不修改系统代码的前提下,那咱们就开开心心的把应用预制到/vendor/operator/app目录下吧,添加:

LOCAL_MODULE_PATH := $(TARGET_OUT_VENDOR)/operator/app

然后编译烧录,结果·······

 

找不到so库····  好吧那我就按照大佬的方法提取出来

 

LOCAL_PATH := $(call my-dir)

 

include $(CLEAR_VARS)

 

LOCAL_MODULE := Wandoujia

LOCAL_SRC_FILES := $(LOCAL_MODULE).apk

LOCAL_MODULE_CLASS := APPS

LOCAL_MODULE_TAGS := optional

LOCAL_MODULE_SUFFIX := $(COMMON_ANDROID_PACKAGE_SUFFIX)

LOCAL_CERTIFICATE := PRESIGNED

#LOCAL_DEX_PREOPT := false

LOCAL_PREBUILT_JNI_LIBS= \

    lib/armeabi/libalicleaner.so \

    lib/armeabi/libanb.so \

    lib/armeabi/libbase64encoder_v1_4.so \

    lib/armeabi/libc++_shared.so \

    lib/armeabi/libcocktail_1.0. \

    lib/armeabi/libcrashsdk.so \

    lib/armeabi/libdalvikhack.so \

    lib/armeabi/libdalvikpatch.so \

    lib/armeabi/libfoem.so \

    lib/armeabi/libhiddenApiFxxxer.so \

    lib/armeabi/libIncrementalUpdate.so \

    lib/armeabi/libmmdb.so \

    lib/armeabi/libmmkv.so \

    lib/armeabi/libpl_droidsonroids_gif.so \

    lib/armeabi/libppapkpatchso.so \

    lib/armeabi/libppkkdb.so \

    lib/armeabi/libpppmtools.so \

    lib/armeabi/libppsu.so \

    lib/armeabi/libqc-cyt.so \

    lib/armeabi/libreleaseCatcher.so \

    lib/armeabi/libsgmain.so \

    lib/armeabi/libsgsecuritybody.so \

    lib/armeabi/libsss.so \

    lib/armeabi/libtnet-3.1. \

    lib/armeabi/libwdj_udid.so \

    lib/armeabi/libweexcore.so \

    lib/armeabi/libweexjsb.so \

    lib/armeabi/libweexjss.so \

    lib/armeabi/libweexjst.so \

    lib/armeabi/libweibosdkcore.so

LOCAL_MODULE_PATH := $(TARGET_OUT_VENDOR)/operator/app

include $(BUILD_PREBUILT)

 

然后再一款设备上就神奇地安装上了,运行没有任何问题

然后产品又说,要在另一款设备上也装上,那我就全部copy过来不就行了?

 

结果··········

 

10-16 10:06:50.532  4963  4981 I ActivityManager: Start proc 6520:.phoenix2:aid/u0a75 for content provider .phoenix2/com.                                         

10-16 10:06:50.534  6470  6470 W WeexJSBridgeThr: type=1400 audit(0.0:1210): avc: denied { open for path="/data/app-lib/Wandoujia/" dev="dm-2" ino=3194905 scontext=u:r:untrusted_app_25:s0:c512,c768 tcontext=u:object_r:system_data_file:s0 tclass=file permissive=0                                                                            

10-16 10:06:50.535  6470  6519 E weex    : weexjss's Path is/vendor/operator/app/Wandoujia/Wandoujia.apk!/lib/armeabi/libweexjss.so                                                                                                        

10-16 10:06:50.584  6520  6520 W ia.phoenix2:ai:  in APK '/vendor/operator/app/Wandoujia/' is compressed.                                                                                                       

10-16 10:06:50.794  4963  4981 I ActivityManager: Start proc 6579:.phoenix2:channel/u0a75 for broadcast .phoenix2/com.                                                                  

10-16 10:06:50.870  6579  6579 W hoenix2:channe:  in APK '/vendor/operator/app/Wandoujia/' is compressed.                                                                                                       

10-16 10:06:51.259  4963  5325 W ActivityManager: Unable to start service Intent { pkg=.phoenix2 cmp=.phoenix2/com.$KernelService } U=0: not found                                     

10-16 10:06:51.396  6579  6686 I hoenix2:channe: Caused by: : Didn't find class "" on path: DexPathList[[zip file "/system/framework/", zip file "/system/framework/", zip file "/system/framework/", zip file "/vendor/operator/app/Wandoujia/"],nativeLibraryDirectories=[/data/app-lib/Wandoujia/system/fake-libs/vendor/operator/app/Wandoujia/Wandoujia.apk!/lib/armeabi/system/lib]]                                                           

10-16 10:06:51.397  6579  6686 I hoenix2:channe: Caused by: : Didn't find class "" on path: DexPathList[[zip file "/system/framework/", zip file "/system/framework/", zip file "/system/framework/", zip file "/vendor/operator/app/Wandoujia/"],nativeLibraryDirectories=[/data/app-lib/Wandoujia/system/fake-libs/vendor/operator/app/Wandoujia/Wandoujia.apk!/lib/armeabi/system/lib]]                                                           

10-16 10:06:51.398  6579  6686 I hoenix2:channe: Caused by: : Didn't find class "" on path: DexPathList[[zip file "/system/framework/", zip file "/system/framework/", zip file "/system/framework/", zip file "/vendor/operator/app/Wandoujia/"],nativeLibraryDirectories=[/data/app-lib/Wandoujia/system/fake-libs/vendor/operator/app/Wandoujia/Wandoujia.apk!/lib/armeabi/system/lib]]                                                           

10-16 10:06:51.467  6470  6708 I chatty  : uid=10075(.phoenix2) JunkScan-thread identical 4 lines       

10-16 10:06:52.294  6470  6519 E weex    : findLibJssRealPath /data/user/0/com.wandoujia.phoenix2/cache/libweexjss.so

10-16 10:06:52.295  6470  6519 E weex    : getLibJssPath is running /data/user/0/com.wandoujia.phoenix2/cache/libweexjss.so                                                                                                                

10-16 10:06:52.296  6470  6519 E WeexCore: g_jssSoPath is /data/user/0/com.wandoujia.phoenix2/cache/libweexjss.so    

10-16 10:06:52.974  6520  6520 W Thread-5: type=1400 audit(0.0:1249): avc: denied { open for path="/data/app-lib/Wandoujia/" dev="dm-2" ino=3194889 scontext=u:r:untrusted_app_25:s0:c512,c768 tcontext=u:object_r:system_data_file:s0 tclass=file permissive=0                                                                                    

10-16 10:06:52.982  6520  6520 W ia.phoenix2:aid: type=1400 audit(0.0:1250): avc: denied { open for path="/data/app-lib/Wandoujia/" dev="dm-2" ino=3194907 scontext=u:r:untrusted_app_25:s0:c512,c768 tcontext=u:object_r:system_data_file:s0 tclass=file permissive=0                                                                         

10-16 10:06:53.006  6520  6520 W Thread-7: type=1400 audit(0.0:1251): avc: denied { open for path="/data/app-lib/Wandoujia/" dev="dm-2" ino=3194889 scontext=u:r:untrusted_app_25:s0:c512,c768 tcontext=u:object_r:system_data_file:s0 tclass=file permissive=0                                                                                    

10-16 10:06:53.018  6520  6520 W pool-4-thread-1: type=1400 audit(0.0:1252): avc: denied { open for path="/data/app-lib/Wandoujia/" dev="dm-2" ino=3194889 scontext=u:r:untrusted_app_25:s0:c512,c768 tcontext=u:object_r:system_data_file:s0 tclass=file permissive=0                                                                             

10-16 10:06:54.245  4963  4963 W system_server:  in APK '/vendor/operator/app/Wandoujia/' is compressed.

 

奇了怪了,明明代码都是同一套,莫非是供应商做了什么骚操作???? 看到上面的log并在  惊厥下   觉得可能是selinux问题,八成是这两个中的一个被改过SElinux, 赶紧搜一搜untrusted_app_25,果然有发现:

 device/mediatek/sepolicy/basic/non_plat/untrusted_app.te

#modify_lwf_add

typeattribute system_data_file mlstrustedobject;

allow untrusted_app_27 system_data_file:file r_file_perms;

allow untrusted_app_27 system_data_file:file execute;

allow untrusted_app_25 system_data_file:file r_file_perms;

allow untrusted_app_25 system_data_file:file execute;

#modify_lwf_end

然后就添加上了····· 然后就好了

 

然后网上一搜发现也有人遇到同样的问题:MTK6757 9.0 APK预置vendor/operator/app 无法正常工作

 

参考:

一篇文章看明白 Android PackageManagerService 工作流程

预置第三方apk到系统中, 关于32/64位so库兼容的问题

android Linker:namespace隔离机制

动态链接库加载原理及HotFix方案