Android Studio失败构建NDK项目非零退出值2

时间:2017-10-05 20:38:26

标签: java android android-ndk

我在我的项目中使用带有ndk的库,每当我想构建我的项目时它都会显示此错误

  

错误:任务执行失败':tess-two:ndkBuild'。   处理' C:\ android-ndk-r14b / ndk-build.cmd''完成非零退出值2

我的 build.gradle

apply plugin: 'com.android.library'

android {
    compileSdkVersion 23
    buildToolsVersion '25.0.0'

    defaultConfig {
        minSdkVersion 8
        targetSdkVersion 22
        versionCode 1
        versionName "1.0"

    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }

    sourceSets {
        main {
            manifest.srcFile 'AndroidManifest.xml'
            java.srcDirs = ['src']
            res.srcDirs = ['res']
            jni.srcDirs = []
            jniLibs.srcDirs = ['libs']
        }
    }



    // Call external ndk-build(.cmd) script to build the native code
     task ndkBuild(type: Exec) {
         def ndkBuildExt = Os.isFamily(Os.FAMILY_WINDOWS) ? ".cmd" : ""
         commandLine "${android.ndkDirectory}/ndk-build${ndkBuildExt}",
                 '-C', file('.').absolutePath,
                 '-j', Runtime.runtime.availableProcessors()

        // commandLine 'C:\\android-ndk-r14b', '-C', file('src/main/jni').absotePath
     }

 tasks.withType(JavaCompile) {
         compileTask -> compileTask.dependsOn ndkBuild
     }
     // Cleanup task to remove previously generated binaries
     task ndkClean(type: Exec) {
         def ndkBuildExt = Os.isFamily(Os.FAMILY_WINDOWS) ? ".cmd" : ""
         commandLine "${android.ndkDirectory}/ndk-build${ndkBuildExt}",
                 '-C', file('.').absolutePath, 'clean'
     }

     tasks.withType(Delete) {
         cleanTask -> cleanTask.dependsOn ndkClean
     }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
}


// Settings for uploading module AAR to Bintray for library distribution

task sourcesJar(type: Jar) {
    from android.sourceSets.main.java.srcDirs
    classifier = 'sources'
}

task javadoc(type: Javadoc) {
    source = android.sourceSets.main.java.srcDirs
    classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
    options {
        links "http://docs.oracle.com/javase/7/docs/api/"
        linksOffline "http://d.android.com/reference","${android.sdkDirectory}/docs/reference"
    }
}

task javadocJar(type: Jar, dependsOn: javadoc) {
    classifier = 'javadoc'
    from javadoc.destinationDir
}

artifacts {
    archives javadocJar
    archives sourcesJar
}


Properties properties = new Properties()
properties.load(project.rootProject.file('local.properties').newDataInputStream())

我的 local.properties

ndk.dir = C:\机器人-NDK-R14B

sdk.dir = C:\ Users \ Studio - PC \ AppData \ Local \ Android \ Sdk

1 个答案:

答案 0 :(得分:0)

使用'gradlew assDebug --info'获取更多日志。 您可能会发现问题所在。