gpt4 book ai didi

android - Gradle 实验性 JNI OpenCv arm 64-v8a 链接器错误

转载 作者:太空宇宙 更新时间:2023-11-03 22:10:58 26 4
gpt4 key购买 nike

我有一个使用 opencv android sdk 的项目,为了加快速度,我决定用 C++ 实现一些功能。

无论如何,我正在使用 gradle 实验性插件 0.4.0 以及何时为 arm64-v8a 构建,链接器告诉我它无法在 jniLibs 文件夹中找到库。尝试了许多不同的变体,我相信路径是正确的(使用 cd 在终端上检查)

这是我的 app.gradle:

apply plugin: 'com.android.model.application' model{



android {

compileSdkVersion = 23
buildToolsVersion = "23.0.2"
/* sourceSets.main {
jniLibs.srcDir 'src/main/jniLibs' //set libs as .so's location instead of jni
jni.srcDirs = [] //disable automatic ndk-build call with auto-generated Android.mk file
}*/
defaultConfig.with {
applicationId = "com.sketchcamera.camera"
minSdkVersion.apiLevel = 15
targetSdkVersion.apiLevel = 23
versionCode = 105
versionName = "1.05"
}


}


android.buildTypes {
release {
minifyEnabled = false
proguardFiles.add(file('proguard-android.txt'))
//proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
//jniDebuggable = true
// signingConfig signingConfigs.release
}
debug {
//jniDebuggable = true
}
}
android.productFlavors {
create("AArch-64") {
ndk.with{
abiFilters.add("arm64-v8a")

File curDir = file('./')
curDir = file(curDir.absolutePath)
String libsDir = curDir.absolutePath + "/src/main/jniLibs/arm64-v8a/"

ldLibs.add(libsDir + "libopencv_core.a")
ldLibs.add(libsDir + "libopencv_highgui.a")
ldLibs.add(libsDir + "libopencv_imgproc.a")
ldLibs.add(libsDir + "libopencv_java3.so")
ldLibs.add(libsDir + "libopencv_ml.a")

}
}
create("arm") {
ndk.with{
abiFilters.add("armeabi")

File curDir = file('./')
curDir = file(curDir.absolutePath)
String libsDir = curDir.absolutePath + "/src/main/jniLibs/armeabi/"

ldLibs.add(libsDir + "libopencv_core.a")
ldLibs.add(libsDir + "libopencv_highgui.a")
ldLibs.add(libsDir + "libopencv_imgproc.a")
ldLibs.add(libsDir + "libopencv_java3.so")
ldLibs.add(libsDir + "libopencv_ml.a")

}
}
create("armv7") {
ndk.with {
abiFilters.add("armeabi-v7a")

File curDir = file('./')
curDir = file(curDir.absolutePath)
String libsDir = curDir.absolutePath + "/src/main/jniLibs/armeabi-v7a/"
ldLibs.add(libsDir + "libopencv_core.a")
ldLibs.add(libsDir + "libopencv_highgui.a")
ldLibs.add(libsDir + "libopencv_imgproc.a")
ldLibs.add(libsDir + "libopencv_java3.so")
ldLibs.add(libsDir + "libopencv_ml.a")
ldLibs.add(libsDir + "libopencv_ts.a")

}
}
}

android.ndk {
moduleName = "opencv_fast_processing"
cppFlags.add("-std=c++11")
cppFlags.add("-fexceptions")
cppFlags.add("-I${file("/home/onur/Masaüstü/Home/OpenCV-android-sdk/sdk/native/jni/include")}".toString())
ldLibs.addAll(["android", "EGL", "GLESv2", "dl", "log", "z"])
stl = "gnustl_shared"
}
// android.useLibrary = 'org.apache.http.legacy'

如果我使用 arm7 或 arm,一切都很好,但如果使用 arm64-v8a 编译,链接器会给出此错误:

/home/onur/Android/android-ndk-r11c/toolchains/aarch64-linux-android-4.9/prebuilt/linux-x86_64/bin/../lib/gcc/aarch64-linux-android/4.9/../../../../aarch64-linux-android/bin/ld: cannot find -l/home/onur/AndroidStudioProjects/SketchCamera/app/src/main/jniLibs/arm64-v8a/libopencv_core.a

其他文件也有同样的错误..正如我之前所说,我确信路径是正确的,但不知道/home 前面的 -l 是什么(对 C 和 gnu 没有太多经验)

我是 JNI 的新手,很可能做了一些愚蠢的事情。感谢您的帮助

最佳答案

我在这里遇到了同样的问题,但使用了 libcrypto (OpenSSL)。我设法通过更改我的 build.gradle 文件来解决它。而不是使用 productFlavors 我改为 repositores 部分作为以下示例:

删除这段代码:

abis {
create("x86") {
ldLibs.add("${file("src/main/jniLibs/x86/libcrypto.so")}".toString())
}
create("x86_64") {
ldLibs.add("${file("src/main/jniLibs/x86_64/libcrypto.so")}".toString())
}
create("armeabi-v7a") {
ldLibs.add("${file("src/main/jniLibs/armeabi-v7a/libcrypto.so")}".toString())
}
create("arm64-v8a") {
ldLibs.add("${file("src/main/jniLibs/armeabi-v7a/libcrypto.so")}".toString())
}
}

然后添加这个:

repositories {
prebuilt(PrebuiltLibraries) {
prebuiltSharedlib {
binaries.withType(SharedLibraryBinary) {
sharedLibraryFile = file("src/main/jniLibs/${targetPlatform.getName()}/libcrypto.so")
}
}
}
}
android.sources {
main {
jni {
dependencies {
library "prebuiltSharedlib"
}
}
}
}

最后在 ndk 部分设置 ABI 过滤器:

abiFilters.addAll(["armeabi-v7a", "arm64-v8a", "x86", "x86_64"])

希望对您有所帮助。

关于android - Gradle 实验性 JNI OpenCv arm 64-v8a 链接器错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36794477/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com