Cocos2d-x 2.2.6 to gradle?

Cocos2d-x 2.2.6 to gradle?
0.0 0

#1

@nite @slackmoehrle

Hi,

Is there way to easy make cocos2d-x 2.2.6 compile thru Android studio/gradle - by copy pasting cocos2d-x 3.x gradle configuration files?

Is cocos2d-x 3.15 console is capable of compiling cocos2d-x 2.2.6 with gradle setup?

We want to make update for older project made on cocos2d-x 2.x - but this is really pain as no Android SDK or Eclipse not supporting anymore ant builds ;( and it will be hard to manage new integrations - so looking for gradle setup :confused:


#2

Is it something working solution?

http://blog.kasajei.com/entry/2015/04/05/AndroidStuido%26coco2d-x_ver2_2_6でgradleビルドする方法


#3

I think you can ref to bellow folders:

~/test/cpp3151$ find . -name "build.gradle"
./cocos2d/cocos/platform/android/libcocos2dx/build.gradle
./proj.android-studio/app/build.gradle
./proj.android-studio/build.gradle

#4

@zhangxm do you know any team in china has compiled 2.2.6 with android studio?


#5

No, i haven’t heard that.
@energyy you can still use ant, just copy tools folder from older Android SDK.


#6

no, we now hate ant :smiley: after using gradle.

@nite @zhangxm
Good news:) I managed to make it working with Android studio/gradle - so I can compile project from Android studio and from console using cocos2d-x 3.15.1 console :slight_smile:

Actually it is very easy to do if u know what to do:D even thinking that u can add android studio support to 2.2.6 an release it :slight_smile:

I managed to make it working with project setup from cocos 3.14 and 3.15 :wink:

To make 2.2.6 compile in gradle as cocos 3.14 version:

  1. Using NDK 10, Cocos2d-x 3.15.1 console which supports latest adnroid sdk.

  2. Copying from 3.14 project folder file .cocos-project.json to 2.2.6 project folder (as cocos console checking for this file)

  3. Copying from 3.14 project folder proj.android-studio to 2.2.6 project

  4. Replacing in proj.android-studio main.h file in JNI folder to original one from proj.android

  5. Most tricky part was to change build-cfg.json inside proj.android-studio:

    {
    “ndk_module_path” :[
    “…/…/…/cocos2dx”,
    “…/…/…/external”,
    “…/…/…/cocos2dx/platform/third_party/android/prebuilt”,
    “…/…/…/extensions”,
    “…/…/…/CocosDenshion/android”

     ],
     "copy_resources": [
         {
             "from": "../Resources",
             "to": ""
         }
     ]
    

    }

  6. Copying folder from cocos 3.14 cocos2d/cocos/platform/android/libcocos2dx to cocos2d-x-2.2.6/cocos2dx/platform/android/libcocos2dx - it contains build.gradle from cocos - so after that u just need to adjust in settings.gradle path to point cocos2d-x-2.2.6/cocos2dx/platform/android/libcocos2dx

After that I managed to compile project, also made it working with build.gradle from cocos 3.15 to make it able compile from Android Studio directly, also imported SDKBOX and Fabric and it also worked :slight_smile:

Also good news that I can compile cocos2d-x 2.2.6 IOS project with latest Xcode 8.3.3 - so it works together still :slight_smile:

Example of build.gradle from app folder if u want to use fabric, Android-studio direct compile in cocos 2.2.6:

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




buildscript {
    repositories {
        jcenter()
        maven { url 'https://maven.fabric.io/public'
        }
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:2.2.3'
        // The Fabric Gradle plugin uses an open ended version to
        // react quickly to Android tooling updates
        classpath 'io.fabric.tools:gradle:1.+'
    }
}


apply plugin: 'com.android.application'
apply plugin: 'io.fabric'



repositories {
    jcenter()
    maven { url 'https://maven.fabric.io/public' }

    flatDir{
        dirs 'heyzap'
    }
}



android {
    compileSdkVersion 22
    buildToolsVersion "25.0.0"

    defaultConfig {
        applicationId "com.test.game2048"
        minSdkVersion 16
        targetSdkVersion 22
        versionCode 1
        versionName "1.0"

        externalNativeBuild {
            ndkBuild {
                if (!project.hasProperty("PROP_NDK_MODE") || PROP_NDK_MODE.compareTo('none') != 0) {
                    // skip the NDK Build step if PROP_NDK_MODE is none
                    targets 'cocos2dcpp'
                    arguments 'NDK_TOOLCHAIN_VERSION=4.9'
                    arguments 'APP_PLATFORM=android-16'

                    def module_paths = [project.file("../../../../cocos2dx").absolutePath,
                                        project.file("../../../../external").absolutePath,
                                        project.file("../../../../extensions").absolutePath,
                                        project.file("../../../../cocos2dx/platform/third_party/android/prebuilt").absolutePath,
                                        project.file("../../../../CocosDenshion/android").absolutePath,
                    ]
                    if (Os.isFamily(Os.FAMILY_WINDOWS)) {
                        // should use '/'
                        module_paths = module_paths.collect {it.replaceAll('\\\\', '/')}
                        arguments 'NDK_MODULE_PATH=' + module_paths.join(";")
                    }
                    else {
                        arguments 'NDK_MODULE_PATH=' + module_paths.join(':')
                    }

                    arguments '-j' + Runtime.runtime.availableProcessors()
                    abiFilters.addAll(PROP_APP_ABI.split(':').collect{it as String})
                }
            }
        }
    }


    lintOptions {
        checkReleaseBuilds false
        // Or, if you prefer, you can continue to check for errors in release builds,
        // but continue the build even when errors are found:
        abortOnError false
    }


    sourceSets.main {
        java.srcDir "src"
        res.srcDir "res"
        manifest.srcFile "AndroidManifest.xml"
        assets.srcDir "../../Resources"
        jniLibs.srcDirs = ['libs']

    }

    externalNativeBuild {
        ndkBuild {
            if (!project.hasProperty("PROP_NDK_MODE") || PROP_NDK_MODE.compareTo('none') != 0) {
                // skip the NDK Build step if PROP_NDK_MODE is none
                path "jni/Android.mk"
            }
        }
    }

    dexOptions {
        javaMaxHeapSize "4g"
    }

    splits {
        abi {
            enable true
            reset()
            include 'armeabi'
            universalApk false
        }
    }

    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
            }

            externalNativeBuild {
                ndkBuild {
                    arguments 'NDK_DEBUG=0'
                }
            }
        }

        debug {
            externalNativeBuild {
                ndkBuild {
                    arguments 'NDK_DEBUG=1'
                }
            }
        }
    }
}



crashlytics {
    enableNdk true
    androidNdkOut 'build/intermediates/ndkBuild/release/obj/local'
    androidNdkLibsOut 'build/intermediates/ndkBuild/release/obj/local'
}



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





    // Crashlytics Kit
    compile('com.crashlytics.sdk.android:crashlytics:2.6.8@aar') {
        transitive = true
    }
    // NDK Kit
    compile('com.crashlytics.sdk.android:crashlytics-ndk:1.1.6@aar') {
        transitive = true
    }
}

#7

Could you help me on this ? Maybe tell me more about the 2-5 steps, thanks!


#8

For 3.14 project I mean hello world project generated using cocos2d-x 3.14 version


Android Studio and cocos2d-x v2.2.6