项目背景
应用依赖的jar包存在动态加载Dex,而且Dex依赖so文件。
依赖的so路径为context.getApplicationInfo().nativeLibraryDir
动态加载部分代码如下:
String libraryPath = context.getApplicationInfo().nativeLibraryDir;
DexClassLoader dexClassLoader = new DexClassLoader(dexPath, optimizedDirectoryPath, libraryPath, context.getClassLoader());
Grale配置:
Android Gradle Plugin Version: 4.0.1
Gradle Version:6.1.1
项目build.gradle
注意,这里设置
minSdkVersion 22
android {
compileSdkVersion 29
buildToolsVersion "29.0.3"
defaultConfig {
applicationId "com.jc.demoset4"
minSdkVersion 22
targetSdkVersion 29
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
...
}
找不到so问题
把
minSdkVersion
设置成23
,安装应用报找不到so
项目build.gradle如下:
android {
compileSdkVersion 29
buildToolsVersion "29.0.3"
defaultConfig {
applicationId "com.jc.demoset4"
minSdkVersion 23
targetSdkVersion 29
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
...
}
安装运行发现应用崩溃,日志如下:
java.lang.UnsatisfiedLinkError: dalvik.system.DexClassLoader[DexPathList[[dex file
"/data/user/0/com.jc.demoset4/files/nepcore.dex"],nativeLibraryDirectories=
[/data/app/com.jc.demoset4-2/lib/arm