安装Gradle

$ brew update
$ brew install gradle

创建化gradle

$ cd $COCOS2DX-ROOT
$ gradle init

修改build.gradle,替换成

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:0.9.+'
    }
}

修改settings.gradle,替换成/p>


include ‘:cocos2d:platform:android:java’
include ‘:projects:xxxx:proj.android’

创建build.gradle,保存至cocos2dx/platform/android/java里

apply plugin: 'android-library'

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

android {
    compileSdkVersion 19
    buildToolsVersion "19.0.3"

    sourceSets {
        main {
            manifest.srcFile 'AndroidManifest.xml'
            java.srcDirs = ['src']
            resources.srcDirs = ['src']
            aidl.srcDirs = ['src']
            renderscript.srcDirs = ['src']
            res.srcDirs = ['res']
            assets.srcDirs = ['assets']
        }
    }
}

创建build.gradle保存至项目中

apply plugin: 'android'

repositories {
    mavenCentral()
}

dependencies {
    compile fileTree(dir: 'libs', include: '*.jar')
    compile fileTree(dir: "libs/armeabi", include: '*/so')
    compile project(':cocos2dx:platform:android:java')
}

// 编译so动态库
task ndkBuild(type: Exec) {
    commandLine './build_native.sh', 'NDK_DEBUG=1', 'NDK_APPLICATION_MK=jni/Application.mk', '-j4'
}

android {
    compileSdkVersion 19
    buildToolsVersion "19.0.3"

    defaultConfig {
        minSdkVersion 9
        targetSdkVersion 19
    }

    sourceSets {
        main {
            manifest.srcFile 'AndroidManifest.xml'
            java.srcDirs = ['src']
            resources.srcDirs = ['src']
            aidl.srcDirs = ['src']
            renderscript.srcDirs = ['src']
            res.srcDirs = ['res']
            assets.srcDirs = ['assets']
            jniLibs.srcDirs = ['libs']
        }
    }
}

编译

$ gradle ndkBuild
$ gradle installDebug