2016-05-12 262 views
0

我使用最新的android studio build 1.5,因爲我想導入一個需要NDK的eclipse項目。我的項目正在工作。我嘗試進口org.apache.tools.ant.taskdefs.condition.Os但它工作時,我建APK,它使錯誤:Android Studio NDK構建錯誤:執行任務失敗':app:ndkBuild'

Error:Execution failed for task ':app:ndkBuild'. 
> A problem occurred starting process 'command 'ndk-build.cmd'' 

我的build.gradle:

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.+' 
} 

我的地方.properties:

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

請幫我修復錯誤。非常感謝!

回答

0

我們使用以下包裝:

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')。

+0

com.android.library這是幹什麼用的? –

+1

@AhmadArslan:我主要使用本地代碼[庫模塊](https://developer.android.com/studio/projects/android-library.html);你將使用'com.android.application'作爲應用程序模塊。還有其他方法可以找到** ndkDir **:http://stackoverflow.com/questions/21999829/how-do-i-read-properties-defined-in-local-properties-in-build-gradle –

相關問題