Search code examples
android-studioandroid-ndkcocos2d-x

cocos-x 3.7+Android Studio: NDK not configured when cocos plugin is used


I've managed to compile new cocos 3.7 project under Android Studio (not easy though). When I add Facebook plugin in the project then this compilation error occurs:

Skipping task ':libcocos2dx:compileDebugAidl' as it is up-to-date (took 0.008 secs).
:libPluginProtocol:compileReleaseNdk UP-TO-DATE
:libcocos2dx:compileDebugAidl (Thread[Task worker Thread 3,5,main]) completed. Took 0.011 secs.

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':libPluginProtocol:compileReleaseNdk'.
> NDK not configured.
  Download the NDK from http://developer.android.com/tools/sdk/ndk/.Then add ndk.dir=path/to/ndk in local.properties.
  (On Windows, make sure you escape backslashes, e.g. C:\\ndk rather than C:\ndk)

* Try:
Run with --stacktrace option to get the stack trace. Run with --debug option to get more log output.

BUILD FAILED

I've added the plugin in the projects with "Import Module" and then selecting the corresponding proj.android folder.

What I've tried:

  1. setting the same compile/target/min sdk/tools versions for all modules (copying the values from previously working module)
  2. Adding ndk.dir to my project local.properties
  3. Adding ndk.dir to libPluginProtocol local.properties
  4. disabling automatic ndk-build call by jni.srcDirs = []

Changing local.properties doesn't work because these files get auto-generated and my added ndk.dir entry gets lost.

I'm compiling from the command line: cocos compile -p android --android-studio

Environment: cocos-js 3.7, ndk=r10c

Here is the peak to my generated gradle files:

project (working)

apply plugin: 'com.android.application'

android {
    compileSdkVersion 22
    buildToolsVersion "22.0.1"

    defaultConfig {
        applicationId "com.sharkintelligence.GameXY.google.full"
        minSdkVersion 10
        targetSdkVersion 22
        versionCode 1
        versionName "1.0"
    }

    sourceSets.main {
        java.srcDir "src"
        res.srcDir "res"
        jniLibs.srcDir "libs"
        manifest.srcFile "AndroidManifest.xml"
        assets.srcDir "assets"
        jni.srcDirs = [] //disable automatic ndk-build call
    }

    signingConfigs {

       release {
            if (project.hasProperty("RELEASE_STORE_FILE")) {
                storeFile file(RELEASE_STORE_FILE)
                storePassword RELEASE_STORE_PASSWORD
                keyAlias RELEASE_KEY_ALIAS
                keyPassword RELEASE_KEY_PASSWORD
            }
        }
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            if (project.hasProperty("RELEASE_STORE_FILE")) {
                signingConfig signingConfigs.release
            }
        }
    }
}

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

libcocos (working)

apply plugin: 'com.android.library'

android {
    compileSdkVersion 22
    buildToolsVersion "22.0.1"

    defaultConfig {
        minSdkVersion 10
        targetSdkVersion 22
        versionCode 1
        versionName "1.0"
    }

    sourceSets.main {
        aidl.srcDir "../java/src"
        java.srcDir "../java/src"
        manifest.srcFile "AndroidManifest.xml"
    }

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

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

libPluginProtocol (NOT working)

apply plugin: 'com.android.library'
android {
    compileSdkVersion 22
    buildToolsVersion '22.0.1'
    defaultConfig {
        minSdkVersion 10
        targetSdkVersion 22

        ndk {
            moduleName "PluginProtocolStatic"
        }
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
        }
    }
    productFlavors {
    }
}

dependencies {
}

Solution

  • answer is to set system variable ANDROID_NDK_HOME. In my case: export ANDROID_NDK_HOME=$NDK_ROOT