2018-05-11 15:07:19 +08:00
|
|
|
import org.gradle.internal.os.OperatingSystem;
|
2017-03-17 11:54:36 +08:00
|
|
|
|
2015-05-15 16:37:43 +08:00
|
|
|
apply plugin: 'com.android.application'
|
|
|
|
|
|
|
|
android {
|
2017-06-05 11:35:48 +08:00
|
|
|
compileSdkVersion PROP_COMPILE_SDK_VERSION.toInteger()
|
2015-05-15 16:37:43 +08:00
|
|
|
|
|
|
|
defaultConfig {
|
|
|
|
applicationId "org.cocos2dx.lua_empty_test"
|
2017-06-05 11:35:48 +08:00
|
|
|
minSdkVersion PROP_MIN_SDK_VERSION
|
2017-03-14 13:41:28 +08:00
|
|
|
targetSdkVersion PROP_TARGET_SDK_VERSION
|
2015-05-15 16:37:43 +08:00
|
|
|
versionCode 1
|
|
|
|
versionName "1.0"
|
|
|
|
|
2017-02-21 17:58:30 +08:00
|
|
|
externalNativeBuild {
|
2018-04-24 13:46:20 +08:00
|
|
|
if (PROP_BUILD_TYPE == 'ndk-build') {
|
2018-02-08 09:24:33 +08:00
|
|
|
ndkBuild {
|
2017-03-14 13:41:28 +08:00
|
|
|
targets 'lua_empty_test'
|
2017-11-23 09:08:50 +08:00
|
|
|
arguments 'NDK_TOOLCHAIN_VERSION=clang'
|
2017-03-14 13:41:28 +08:00
|
|
|
arguments '-j' + Runtime.runtime.availableProcessors()
|
|
|
|
}
|
2017-02-21 17:58:30 +08:00
|
|
|
}
|
2018-04-24 13:46:20 +08:00
|
|
|
else if (PROP_BUILD_TYPE == 'cmake') {
|
2018-02-08 09:24:33 +08:00
|
|
|
cmake {
|
cmake support win32 ,and support generate&use prebuilt libs (#18683)
* fix win32 prebuilt error, and set cmake as default android native build
* cpp-template support msvc
* add msvc version check
* add -D_USRLUASTATIC, fix lua lib cmake compile error
* fix cpp-empty-test res copy dir, add function needed
* improve msvc res copy
* refactor cmake copy dll logic
* fix cpp-tests compile error
* refactor copy dll temp
* refactor win32 exe using dlls
* js-project compile support cmake using msvc
* improve res mark for win32
* update the way of lua project res mark
* add D_USRLUASTATIC for lua project
* unify RELEASE Release to Release, add CMAKE_CONFIGURATION_TYPES
* improve VS shows targets, add folder
* improve mac/ios res mark
* reduce useless comments
* unify cpp src include variable
* refactor cpp test project package logic
* improve pkg app logic
* start support prebuilt libs for cpp project using cmake
* improve prebuilt libs generate
* expand js/lua support prebuilt libs on mac
* adapt IDE generate libs path
* start do prebuilt for android
* improve the way of using external libs for prebuilt
* prebuilt libs support cpp-empty-test on android studio
* cpp-tests prebuilt libs, and remove useless
* start to improve libs using, to adapt prebuilt
* improve cpp tests prebuilt on android
* prebuilt support lua & js test on android
* prebuilt support cpp&js template
* rename prebuilt variabl, detail androd config
* finish android support prebuilt using cmake
* fix cmake script run in windows error
* reduce variable name length
* improve the way of win32 use dlls to adapt prebuilt
* loosen pick js/lua engine lib condition
* self review and start check linux build
* unify compile option location
* strict copy dlls condition
* improve libs link order
* start redo the way of copy dlls
* unify dlls copy logic
* fix linux res copy error
* update cmake copy file path in linux
* make prebuilt dir if needed, and divide Debug and Release dir
* cmake win32 divide Debug and Release dir well
* comment Lua Template project, for the unfinished lua simulator support
* add simulator cmake file
* start support simulator
* simulator support cmake build on macOS
* fix simulator compile error on win32
* add simulator prebuilt support
* improve mark cocos app macro
* improve cmake template project format
* improve cmake app files format
* fix format improve mistake
* detail cmake readme
* improve readme, useless comments
* add game.rc to template project
* check travis openssl version
* try update travis openssl
* upgrade travis openssl
* change openssl link
* change to upgrade openssl
* re install python with upgrade openssl
* add comment for macro and func, improve variable name
2018-03-08 09:47:57 +08:00
|
|
|
targets "lua_empty_test"
|
2018-02-08 09:24:33 +08:00
|
|
|
arguments "-DCMAKE_FIND_ROOT_PATH=", "-DANDROID_STL=c++_static", "-DANDROID_TOOLCHAIN=clang", "-DANDROID_ARM_NEON=TRUE", \
|
2018-03-14 13:51:29 +08:00
|
|
|
"-DUSE_CHIPMUNK=TRUE", "-DUSE_BULLET=TRUE", "-DBUILD_LUA_LIBS=TRUE"
|
2018-02-08 09:24:33 +08:00
|
|
|
cppFlags "-frtti -fexceptions"
|
cmake support win32 ,and support generate&use prebuilt libs (#18683)
* fix win32 prebuilt error, and set cmake as default android native build
* cpp-template support msvc
* add msvc version check
* add -D_USRLUASTATIC, fix lua lib cmake compile error
* fix cpp-empty-test res copy dir, add function needed
* improve msvc res copy
* refactor cmake copy dll logic
* fix cpp-tests compile error
* refactor copy dll temp
* refactor win32 exe using dlls
* js-project compile support cmake using msvc
* improve res mark for win32
* update the way of lua project res mark
* add D_USRLUASTATIC for lua project
* unify RELEASE Release to Release, add CMAKE_CONFIGURATION_TYPES
* improve VS shows targets, add folder
* improve mac/ios res mark
* reduce useless comments
* unify cpp src include variable
* refactor cpp test project package logic
* improve pkg app logic
* start support prebuilt libs for cpp project using cmake
* improve prebuilt libs generate
* expand js/lua support prebuilt libs on mac
* adapt IDE generate libs path
* start do prebuilt for android
* improve the way of using external libs for prebuilt
* prebuilt libs support cpp-empty-test on android studio
* cpp-tests prebuilt libs, and remove useless
* start to improve libs using, to adapt prebuilt
* improve cpp tests prebuilt on android
* prebuilt support lua & js test on android
* prebuilt support cpp&js template
* rename prebuilt variabl, detail androd config
* finish android support prebuilt using cmake
* fix cmake script run in windows error
* reduce variable name length
* improve the way of win32 use dlls to adapt prebuilt
* loosen pick js/lua engine lib condition
* self review and start check linux build
* unify compile option location
* strict copy dlls condition
* improve libs link order
* start redo the way of copy dlls
* unify dlls copy logic
* fix linux res copy error
* update cmake copy file path in linux
* make prebuilt dir if needed, and divide Debug and Release dir
* cmake win32 divide Debug and Release dir well
* comment Lua Template project, for the unfinished lua simulator support
* add simulator cmake file
* start support simulator
* simulator support cmake build on macOS
* fix simulator compile error on win32
* add simulator prebuilt support
* improve mark cocos app macro
* improve cmake template project format
* improve cmake app files format
* fix format improve mistake
* detail cmake readme
* improve readme, useless comments
* add game.rc to template project
* check travis openssl version
* try update travis openssl
* upgrade travis openssl
* change openssl link
* change to upgrade openssl
* re install python with upgrade openssl
* add comment for macro and func, improve variable name
2018-03-08 09:47:57 +08:00
|
|
|
// prebuilt root must be defined as a directory which you have right to access or create if you use prebuilt
|
|
|
|
// set "-DGEN_COCOS_PREBUILT=ON" and "-DUSE_COCOS_PREBUILT=OFF" to generate prebuilt, this way build cocos2d-x libs
|
|
|
|
// set "-DGEN_COCOS_PREBUILT=OFF" and "-DUSE_COCOS_PREBUILT=ON" to use prebuilt, this way not build cocos2d-x libs
|
|
|
|
//arguments "-DCOCOS_PREBUILT_ROOT=/Users/laptop/cocos-prebuilt"
|
|
|
|
//arguments "-DGEN_COCOS_PREBUILT=OFF", "-DUSE_COCOS_PREBUILT=OFF"
|
2018-02-08 09:24:33 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ndk {
|
|
|
|
abiFilters = []
|
|
|
|
abiFilters.addAll(PROP_APP_ABI.split(':').collect{it as String})
|
2017-02-21 17:58:30 +08:00
|
|
|
}
|
2015-05-15 16:37:43 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
sourceSets.main {
|
|
|
|
java.srcDir "src"
|
|
|
|
res.srcDir "res"
|
|
|
|
manifest.srcFile "AndroidManifest.xml"
|
2017-02-21 17:58:30 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
externalNativeBuild {
|
2018-04-24 13:46:20 +08:00
|
|
|
if (PROP_BUILD_TYPE == 'ndk-build') {
|
2018-02-08 09:24:33 +08:00
|
|
|
ndkBuild {
|
2017-03-14 13:41:28 +08:00
|
|
|
path "jni/Android.mk"
|
|
|
|
}
|
2017-02-21 17:58:30 +08:00
|
|
|
}
|
2018-04-24 13:46:20 +08:00
|
|
|
else if (PROP_BUILD_TYPE == 'cmake') {
|
2018-02-08 09:24:33 +08:00
|
|
|
cmake {
|
|
|
|
path "../../CMakeLists.txt"
|
|
|
|
}
|
|
|
|
}
|
2015-05-15 16:37:43 +08:00
|
|
|
}
|
|
|
|
|
2015-05-22 15:52:41 +08:00
|
|
|
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
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-05-15 16:37:43 +08:00
|
|
|
buildTypes {
|
|
|
|
release {
|
2017-11-23 09:08:50 +08:00
|
|
|
debuggable false
|
|
|
|
jniDebuggable false
|
|
|
|
renderscriptDebuggable false
|
|
|
|
minifyEnabled true
|
|
|
|
shrinkResources true
|
2015-05-15 16:37:43 +08:00
|
|
|
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
|
2015-05-22 15:52:41 +08:00
|
|
|
if (project.hasProperty("RELEASE_STORE_FILE")) {
|
|
|
|
signingConfig signingConfigs.release
|
|
|
|
}
|
2017-03-14 13:41:28 +08:00
|
|
|
|
2017-03-29 15:56:46 +08:00
|
|
|
externalNativeBuild {
|
|
|
|
ndkBuild {
|
|
|
|
arguments 'NDK_DEBUG=0'
|
2017-03-14 13:41:28 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
debug {
|
2017-11-23 09:08:50 +08:00
|
|
|
debuggable true
|
|
|
|
jniDebuggable true
|
|
|
|
renderscriptDebuggable true
|
2017-03-29 15:56:46 +08:00
|
|
|
externalNativeBuild {
|
|
|
|
ndkBuild {
|
|
|
|
arguments 'NDK_DEBUG=1'
|
2017-03-14 13:41:28 +08:00
|
|
|
}
|
|
|
|
}
|
2015-05-15 16:37:43 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-29 15:56:46 +08:00
|
|
|
def getCocosCommandPath() {
|
2018-05-11 15:07:19 +08:00
|
|
|
if (OperatingSystem.current().isWindows()) {
|
2017-03-29 15:56:46 +08:00
|
|
|
return 'cocos.bat'
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// on unix like system, can not get environments variables easily
|
|
|
|
// so run a shell script to get environment variable sets by cocos2d-x setup.py
|
|
|
|
new ByteArrayOutputStream().withStream { os ->
|
|
|
|
def result = exec {
|
|
|
|
executable = project.file('get_environment.sh')
|
|
|
|
standardOutput = os
|
|
|
|
}
|
|
|
|
ext.console_path = os.toString().trim()
|
|
|
|
}
|
|
|
|
return new File(console_path + '/cocos').absolutePath;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-14 13:41:28 +08:00
|
|
|
// a method used to invoke the cocos luacompile command
|
|
|
|
def compileLua(srcDir, dstDir, doCompile, is64bit, doEncrypt) {
|
|
|
|
def compileArgs = ['luacompile', '-s', srcDir, '-d', dstDir]
|
|
|
|
if (!doCompile) {
|
|
|
|
compileArgs << '--disable-compile'
|
|
|
|
}
|
|
|
|
else if (is64bit) {
|
|
|
|
compileArgs << '--bytecode-64bit'
|
|
|
|
}
|
2017-02-21 17:58:30 +08:00
|
|
|
|
2017-03-14 13:41:28 +08:00
|
|
|
if (doEncrypt) {
|
|
|
|
compileArgs << '-e'
|
|
|
|
compileArgs << '-k'
|
|
|
|
compileArgs << project.property('PROP_LUA_ENCRYPT_KEY')
|
|
|
|
compileArgs << '-b'
|
|
|
|
compileArgs << project.property('PROP_LUA_ENCRYPT_SIGN')
|
|
|
|
}
|
2017-02-21 17:58:30 +08:00
|
|
|
|
2017-03-14 13:41:28 +08:00
|
|
|
// commandLine compileArgs
|
|
|
|
println 'running command : ' + 'cocos ' + compileArgs.join(' ')
|
|
|
|
exec {
|
2017-03-29 15:56:46 +08:00
|
|
|
// if you meet problem, just replace `getCocosCommandPath()` to the path of cocos command
|
|
|
|
executable getCocosCommandPath()
|
2017-03-14 13:41:28 +08:00
|
|
|
args compileArgs
|
|
|
|
}
|
|
|
|
|
|
|
|
// remove the lua files in dstDir
|
|
|
|
delete fileTree(dstDir) {
|
|
|
|
include '**/*.lua'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
android.applicationVariants.all { variant ->
|
|
|
|
// delete previous files first
|
|
|
|
delete "${buildDir}/intermediates/assets/${variant.dirName}"
|
|
|
|
|
|
|
|
variant.mergeAssets.doLast {
|
2017-02-21 17:58:30 +08:00
|
|
|
copy {
|
|
|
|
from "${buildDir}/../../../../res"
|
|
|
|
into "${buildDir}/intermediates/assets/${variant.dirName}/res"
|
|
|
|
}
|
|
|
|
|
|
|
|
copy {
|
|
|
|
from "${buildDir}/../../../../src"
|
|
|
|
into "${buildDir}/intermediates/assets/${variant.dirName}/src"
|
|
|
|
}
|
|
|
|
|
|
|
|
copy {
|
|
|
|
from "${buildDir}/../../../../../../cocos/scripting/lua-bindings/script"
|
|
|
|
into "${buildDir}/intermediates/assets/${variant.dirName}/src/cocos"
|
|
|
|
}
|
|
|
|
|
2017-03-14 13:41:28 +08:00
|
|
|
// compile & encrypt the scripts if necessary
|
|
|
|
def compileScript = (variant.name.compareTo('release') == 0)
|
|
|
|
if (project.hasProperty('PROP_COMPILE_SCRIPT')) {
|
|
|
|
compileScript = (PROP_COMPILE_SCRIPT.compareTo('1') == 0)
|
|
|
|
}
|
|
|
|
|
|
|
|
def encryptLua = project.hasProperty('PROP_LUA_ENCRYPT') && (PROP_LUA_ENCRYPT.compareTo('1') == 0)
|
|
|
|
if (compileScript || encryptLua) {
|
|
|
|
// -1 means not build bytecode
|
|
|
|
// 0 means build 32bit only
|
|
|
|
// 1 means build 64bit only
|
|
|
|
// 2 means build both 32bit & 64bit
|
|
|
|
def buildType = -1
|
|
|
|
if (compileScript) {
|
|
|
|
def need64 = false
|
|
|
|
def need32 = false
|
|
|
|
def abis = PROP_APP_ABI.split(':').collect{it as String}
|
|
|
|
abis.each{ abi->
|
|
|
|
if (abi.compareTo('arm64-v8a') == 0) {
|
|
|
|
need64 = true
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
need32 = true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (need64 && need32) {
|
|
|
|
buildType = 2
|
|
|
|
}
|
|
|
|
else if (need64) {
|
|
|
|
buildType = 1
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
buildType = 0
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// invoke cocos command to compile & encrypt the lua files
|
|
|
|
switch (buildType) {
|
|
|
|
case -1:
|
|
|
|
compileLua("${buildDir}/intermediates/assets/${variant.dirName}/src",
|
|
|
|
"${buildDir}/intermediates/assets/${variant.dirName}/src",
|
|
|
|
false, false, encryptLua)
|
|
|
|
break
|
|
|
|
case 0:
|
|
|
|
compileLua("${buildDir}/intermediates/assets/${variant.dirName}/src",
|
|
|
|
"${buildDir}/intermediates/assets/${variant.dirName}/src",
|
|
|
|
true, false, encryptLua)
|
|
|
|
break
|
|
|
|
case 1:
|
|
|
|
compileLua("${buildDir}/intermediates/assets/${variant.dirName}/src",
|
|
|
|
"${buildDir}/intermediates/assets/${variant.dirName}/src/64bit",
|
|
|
|
true, true, encryptLua)
|
|
|
|
|
|
|
|
// remove the lua files in src dir
|
|
|
|
delete fileTree("${buildDir}/intermediates/assets/${variant.dirName}/src") {
|
|
|
|
include '**/*.lua'
|
|
|
|
}
|
|
|
|
delete "${buildDir}/intermediates/assets/${variant.dirName}/src/cocos"
|
|
|
|
break
|
|
|
|
case 2:
|
|
|
|
compileLua("${buildDir}/intermediates/assets/${variant.dirName}/src",
|
|
|
|
"${buildDir}/intermediates/assets/${variant.dirName}/src/64bit",
|
|
|
|
true, true, encryptLua)
|
|
|
|
compileLua("${buildDir}/intermediates/assets/${variant.dirName}/src",
|
|
|
|
"${buildDir}/intermediates/assets/${variant.dirName}/src",
|
|
|
|
true, false, encryptLua)
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-02-21 17:58:30 +08:00
|
|
|
}
|
|
|
|
|
2015-05-15 16:37:43 +08:00
|
|
|
dependencies {
|
2017-11-23 09:08:50 +08:00
|
|
|
implementation fileTree(dir: 'libs', include: ['*.jar'])
|
|
|
|
implementation project(':libcocos2dx')
|
2015-05-15 16:37:43 +08:00
|
|
|
}
|