项目场景:
作为系统App启动异常之
java.lang.UnsatisfiedLinkError: dlopen failed: library “libopencv_java3.so” not found
问题描述:
将apk 放到system/app下作为启动App,启动时异常报错加载不到第三方库相关的.so文件
捕捉异常日志分析
2021-03-21 20:06:30
SUPPORTED_64_BIT_ABIS=[Ljava.lang.String;@3fd2815
versionCode=23
BOARD=msm8909
BOOTLOADER=unknown
TYPE=userdebug
ID=LMY47V
TIME=1614138391000
BRAND=qcom
TAG=Build
SERIAL=543e9bdb
HARDWARE=qcom
SUPPORTED_ABIS=[Ljava.lang.String;@2a3ea72a
CPU_ABI=armeabi-v7a
RADIO=unknown
IS_DEBUGGABLE=true
MANUFACTURER=unknown
SUPPORTED_32_BIT_ABIS=[Ljava.lang.String;@3050bdcc
TAGS=release-key
CPU_ABI2=armeabi
UNKNOWN=unknown
USER=ppdy
FINGERPRINT=qcom/msm8909/msm8909:5.1.1/LMY47V/ppdy02241145:userdebug/release-key
HOST=ppdy-HP-EliteBook-8570w
PRODUCT=msm8909
versionName=v2.0.3
DISPLAY=XY8901P1_V0.2
MODEL=msm8909
DEVICE=msm8909
java.lang.UnsatisfiedLinkError: dlopen failed: library "libopencv_java3.so" not found
at java.lang.Runtime.loadLibrary(Runtime.java:371)
at java.lang.System.loadLibrary(System.java:988)
at com.ppdy.news7001.storage.doImage.doImageJni.<clinit>(doImageJni.java:17)
at com.ppdy.news7001.storage.doImage.doImageRepositoryImpl.<init>(doImageRepositoryImpl.java:23)
at com.zddx.mvp.presenter.NewTestPresenter.<init>(NewTestPresenter.java:181)
at com.zddx.di.module.NewTestModule.provideNewTestPresenter(NewTestModule.java:39)
at com.zddx.di.module.NewTestModule_ProvideNewTestPresenterFactory.provideNewTestPresenter(NewTestModule_ProvideNewTestPresenterFactory.java:41)
at com.zddx.di.component.DaggerNewTestComponent.getNewTestPresenter(DaggerNewTestComponent.java:33)
at com.zddx.di.component.DaggerNewTestComponent.injectNewTestFragment(DaggerNewTestComponent.java:40)
at com.zddx.di.component.DaggerNewTestComponent.inject(DaggerNewTestComponent.java:37)
at com.zddx.mvp.fragments.NewTestFragment.initData(NewTestFragment.java:732)
at com.zddx.mvp.fragments.NewTestFragment.onFragmentFirstVisible(NewTestFragment.java:204)
at com.zddx.mvp.fragments.ViewPagerBaseFragment.onViewCreated(ViewPagerBaseFragment.java:113)
at com.zddx.mvp.fragments.NewTestFragment.onViewCreated(NewTestFragment.java:175)
重点:
java.lang.UnsatisfiedLinkError: dlopen failed: library "libopencv_java3.so" not found
at java.lang.Runtime.loadLibrary(Runtime.java:371)
at java.lang.System.loadLibrary(System.java:988)
猜想:
将apk 放到system/app下导致的加载不到第三方库相关的.so文件
验证:
1. 解压 news7001.apk
共 12 个 .so文件
2. 查看 /system/app/news7001下的lib文件夹中.so文件详情
共 9 个 .so文件
**
对比发现 “libopencv_java3.so” 确实未被加载
**
解决方案:
将 apk 的 .so文件复制到 /system/lib 中
步骤:
1. root, 获取 root 权限
E:\PPDY\git-ppdyns-android20200927\git-ppdyns-android>adb root
restarting adbd as root
2. remount, 重新挂载 system 分区
E:\PPDY\git-ppdyns-android20200927\git-ppdyns-android>adb remount
remount succeeded
3. push, 推送(复制).so文件到 /system/lib 文件夹下
E:\PPDY\git-ppdyns-android20200927\git-ppdyns-android>adb push C:\Users\PPDY\Desktop\so\libopencv_java3.so /system/lib
C:\Users\PPDY\Desktop\so\libopencv_java3.so: 1 file pushed, 0 skipped. 3.6 MB/s (10969196 bytes in 2.878s)
4. reboot, 重启
E:\PPDY\git-ppdyns-android20200927\git-ppdyns-android>adb reboot
参考文章:
<<将第三方apk变成系统apk>> https://blog.51cto.com/670176656/1608687