提问人:Ettore Gallina 提问时间:8/2/2021 更新时间:1/15/2022 访问量:712
Android Gradle 插件 7.0.0 和 NDK:UnsatisfiedLinkError
Android Gradle plugin 7.0.0 and NDK: UnsatisfiedLinkError
问:
我最近将 Android Gradle 插件更新到了 7.0.0 版(Gradle 版本 7.0.2)。 自从我做了这个更新后,我的原生库继续定期编译,但我的最终apk中没有生成.so文件。
事实上,运行应用程序会引发异常:
java.lang.UnsatisfiedLinkError: dalvik.system.PathClassLoader[DexPathList[[zip file "/data/app/it.Ettore.raspcontroller-2/base.apk"],nativeLibraryDirectories=[/data/app/it.Ettore.raspcontroller-2/lib/x86, /data/app/it.Ettore.raspcontroller-2/base.apk!/lib/x86, /system/lib, /vendor/lib]]] couldn't find "libf-native-lib.so"
降级到 Android Gradle 插件版本 4.2.2(Gradle 版本 6.7.1),一切正常。
这可能是 Android Gradle 插件错误还是我的错误?
build.gradle :
android {
defaultConfig {
externalNativeBuild {
cmake {
cFlags "-fvisibility=hidden"
cppFlags "-fvisibility=hidden"
}
}
ndk {
moduleName "f-native-lib"
}
sourceSets.main {
jni.srcDirs = ['src/main/c']
}
}
buildTypes {
release {
shrinkResources true
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
ndk {
debugSymbolLevel 'SYMBOL_TABLE'
}
}
}
externalNativeBuild {
cmake {
path "CMakeLists.txt"
}
}
}
CMakeList:.txt:
cmake_minimum_required(VERSION 3.4.1)
add_library( # Sets the name of the library.
f-native-lib
# Sets the library as a shared library.
SHARED
# Provides a relative path to your source file(s).
src/main/c/mydir/myfile.c
)
find_library( # Sets the name of the path variable.
log-lib
# Specifies the name of the NDK library that you want CMake to locate.
log
)
find_library( # Sets the name of the path variable.
z-lib
# Specifies the name of the NDK library that you want CMake to locate.
z
)
target_link_libraries( # Specifies the target library.
f-native-lib
# Links the target library to the log library included in the NDK.
${log-lib}
${z-lib}
)
活动:
static {
System.loadLibrary("f-native-lib");
}
答:
1赞
eSDe
9/14/2021
#1
有同样的问题,gradle 插件版本 7.0.2 解决了这个问题
评论
0赞
Anuvrat Chitranshi
1/15/2022
#2
您是否在 gradle 文件中使用 tasks.whenTaskAdded?gradle 插件 7.0.0 存在问题。参考这个。使用 7.0.2 或更高版本作为分辨率。
评论
0赞
Ettore Gallina
1/15/2022
是的,实际上我正在使用 tasks.whenTaskAdded
0赞
Anuvrat Chitranshi
1/19/2022
这就是 7.0.2 补丁发行说明(上面给出的链接)中提到的此错误的原因。
评论
abiFilters
?abiFilters 'x86', 'x86_64', 'armeabi-v7a', 'arm64-v8a'