Android Studio NDK生成故障错误:任务执行失败';:应用程序:ndkBuild';

Android Studio NDK生成故障错误:任务执行失败';:应用程序:ndkBuild';,android,android-ndk,build.gradle,Android,Android Ndk,Build.gradle,我正在使用最新的android studio build 1.5,因为我想导入一个需要NDK的eclipse项目。我的项目正在进行中。我尝试导入org.apache.tools.ant.taskdefs.condition.Os,但在我构建APK时,它仍在工作,出现了错误: Error:Execution failed for task ':app:ndkBuild'. > A problem occurred starting process 'command 'ndk-build.cm

我正在使用最新的android studio build 1.5,因为我想导入一个需要NDK的eclipse项目。我的项目正在进行中。我尝试导入org.apache.tools.ant.taskdefs.condition.Os,但在我构建APK时,它仍在工作,出现了错误:

Error:Execution failed for task ':app:ndkBuild'.
> A problem occurred starting process 'command 'ndk-build.cmd''
我的身材。格雷德尔:

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

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.2"

    defaultConfig {
        applicationId "vaeapp.gamecard.vn"
        minSdkVersion 14
        targetSdkVersion 19
        multiDexEnabled = true
        versionCode 4
        versionName "1.3.4"

        ndk {
            moduleName "gc"
        }
    }
    task ndkBuild(type: Exec) {
        if (Os.isFamily(Os.FAMILY_WINDOWS)) {
            commandLine 'ndk-build.cmd', '-C', file('src/main').absolutePath
        } else {
            commandLine 'C\\:\\\\Users\\\\Android\\\\AppData\\\\Local\\\\Android\\\\sdk\\\\ndk-bundle', '-C', file('src/main/jni').absolutePath
        }
    }

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

    repositories {
        jcenter()
        maven { url "https://jitpack.io" }
    }
    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:multidex:1.0.1'
    compile 'com.android.support:appcompat-v7:23.2.0'
    compile 'com.google.code.gson:gson:2.2.4'
    compile 'org.jbundle.util.osgi.wrapped:org.jbundle.util.osgi.wrapped.org.apache.http.client:4.1.2'
    compile 'com.facebook.android:facebook-android-sdk:4.2.0'
    // compile 'com.android.support:appcompat-v7:20.0.0'
//    compile 'com.google.android.gms:play-services:+'
    compile 'com.google.android.gms:play-services:4.0.30'
    compile files('libs/activation.jar')
    compile files('libs/additionnal.jar')
    compile files('libs/commons-io-2.4.jar')
    compile files('libs/error-reporter.jar')
    //compile files('libs/httpclient-4.0.1.jar')
    compile files('libs/mail.jar')
    compile files('libs/universal-image-loader-1.9.3.jar')
    compile fileTree(dir: 'libs', include: 'Parse-*.jar')
    // compile 'com.parse:parse-android:1.10.1'
    compile 'com.parse.bolts:bolts-android:1.+'
    compile 'com.parse:parse-android:1.+'
}
My local.properties:

ndk.dir=C\:\\Users\\Android\\AppData\\Local\\Android\\sdk\\ndk-bundle
sdk.dir=C\:\\Users\\Android\\AppData\\Local\\Android\\sdk

请帮我修复错误。非常感谢你

我们使用以下包装:

task ndkBuild(type: Exec) {

    File ndkDir = project.getPlugins().getPlugin('com.android.library').sdkHandler.getNdkFolder()
    if (ndkDir == null) {
        ndkDir = file(System.getenv('NDK_ROOT'))
    }

    if (ndkDir == null) {
        def gradle_project_root = project.rootProject.rootDir
        throw new GradleException("NDK is not configured. Make sure there is a local.properties " +
                "file with an ndk.dir entry in the directory ${gradle_project_root}, or set the " +
                "ANDROID_NDK envrionment variable")
    }

    def ndkBuildExecutable = new File(ndkDir, 'ndk-build')
    if (Os.isFamily(Os.FAMILY_WINDOWS)) {
        ndkBuildExecutable += '.cmd'
    }
    if (!ndkBuildExecutable.exists()) {
        throw new GradleException("Could not find ndk-build. The configured NDK directory ${ndkDir} may not be correct.")
    }
    commandLine(ndkBuildExecutable, '-j8', '-C', file('src/main').absolutePath)
}

在gradle中,ndk build.cmd的实际路径是为非Windows平台设置的。我认为这是错误的,因为您在那里设置的路径是一条非常Windows-y的路径。而且,为了避免转义字符乘法的疯狂,您可以在gradle文件中使用正斜杠
/
来定义路径,例如
'C:/Users/Android/AppData/Local/Android/sdk/ndk bundle'
。仅确保您指定的所有路径没有空格(例如,
'C:/Program Files'
)。

我们使用以下包装器:

task ndkBuild(type: Exec) {

    File ndkDir = project.getPlugins().getPlugin('com.android.library').sdkHandler.getNdkFolder()
    if (ndkDir == null) {
        ndkDir = file(System.getenv('NDK_ROOT'))
    }

    if (ndkDir == null) {
        def gradle_project_root = project.rootProject.rootDir
        throw new GradleException("NDK is not configured. Make sure there is a local.properties " +
                "file with an ndk.dir entry in the directory ${gradle_project_root}, or set the " +
                "ANDROID_NDK envrionment variable")
    }

    def ndkBuildExecutable = new File(ndkDir, 'ndk-build')
    if (Os.isFamily(Os.FAMILY_WINDOWS)) {
        ndkBuildExecutable += '.cmd'
    }
    if (!ndkBuildExecutable.exists()) {
        throw new GradleException("Could not find ndk-build. The configured NDK directory ${ndkDir} may not be correct.")
    }
    commandLine(ndkBuildExecutable, '-j8', '-C', file('src/main').absolutePath)
}

在gradle中,ndk build.cmd的实际路径是为非Windows平台设置的。我认为这是错误的,因为您在那里设置的路径是一条非常Windows-y的路径。而且,为了避免转义字符乘法的疯狂,您可以在gradle文件中使用正斜杠
/
来定义路径,例如
'C:/Users/Android/AppData/Local/Android/sdk/ndk bundle'
。仅确保您指定的所有路径没有空格(例如,
'C:/Program Files'
)。

com.android.library这是干什么用的?@AhmadArslan:我使用本机代码主要是为了;您将使用
com.android.application
作为应用程序模块。还有其他方法可以找到ndkDir:com.android.library这是干什么用的?@AhmadArslan:我使用本机代码主要是为了;您将使用
com.android.application
作为应用程序模块。找到ndkDir还有其他方法: