Hi,
I am pretty new here as a “signed user” but I have been using cocos for over 4 month now.
I am currently trying to build cocos using the new gradle-experimental plugin, and it has been quite a chore. I am not yet done but still, things are building up. (note that I am using the gradle-experimental-0.6.0-alpha3 version atm)
I just wanted to share my progress (and get a bit of help if you feel like so).
Here are some basic references for building:
- (gradle 2.9 documentation) https://docs.gradle.org/current/userguide/nativeBinaries.html
- (gradle experimental doc, very messy) http://tools.android.com/tech-docs/new-build-system/gradle-experimental
Here are the build.gradle file I have at the moment (many errors in linkage, but no syntax/ compilation error):
apply plugin: 'com.android.model.library'
model {
repositories {
libs(PrebuiltLibraries) {
chipmunk {
headers.srcDir "../../../../external/chipmunk/include"
binaries.withType(SharedLibraryBinary) {
//
// NOTE: this block should be "StaticLibraryBinary"/staticLibraryFile - but SharedLibraryBinary works and StaticLibraryBinary doesn't as of 0.6.0-alpha2
// bug reported here: https://code.google.com/p/android/issues/detail?id=196065
//
sharedLibraryFile = file("../../../../external/chipmunk/prebuilt/android/${targetPlatform.getName()}/libchipmunk.a")
}
}
freetype2 {
headers.srcDir "../../../../external/freetype2/include/android/freetype2"
binaries.withType(SharedLibraryBinary) {
sharedLibraryFile = file("../../../../external/freetype2/prebuilt/android/${targetPlatform.getName()}/libfreetype.a")
}
}
curl {
headers.srcDir "../../../../external/curl/include/android/curl"
binaries.withType(SharedLibraryBinary) {
sharedLibraryFile = file("../../../../external/curl/prebuilt/android/${targetPlatform.getName()}/libcurl.a")
}
}
}
}
android {
compileSdkVersion = 21
buildToolsVersion = "23.0.2"
defaultConfig.with {
minSdkVersion.apiLevel = 9
targetSdkVersion.apiLevel = 9
}
}
android.buildTypes {
release {
minifyEnabled = false
}
}
android.ndk {
moduleName = "cocos2dx"
stl = "c++_static"
cppFlags.add("-std=c++11")
cppFlags.add("-pthread")
cppFlags.add("-fexceptions")
cppFlags.add("-frtti")
CFlags.add("-DUSE_FILE32API")
CFlags.add("-fexceptions")
ldLibs.addAll(["atomic", "log", "android", "EGL", "GLESv2", "z"])
abiFilters.addAll(["armeabi", "armeabi-v7a", "x86"])
}
android.sources {
main {
manifest.source {
srcDir "."
include "AndroidManifest.xml"
}
jni {
source {
// INTERNAL CPP FILES
//srcDir "../../../../cocos/"
// include only file at this level
srcDir "../../../../cocos/2d"
srcDir "../../../../cocos/math"
srcDir "../../../../cocos/base"
//srcDir "../../../../cocos/platform"
// include only file at this level
srcDir "../../../../cocos/platform/android"
srcDir "../../../../cocos/renderer"
srcDir "../../../../cocos/deprecated"
srcDir "../../../../cocos/physics"
srcDir "../../../../cocos/physics3d"
srcDir "../../../../cocos/navmesh"
// EXTERNAL CPP FILES
srcDir "../../../../external/ConvertUTF"
srcDir "../../../../external/tinyxml2"
srcDir "../../../../external/unzip"
srcDir "../../../../external/edtaa3func"
srcDir "../../../../external/poly2tri"
srcDir "../../../../external/clipper"
srcDir "../../../../external/xxhash"
}
exportedHeaders {
// INTERNAL HEADERS
srcDir "../../../../cocos"
srcDir "../../../../cocos/2d"
srcDir "../../../../cocos/math"
srcDir "../../../../cocos/base"
srcDir "../../../../cocos/platform"
srcDir "../../../../cocos/platform/android"
srcDir "../../../../cocos/renderer"
srcDir "../../../../cocos/deprecated"
srcDir "../../../../cocos/physics"
srcDir "../../../../cocos/physics3d"
srcDir "../../../../cocos/navmesh"
// EXTERNAL HEADERS
srcDir "../../../../external"
srcDir "../../../../external/ConvertUTF"
srcDir "../../../../external/tinyxml2"
srcDir "../../../../external/unzip"
srcDir "../../../../external/edtaa3func"
srcDir "../../../../external/poly2tri"
srcDir "../../../../external/poly2tri/common"
srcDir "../../../../external/poly2tre/sweep"
srcDir "../../../../external/clipper"
srcDir "../../../../external/xxhash"
// STATIC LIBRARIES
srcDir "../../../../external/chipmunk/include/chipmunk"
srcDir "../../../../external/freetype2/include/android/freetype2"
srcDir "../../../../external/curl/include/android"
}
dependencies
{
library "chipmunk"
library "freetype2"
library "curl"
}
}
}
}
}
dependencies {
compile files('../java/libs/android-async-http-1.4.8.jar')
}
Setup in android-studio is pretty straightforward and will not be covered here except for 3 points:
1°) be sure to use:
distributionUrl=https\://services.gradle.org/distributions/gradle-2.9-all.zip
in your gradle-wrapper.properties
2°) be sure to use gradle-experimental in your general top-level gradle file:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle-experimental:0.6.0-alpha3'
}
}
allprojects {
repositories {
jcenter()
}
}
3°) The build.gradle file I have posted should be a replacement of the one found in
cocos/platform/android/libcocos2dx
I will keep this post updated as I progress. For now I am stuck on the network folder building (it uses an Android.mk file), and I have not yet decided if I should make it a sub-project with its own build.gradle file.
As I said, it doesn’t quite compile yet (link error due to MANY things)but I am slowly building the file up. Any help would be appreciated.
I may submit a pull request when it’s finished, so everyone can enjoy the new ndk support in android-studio
Thanks!