Build command failed.
Error while executing process G:\Sdk\cmake\3.10.2.4988404\bin\ninja.exe with arguments {-C F:\android\ByMySelf\app\.cxx\cmake\debug\arm64-v8a native-lib}
ninja: Entering directory `F:\android\ByMySelf\app\.cxx\cmake\debug\arm64-v8a'
[1/2] Building CXX object CMakeFiles/native-lib.dir/src/main/cpp/native-lib.cpp.o
[2/2] Linking CXX shared library ..\..\..\..\build\intermediates\cmake\debug\obj\arm64-v8a\libnative-lib.so
FAILED: ../../../../build/intermediates/cmake/debug/obj/arm64-v8a/libnative-lib.so 
cmd.exe /C "cd . && G:\Sdk\ndk\20.1.5948944\toolchains\llvm\prebuilt\windows-x86_64\bin\clang++.exe --target=aarch64-none-linux-android21 --gcc-toolchain=G:/Sdk/ndk/20.1.5948944/toolchains/llvm/prebuilt/windows-x86_64 --sysroot=G:/Sdk/ndk/20.1.5948944/toolchains/llvm/prebuilt/windows-x86_64/sysroot -fPIC -g -DANDROID -fdata-sections -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -fno-addrsig -Wa,--noexecstack -Wformat -Werror=format-security   -O0 -fno-limit-debug-info -fno-experimental-isel  -Wl,--exclude-libs,libgcc.a -Wl,--exclude-libs,libatomic.a -Wl,--build-id -Wl,--warn-shared-textrel -Wl,--fatal-warnings -Wl,--no-undefined -Qunused-arguments -Wl,-z,noexecstack -shared -Wl,-soname,libnative-lib.so -o ..\..\..\..\build\intermediates\cmake\debug\obj\arm64-v8a\libnative-lib.so CMakeFiles/native-lib.dir/src/main/cpp/native-lib.cpp.o  ../../../../src/main/jniLibs/arm64-v8a/libopencv_java3.so -ljnigraphics -llog -latomic -lm && cd ."
CMakeFiles/native-lib.dir/src/main/cpp/native-lib.cpp.o: In function `Java_com_example_bymyself_NDKInterface_ORBDET':
F:\android\ByMySelf\app\.cxx\cmake\debug\arm64-v8a/../../../../src/main/cpp/native-lib.cpp:126: undefined reference to `cv::drawKeypoints(cv::_InputArray const&, std::__ndk1::vector<cv::KeyPoint, std::__ndk1::allocator<cv::KeyPoint> > const&, cv::_InputOutputArray const&, cv::Scalar_<double> const&, int)'
clang++: error: linker command failed with exit code 1 (use -v to see invocation)
ninja: build stopped: subcommand failed.

解决方案 »

  1.   

    链接库失败,你的Gradle是不是美配置好,你的opencv是哪个版本的?arm64-v8a有的版本没有.
      

  2.   

    opencv版本是3.4.7
    gradle配置:
    apply plugin: 'com.android.application'android {
        compileSdkVersion 29
        buildToolsVersion "29.0.2"
        defaultConfig {
            applicationId "com.example.bymyself"
            minSdkVersion 15
            targetSdkVersion 29
            versionCode 1
            versionName "1.0"
            testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
            externalNativeBuild {
                cmake {
                    cppFlags ""
                    arguments "-DANDROID_STL=c++_shared"
                }
            }
            ndk {
                abiFilters 'x86_64', 'arm64-v8a','armeabi-v7a','x86'
            }
        }
        buildTypes {
            release {
                minifyEnabled false
                proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
            }
        }
        externalNativeBuild {
            cmake {
                path "CMakeLists.txt"
                version "3.10.2"
            }
        }
        sourceSets { main { jni.srcDirs = ['src/main/jni', 'src/main/jni/'] } }
    }dependencies {
        implementation fileTree(dir: 'libs', include: ['*.jar'])
        implementation fileTree(dir: "$buildDir/native-libs", include: 'native-libs.jar')
        implementation 'androidx.appcompat:appcompat:1.1.0'
        implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
        testImplementation 'junit:junit:4.12'
        androidTestImplementation 'androidx.test.ext:junit:1.1.1'
        androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
        implementation project(path: ':openCVLibrary347')
    }
    task nativeLibsToJar(type: Jar, description: 'creat a jar archive of the native libs') {
        destinationDir file("$buildDir/native-libs")
        baseName 'native-libs'
        from fileTree(dir: 'libs', include: '**/*.so')
        into 'lib/'
    }tasks.withType(JavaCompile) {
        compileTask -> compileTask.dependsOn(nativeLibsToJar)
    }