我想在我的Android应用程序中包含一些本机cpp源代码。我正在使用带有gradle构建系统的Android Studio 3.0。我有三个模块:我的Android应用程序,android opencv libs,cpp源代码(在jni文件夹中)
构建过程给出了以下错误:
Error:Execution failed for task ':app:ndkBuild'.
Process 'command 'C:/Android/Sdk/ndk-bundle/ndk-build.cmd'' finished with
non-zero exit value 2
似乎路径错误,但我已经检查了ndk-build.cmd文件位置。这是我的build.gradle文件:
apply plugin: 'com.android.application'
android {
compileSdkVersion 26
defaultConfig {
applicationId "com.example.sensen.magicapp"
minSdkVersion 14
targetSdkVersion 26
versionCode 1
versionName "1.0"
testInstrumentationRunner
"android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'),
'proguard-rules.pro'
}
}
sourceSets.main {
jniLibs.srcDir 'src/main/libs'
jni.srcDirs = [] //disable automatic ndk-build call
}
task ndkBuild(type: Exec, description: 'Compile JNI source via NDK') {
commandLine "C:/Android/Sdk/ndk-bundle/ndk-build.cmd",
'NDK_PROJECT_PATH=build/intermediates/ndk',
'NDK_LIBS_OUT=src/main/jniLibs',
'APP_BUILD_SCRIPT=src/main/jni/Android.mk',
'NDK_APPLICATION_MK=src/main/jni/Application.mk'
}
tasks.withType(JavaCompile) {
compileTask -> compileTask.dependsOn ndkBuild
}
}
//add repositories
repositories {
mavenCentral()
mavenLocal()
}
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'com.android.support:appcompat-v7:26.1.0'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test.espresso:espresso-
core:3.0.1'
//add library
compile 'com.github.markushi:circlebutton:1.1'
implementation project(':openCVLibrary331')
}
我已经尝试按照本教程https://www.youtube.com/watch?v=flBlhnEd530的每一步进行操作。并按照https://www.youtube.com/watch?v=nv4MEliij14此视频的opencv设置教程。
据我所知,ndk-build应该给我一些我可以在我的应用程序中使用的.so文件。但是当地人的建设失败了。请帮我解决这个问题。谢谢你提前。