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
@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
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
I managed to make it working with project setup from cocos 3.14 and 3.15
To make 2.2.6 compile in gradle as cocos 3.14 version:
Using NDK 10, Cocos2d-x 3.15.1 console which supports latest adnroid sdk.
Copying from 3.14 project folder file .cocos-project.json to 2.2.6 project folder (as cocos console checking for this file)
Copying from 3.14 project folder proj.android-studio to 2.2.6 project
Replacing in proj.android-studio main.h file in JNI folder to original one from proj.android
Most tricky part was to change build-cfg.json inside proj.android-studio:
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
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
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
}
}
@energyy thanks for the steps, but why are you referring to both cocos 3.14 and 3.15? Is it possible to do all steps with latest cocos2dx version (3.17.1) instead? As I will work on latest android studio (3.3.1)
I think 3.16 + little changed compile script and gradle files - I would recommend first to make it working as I described and then update gradle files logic to 3.17 - most probably even there is no difference only some cosmetic code changes