【问题标题】:Android Studio: Gradle execution failed while building the NDK applicationAndroid Studio:构建 NDK 应用程序时 Gradle 执行失败
【发布时间】:2016-11-03 10:59:07
【问题描述】:

build.gradle 文件中的这部分似乎导致应用程序执行失败。

控制台上的错误信息:

Error:Execution failed for task ':app:ndkBuild'.
> Process 'command '/Users/marshall/android-sdks/ndk-bundle/ndk-build'' finished with non-zero exit value 2

ndkBuild 任务是我在build.gradle 文件中定义的任务。这是代码块。

task ndkBuild(type: Exec, description: 'Compile JNI source via NDK') {
    def ndkDir = project.plugins.findPlugin('com.android.application').sdkHandler.getNdkFolder()
    commandLine "$ndkDir/ndk-build",
            '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
}

我仔细检查了ndk存储库的目录是否正确,似乎不是失败的原因。

这是整个 build.gradle 文件的源代码。

apply plugin: 'com.android.application'

android {
    compileSdkVersion 25
    buildToolsVersion "25.0.0"
    defaultConfig {
        applicationId "com.my.project"
        minSdkVersion 21
        targetSdkVersion 25
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }

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

android {
    sourceSets {
        main {
            jni.srcDirs = []
        }
    }
}
task ndkBuild(type: Exec, description: 'Compile JNI source via NDK') {
    def ndkDir = project.plugins.findPlugin('com.android.application').sdkHandler.getNdkFolder()
    commandLine "$ndkDir/ndk-build",
            '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
}

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:design:25.0.0'
    compile 'com.android.support:cardview-v7:25.0.0'
    compile project(':openCVLibrary310')
    compile 'com.android.support:appcompat-v7:25.0.0'
}

【问题讨论】:

  • 您能否发布完整的build.gradle?您可能会在此处查看此答案。这可能是可能的情况。 stackoverflow.com/a/30692005/3145960
  • @ReazMurshed 我刚刚上传了整个build.gradle 源代码。你能看看这个吗?谢谢!!
  • 你需要在你的build.gradle中添加defaultConfig {multiDexEnabled true}
  • arrrrr 这让我抓狂!我只是尝试过这种方式,也没有工作..

标签: android android-studio android-ndk


【解决方案1】:

我通过将 Android SDK 和 NDK 路径添加到 .bash_profile 文件解决了这个问题,如下所示。

export ANDROID_HOME=/usr/local/opt/android-sdk export PATH=${PATH}:/usr/local/opt/android-ndk

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-07-18
    • 2020-10-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-06-13
    • 2015-02-06
    • 1970-01-01
    相关资源
    最近更新 更多