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 {
|
2019-06-05 09:29:58 +08:00
|
|
|
cmake {
|
|
|
|
targets "lua_empty_test"
|
|
|
|
arguments "-DCMAKE_FIND_ROOT_PATH=", "-DANDROID_STL=c++_static", "-DANDROID_TOOLCHAIN=clang", "-DANDROID_ARM_NEON=TRUE"
|
|
|
|
cppFlags "-frtti -fexceptions -fsigned-char"
|
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"
|
2019-07-24 09:53:02 +08:00
|
|
|
assets.srcDir "assets"
|
2017-02-21 17:58:30 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
externalNativeBuild {
|
2019-06-05 09:29:58 +08:00
|
|
|
cmake {
|
|
|
|
path "../../CMakeLists.txt"
|
2018-02-08 09:24:33 +08:00
|
|
|
}
|
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
|
|
|
}
|
|
|
|
|
|
|
|
debug {
|
2017-11-23 09:08:50 +08:00
|
|
|
debuggable true
|
|
|
|
jniDebuggable true
|
|
|
|
renderscriptDebuggable true
|
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 {
|
2019-07-24 09:53:02 +08:00
|
|
|
|
|
|
|
def env_console_path = System.getenv("COCOS_CONSOLE_ROOT")
|
|
|
|
|
|
|
|
if (env_console_path != null && !env_console_path.trim().isEmpty()) {
|
|
|
|
return new File(env_console_path.trim() + '/cocos').absolutePath
|
|
|
|
}
|
|
|
|
|
2017-03-29 15:56:46 +08:00
|
|
|
// 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 {
|
2019-07-24 09:53:02 +08:00
|
|
|
executable = "/bin/bash"
|
|
|
|
args = [ "-i", project.file('get_environment.sh')]
|
2017-03-29 15:56:46 +08:00
|
|
|
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 ->
|
2019-07-24 09:53:02 +08:00
|
|
|
delete "${projectDir}/assets"
|
|
|
|
def targetName = variant.name.capitalize()
|
|
|
|
def copyTaskName = "copy${targetName}ResourcesToAssets"
|
|
|
|
|
|
|
|
tasks.register(copyTaskName) {
|
2017-02-21 17:58:30 +08:00
|
|
|
copy {
|
2019-07-24 09:53:02 +08:00
|
|
|
from "${projectDir}/../../../res"
|
|
|
|
into "${projectDir}/assets/res"
|
2017-02-21 17:58:30 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
copy {
|
2019-07-24 09:53:02 +08:00
|
|
|
from "${projectDir}/../../../src"
|
|
|
|
into "${projectDir}/assets/src"
|
2017-02-21 17:58:30 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
copy {
|
2019-07-24 09:53:02 +08:00
|
|
|
from "${projectDir}/../../../../../cocos/scripting/lua-bindings/script"
|
|
|
|
into "${projectDir}/assets/src/cocos"
|
2017-02-21 17:58:30 +08:00
|
|
|
}
|
|
|
|
|
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:
|
2019-07-24 09:53:02 +08:00
|
|
|
compileLua("${projectDir}/assets/src",
|
|
|
|
"${projectDir}/assets/src",
|
2017-03-14 13:41:28 +08:00
|
|
|
false, false, encryptLua)
|
|
|
|
break
|
|
|
|
case 0:
|
2019-07-24 09:53:02 +08:00
|
|
|
compileLua("${projectDir}/assets/src",
|
|
|
|
"${projectDir}/assets/src",
|
2017-03-14 13:41:28 +08:00
|
|
|
true, false, encryptLua)
|
|
|
|
break
|
|
|
|
case 1:
|
2019-07-24 09:53:02 +08:00
|
|
|
compileLua("${projectDir}/assets/src",
|
|
|
|
"${projectDir}/assets/src/64bit",
|
2017-03-14 13:41:28 +08:00
|
|
|
true, true, encryptLua)
|
|
|
|
|
|
|
|
// remove the lua files in src dir
|
2019-07-24 09:53:02 +08:00
|
|
|
delete fileTree("${projectDir}/assets/src") {
|
2017-03-14 13:41:28 +08:00
|
|
|
include '**/*.lua'
|
|
|
|
}
|
2019-07-24 09:53:02 +08:00
|
|
|
delete "${projectDir}/assets/src/cocos"
|
2017-03-14 13:41:28 +08:00
|
|
|
break
|
|
|
|
case 2:
|
2019-07-24 09:53:02 +08:00
|
|
|
compileLua("${projectDir}/assets/src",
|
|
|
|
"${projectDir}/assets/src/64bit",
|
2017-03-14 13:41:28 +08:00
|
|
|
true, true, encryptLua)
|
2019-07-24 09:53:02 +08:00
|
|
|
compileLua("${projectDir}/assets/src",
|
|
|
|
"${projectDir}/assets/src",
|
2017-03-14 13:41:28 +08:00
|
|
|
true, false, encryptLua)
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-07-24 09:53:02 +08:00
|
|
|
tasks.getByName("pre${targetName}Build").dependsOn copyTaskName
|
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
|
|
|
}
|