Android NDK-错误:任务':app:buildNative'执行失败

时间:2016-03-11 05:49:46

标签: android gradle android-ndk

我正在开发视频压缩应用程序,因此我在运行应用程序时使用NDK并收到错误。 我看到了很多stackOverflow问题(应用程序中的执行错误:buildNative),但stackOverflow解决方案不适用于此错误。

Gradle构建消息:

Gradle tasks [:app:assembleDebug]
:app:buildNative FAILED
Error:Execution failed for task ':app:buildNative'.
> A problem occurred starting process 'command 'null/ndk-build.cmd''

有人帮我解答问题吗?

的build.gradle(模块:应用)

apply plugin: 'com.android.application'

android {
    compileSdkVersion 22
    buildToolsVersion '22.0.1'
    defaultConfig {
        applicationId "com.xxxx.videocompressor"
        minSdkVersion 16
        targetSdkVersion 22
        compileOptions {
            sourceCompatibility JavaVersion.VERSION_1_7
            targetCompatibility JavaVersion.VERSION_1_7
        }


    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
        }
    }
    sourceSets.main {
        jni.srcDirs = [] // This prevents the auto generation of Android.mk
        jniLibs.srcDir 'src/main/libs'
        // This is not necessary unless you have precompiled libraries in your project.
    }
    task buildNative(type: Exec, description: 'Compile JNI source via NDK') {
        def ndkDir = android.ndkDirectory
        commandLine "$ndkDir/ndk-build.cmd",
                '-C', file('src/main/jni/').absolutePath, // Change src/main/jni the relative path to your jni source
                '-j', Runtime.runtime.availableProcessors(),
                'all',
                'NDK_DEBUG=1'
    }

    task cleanNative(type: Exec, description: 'Clean JNI object files') {
        def ndkDir = android.ndkDirectory
        commandLine "$ndkDir/ndk-build.cmd",
                '-C', file('src/main/jni/').absolutePath, // Change src/main/jni the relative path to your jni source
                'clean'
    }

    clean.dependsOn 'cleanNative'
    tasks.withType(JavaCompile) {
        compileTask -> compileTask.dependsOn buildNative
    }

    productFlavors {
    }
}

dependencies {
    compile 'com.android.support:support-v4:22.2.+'
    compile 'com.android.support:support-v4:22.2.+'
    compile 'com.android.support:appcompat-v7:22.2.+'
    compile 'com.android.support:recyclerview-v7:22.2.+'
    compile 'com.android.support:design:22.2.+'
    compile 'com.google.android.gms:play-services-ads:7.8.0'
}

1 个答案:

答案 0 :(得分:1)

而不是仅使用此

//从app目录中调用常规的ndk-build(.cmd)脚本

task ndkBuild(type: Exec) {
    if (Os.isFamily(Os.FAMILY_WINDOWS)) {
        commandLine 'ndk-build.cmd', '-C', file('src/main').absolutePath
    } else {
        commandLine 'ndk-build', '-C', file('src/main').absolutePath
    }
} 

使用此

//从app目录中调用常规的ndk-build(.cmd)脚本

    task ndkBuild(type: Exec) {
        if (Os.isFamily(Os.FAMILY_WINDOWS)) {
            commandLine 'ndk-build.cmd', '-C', file('src/main').absolutePath
        } else {
            commandLine 'ndk-build', '-C', file('src/main').absolutePath
        }
    }

   tasks.withType(JavaCompile) {
        compileTask -> compileTask.dependsOn ndkBuild
    }