2
votes

I recently moved from Eclipse to Android Studio And I keep getting compilation errors:

I get this error:

 Error:Execution failed for task ':andEngine:compileReleaseNdk'.

com.android.ide.common.internal.LoggedErrorException: Failed to run command: C:\Program Files\Android\android-ndk-r10\ndk-build.cmd NDK_PROJECT_PATH=null APP_BUILD_SCRIPT=C:\Users\myUser\AndroidstudioProjects\MyApllicationName\andEngine\build\intermediates\ndk\release\Android.mk APP_PLATFORM=android-14 NDK_OUT=C:\Users\myUser\AndroidstudioProjects\MyApllicationName\andEngine\build\intermediates\ndk\release\obj NDK_LIBS_OUT=C:\Users\myUser\AndroidstudioProjects\MyApllicationName\andEngine\build\intermediates\ndk\release\lib APP_ABI=all Error Code: 1

I set up in "local.propeties":

sdk.dir=C\:\\Program Files (x86)\\Android\\android-studio\\sdk
ndk.dir=C\:\\Program Files\\Android\\android-ndk-r10

I download the recent NDK and put it in

C\:\\Program Files\\Android\\android-ndk-r10

allso I added it to the envirenment variables under

"ANDROID_NDK" and "NDK_HOME"

What am I doing wrong? How can I compile AndEngine using android-studio?

2

2 Answers

3
votes

With Android Studio, NDK support is preliminary and your *.mk files are ignored.

To solve the issue you're encountering, you should post more information regarding your project structure and the content of your build.gradle files.

Otherwise you can make it work by setting Android Studio/gradle so it reuses your *.mk files by deactivating the default NDK integration, making it call ndk-build(.cmd) by itself, and using standard libs/ location for .so files integration, like so:

import org.apache.tools.ant.taskdefs.condition.Os

apply plugin: 'android'

android {
    compileSdkVersion 19
    buildToolsVersion "19.0.3"

    defaultConfig{
        minSdkVersion 15
        targetSdkVersion 19
        versionCode 101
        versionName "1.0.1"
    }

    sourceSets.main {
        jniLibs.srcDir 'src/main/libs'
        jni.srcDirs = [] //disable automatic ndk-build call
    }

    // call regular ndk-build(.cmd) script from app directory
    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
    }
}
2
votes

For our setup, spaces in NDK path were the issue. Moving NDK to path without spaces solved the problem for us.

We got the same error with error code 1, so I hope it will help someone with the same problem.

Our setup:

  • Gradle 2.1
  • Gradle Android plugin 0.13.2
  • Ndk r10b