"JNI FatalError called: Unable to load library"
"JNI FatalError called: Unable to load library"
我有一个配置为动态功能模块的统一项目。这可以按需完美安装。但是当我 运行 它时,应用程序崩溃并出现以下错误:
JNI FatalError called: Unable to load library: /data/app/com.example.app-8fx1RRZrQ34BcwXf8ajjqZ==/lib/arm64/libunity.so [dlopen failed: library "libunity.so" not found]
Unity工程的目标activity包括SplitCompat.install(this);
它 gradle 看起来像:
// GENERATED BY UNITY. REMOVE THIS COMMENT TO PREVENT OVERWRITING WHEN EXPORTING AGAIN
buildscript {
repositories {
mavenCentral()
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.5.0'
}
}
allprojects {
repositories {
mavenCentral()
google()
jcenter()
flatDir {
dirs 'libs'
}
}
}
apply plugin: 'com.android.dynamic-feature'
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
}
android {
compileSdkVersion rootProject.compileSdk
buildToolsVersion rootProject.buildTools
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
defaultConfig {
minSdkVersion rootProject.minSdk
targetSdkVersion rootProject.targetSdk
versionCode rootProject.versionCode
versionName rootProject.versionName
ndk {
abiFilters 'armeabi-v7a', 'arm64-v8a'
}
}
lintOptions {
abortOnError false
}
aaptOptions {
noCompress = ['.unity3d', '.ress', '.resource', '.obb']
}
flavorDimensions "default"
productFlavors {
staging {
dimension "default"
}
production {
dimension "default"
}
develop {
dimension "default"
}
}
compileOptions {
sourceCompatibility 1.8
targetCompatibility 1.8
}
buildTypes {
debug {
minifyEnabled false
useProguard false
jniDebuggable true
}
release {
minifyEnabled false
useProguard false
}
}
packagingOptions {
doNotStrip '*/armeabi-v7a/*.so'
doNotStrip '*/arm64-v8a/*.so'
// doNotStrip '*/x86/*.so'
}
}
dependencies {
implementation project(':app')
}
而应用模块的 gradle 有:
bundle {
language {
// Specifies that the app bundle should not support
// configuration APKs for language resources. These
// resources are instead packaged with each base and
// dynamic feature APK.
enableSplit = false
}
density {
// This property is set to true by default.
enableSplit = false
}
abi {
// This property is set to true by default.
enableSplit = true
}
}
我什至尝试通过在 gradle.properties 文件中设置 android.bundle.enableUncompressedNativeLibs = false 来禁用 .so 压缩,但确切的错误仍然存在。
aab 中功能模块的内部结构。存在 .so 库:
我该如何解决这个问题?
更新 1 -
我上面描述的问题是在第一次从 Play 商店安装 aab 时发生的。请注意,我能够成功安装功能模块,并且仅当我尝试 运行 时才会出现错误。但是,当我在同一个安装上推送增量更新时,功能模块能够以某种方式完美地工作并且能够找到必要的 .so 文件。我已经多次重复这些步骤来验证观察结果。
确保在动态功能模块中使用 SplitCompat 加载了统一库:https://developer.android.com/guide/app-bundle/playcore#load_native_libs
我不确定这是否由 Unity 自动处理,但如果是,您可能想联系他们解决这个问题。
我还在日志文件中看到“调用 JNI 致命错误:无法加载库 .../libunity.so”。
就我而言,我注意到 Unity 记录了一个关于无法读取 bin/Data/settings.xml 文件的错误。我将这些目录和文件添加到我的项目资产中,然后 libunity 库就可以加载了。因此,即使您可能会看到一条消息说 libunity.so 文件未找到,但问题实际上是统一库无法正确初始化。
我有一个配置为动态功能模块的统一项目。这可以按需完美安装。但是当我 运行 它时,应用程序崩溃并出现以下错误:
JNI FatalError called: Unable to load library: /data/app/com.example.app-8fx1RRZrQ34BcwXf8ajjqZ==/lib/arm64/libunity.so [dlopen failed: library "libunity.so" not found]
Unity工程的目标activity包括SplitCompat.install(this);
它 gradle 看起来像:
// GENERATED BY UNITY. REMOVE THIS COMMENT TO PREVENT OVERWRITING WHEN EXPORTING AGAIN
buildscript {
repositories {
mavenCentral()
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.5.0'
}
}
allprojects {
repositories {
mavenCentral()
google()
jcenter()
flatDir {
dirs 'libs'
}
}
}
apply plugin: 'com.android.dynamic-feature'
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
}
android {
compileSdkVersion rootProject.compileSdk
buildToolsVersion rootProject.buildTools
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
defaultConfig {
minSdkVersion rootProject.minSdk
targetSdkVersion rootProject.targetSdk
versionCode rootProject.versionCode
versionName rootProject.versionName
ndk {
abiFilters 'armeabi-v7a', 'arm64-v8a'
}
}
lintOptions {
abortOnError false
}
aaptOptions {
noCompress = ['.unity3d', '.ress', '.resource', '.obb']
}
flavorDimensions "default"
productFlavors {
staging {
dimension "default"
}
production {
dimension "default"
}
develop {
dimension "default"
}
}
compileOptions {
sourceCompatibility 1.8
targetCompatibility 1.8
}
buildTypes {
debug {
minifyEnabled false
useProguard false
jniDebuggable true
}
release {
minifyEnabled false
useProguard false
}
}
packagingOptions {
doNotStrip '*/armeabi-v7a/*.so'
doNotStrip '*/arm64-v8a/*.so'
// doNotStrip '*/x86/*.so'
}
}
dependencies {
implementation project(':app')
}
而应用模块的 gradle 有:
bundle {
language {
// Specifies that the app bundle should not support
// configuration APKs for language resources. These
// resources are instead packaged with each base and
// dynamic feature APK.
enableSplit = false
}
density {
// This property is set to true by default.
enableSplit = false
}
abi {
// This property is set to true by default.
enableSplit = true
}
}
我什至尝试通过在 gradle.properties 文件中设置 android.bundle.enableUncompressedNativeLibs = false 来禁用 .so 压缩,但确切的错误仍然存在。
aab 中功能模块的内部结构。存在 .so 库:
我该如何解决这个问题?
更新 1 -
我上面描述的问题是在第一次从 Play 商店安装 aab 时发生的。请注意,我能够成功安装功能模块,并且仅当我尝试 运行 时才会出现错误。但是,当我在同一个安装上推送增量更新时,功能模块能够以某种方式完美地工作并且能够找到必要的 .so 文件。我已经多次重复这些步骤来验证观察结果。
确保在动态功能模块中使用 SplitCompat 加载了统一库:https://developer.android.com/guide/app-bundle/playcore#load_native_libs
我不确定这是否由 Unity 自动处理,但如果是,您可能想联系他们解决这个问题。
我还在日志文件中看到“调用 JNI 致命错误:无法加载库 .../libunity.so”。
就我而言,我注意到 Unity 记录了一个关于无法读取 bin/Data/settings.xml 文件的错误。我将这些目录和文件添加到我的项目资产中,然后 libunity 库就可以加载了。因此,即使您可能会看到一条消息说 libunity.so 文件未找到,但问题实际上是统一库无法正确初始化。