在Android Studio中使用NDK时构建失败

时间:2016-04-12 14:31:34

标签: android android-studio android-ndk opencv4android

我正在尝试使用OpenCV4Android + Android Studio + NDK制作Android应用程序。

我尝试了多种解决方案,但在尝试构建应用时仍然出现以下错误:

Executing tasks: [:app:generateDebugSources,    :app:generateDebugAndroidTestSources, :app:assembleDebug]

Configuration on demand is an incubating feature.
:app:preBuild UP-TO-DATE
:app:preDebugBuild UP-TO-DATE
:app:checkDebugManifest
:app:preReleaseBuild UP-TO-DATE
:libraries:opencv:compileLint
:libraries:opencv:copyReleaseLint UP-TO-DATE
:libraries:opencv:mergeReleaseProguardFiles UP-TO-DATE
:libraries:opencv:preBuild UP-TO-DATE
:libraries:opencv:preReleaseBuild UP-TO-DATE
:libraries:opencv:checkReleaseManifest
:libraries:opencv:prepareReleaseDependencies
:libraries:opencv:compileReleaseAidl UP-TO-DATE
:libraries:opencv:compileReleaseRenderscript UP-TO-DATE
:libraries:opencv:generateReleaseBuildConfig UP-TO-DATE
:libraries:opencv:generateReleaseAssets UP-TO-DATE
:libraries:opencv:mergeReleaseAssets UP-TO-DATE
:libraries:opencv:generateReleaseResValues UP-TO-DATE
:libraries:opencv:generateReleaseResources UP-TO-DATE
:libraries:opencv:packageReleaseResources UP-TO-DATE
:libraries:opencv:processReleaseManifest UP-TO-DATE
:libraries:opencv:processReleaseResources UP-TO-DATE
:libraries:opencv:generateReleaseSources UP-TO-DATE
:libraries:opencv:processReleaseJavaRes UP-TO-DATE
:libraries:opencv:compileReleaseJavaWithJavac UP-TO-DATE
:libraries:opencv:packageReleaseJar UP-TO-DATE
:libraries:opencv:compileReleaseNdk UP-TO-DATE
:libraries:opencv:packageReleaseJniLibs UP-TO-DATE
:libraries:opencv:packageReleaseLocalJar UP-TO-DATE
:libraries:opencv:packageReleaseRenderscript UP-TO-DATE
:libraries:opencv:bundleRelease UP-TO-DATE
:app:prepareComAndroidSupportAppcompatV72310Library UP-TO-DATE
:app:prepareComAndroidSupportSupportV42310Library UP-TO-DATE
:app:prepareFaceDetectionLibrariesOpencvUnspecifiedLibrary UP-TO-DATE
:app:prepareDebugDependencies
:app:compileDebugAidl UP-TO-DATE
:app:compileDebugRenderscript UP-TO-DATE
:app:generateDebugBuildConfig UP-TO-DATE
:app:generateDebugAssets UP-TO-DATE
:app:mergeDebugAssets UP-TO-DATE
:app:generateDebugResValues UP-TO-DATE
:app:generateDebugResources UP-TO-DATE
:app:mergeDebugResources UP-TO-DATE
:app:processDebugManifest UP-TO-DATE
:app:processDebugResources UP-TO-DATE
:app:generateDebugSources UP-TO-DATE
:app:preDebugAndroidTestBuild UP-TO-DATE
:app:prepareDebugAndroidTestDependencies
:app:compileDebugAndroidTestAidl UP-TO-DATE
:app:processDebugAndroidTestManifest UP-TO-DATE
:app:compileDebugAndroidTestRenderscript UP-TO-DATE
:app:generateDebugAndroidTestBuildConfig UP-TO-DATE
:app:generateDebugAndroidTestAssets UP-TO-DATE
:app:mergeDebugAndroidTestAssets UP-TO-DATE
:app:generateDebugAndroidTestResValues UP-TO-DATE
:app:generateDebugAndroidTestResources UP-TO-DATE
:app:mergeDebugAndroidTestResources UP-TO-DATE
:app:processDebugAndroidTestResources UP-TO-DATE
:app:generateDebugAndroidTestSources UP-TO-DATE
:app:ndkBuild FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:ndkBuild'.
> A problem occurred starting process 'command   'C:\Users\Mansi_PC\Downloads\android-ndk-r10e\ndk-build.cmd'

这是我的Gradle文件:

import org.apache.tools.ant.taskdefs.condition.Os
apply plugin: 'com.android.application'

android {
compileSdkVersion 23
buildToolsVersion "23.0.2"

defaultConfig {
    applicationId "com.androidsrc.facedetection"
    minSdkVersion 19
    targetSdkVersion 23
    versionCode 1
    versionName "1.0"

    sourceSets.main {
        //   jniLibs.srcDir 'src/main/libs' //set .so files directory to libs
        jni.srcDirs = [] //disable automatic ndk-build call
    }

    project.ext.versionCodes = ['armeabi': 1, 'armeabi-v7a': 2, 'arm64-v8a': 3, 'mips': 5, 'mips64': 6, 'x86': 8, 'x86_64': 9]
    //versionCode digit for each supported ABI, with 64bit>32bit and x86>armeabi-*
    android.applicationVariants.all { variant ->
        // assign different version code for each output
        variant.outputs.each { output ->
            output.versionCodeOverride =
                    project.ext.versionCodes.get(output.getFilter(com.android.build.OutputFile.ABI), 0) * 1000000 + defaultConfig.versionCode
        }
    }
    // call regular ndk-build(.cmd) script from app directory
    task ndkBuild(type: Exec) {
        if (Os.isFamily(Os.FAMILY_WINDOWS)) {
            commandLine 'C:\\Users\\Mansi_PC\\Downloads\\android-ndk-r10e\\ndk-build.cmd', '-C', file('src/main/jni').absolutePath
        } else {
            commandLine 'C:\\Users\\Mansi_PC\\Downloads\\android-ndk-r10e\\ndk-build', '-C', file('src/main/jni').absolutePath
        }
    }

    tasks.withType(JavaCompile) {
        compileTask -> compileTask.dependsOn ndkBuild
    }
}
buildTypes {
    release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
}

}

dependencies {
   compile fileTree(dir: 'libs', include: ['*.jar'])
   testCompile 'junit:junit:4.12'
   compile 'com.android.support:appcompat-v7:23.1.0'
   compile project(':libraries:opencv')
}

这是我的Android.mk

LOCAL_PATH := $(call my-dir)

#OPENCV_CAMERA_MODULES:=off
#OPENCV_INSTALL_MODULES:=off
#OPENCV_LIB_TYPE:=SHARED
include F:\softwares\opencvandroid\OpenCV-android-sdk\sdk\native\jni\OpenCV.mk

LOCAL_CFLAGS := F:\softwares\opencvandroid\OpenCV-android-sdk\sdk\native\jni\include -Wall -Werror
LOCAL_SRC_FILES  := BOWTrainer_jni.cpp
LOCAL_C_INCLUDES += F:\softwares\opencvandroid\OpenCV-android-sdk\sdk\native\jni\include
LOCAL_STATIC_LIBRARIES+ := F:\softwares\opencvandroid\OpenCV-android-sdk\sdk\native\libs\armeabi-v7a\libopencv_core.a
LOCAL_STATIC_LIBRARIES+ := F:\softwares\opencvandroid\OpenCV-android-sdk\sdk\native\libs\armeabi-v7a\libopencv_features2d.a
LOCAL_STATIC_LIBRARIES+ := F:\softwares\opencvandroid\OpenCV-android-sdk\sdk\native\libs\armeabi-v7a\libopencv_flann.a
LOCAL_LDLIBS     += -llog -ldl

LOCAL_MODULE     := bow_trainer

include $(BUILD_SHARED_LIBRARY)

P.S。 - 我在local.properties文件中设置了ndk路径。        另外,在gradle.properties中我有" android.useDeprecatedNdk = true"

我尝试了所有可能的解决方案 谁能告诉我我做错了什么?

Android Studio - 2.0 NDK - android-ndk-r10e

0 个答案:

没有答案