【发布时间】:2021-10-07 21:01:03
【问题描述】:
我最近将 Android Gradle 插件更新到了版本 7.0.0(Gradle 版本 7.0.2)。 自从我进行了这次更新,我的原生库继续定期编译,但在我的最终 apk 中没有生成 .so 文件。
其实,运行app就抛出异常:
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");
}
【问题讨论】:
-
是否尝试过明确列出您要使用
abiFilters构建的 ABI? -
是的@Michael,我尝试添加
abiFilters 'x86', 'x86_64', 'armeabi-v7a', 'arm64-v8a',但不幸的是问题仍然存在。 -
这里有同样的问题。 Gradle 4.2.2 一切正常,但升级到 7.0.0 后出现同样的错误。
-
这里也一样。降级 Gradle 解决了这个问题。谢谢@Rene 的提示。
-
您好!你有关于这个问题的任何更新吗? Gradle Plugin 7 似乎只构建了我的原生库的 32 位版本。 Gradle Plugins 4.2.2 没有观察到任何问题
标签: android gradle cmake android-ndk android-gradle-plugin