Android Studio 编译打包 cocos2dx-lua (改)


Android Studio 编译打包 cocos2dx-lua (改)

  1. 修改 build.gradle
  • cocos.bat 加密lua脚本用到
1
2
3
if (OperatingSystem.current().isWindows()) {
return 'cocos.bat'
}

改为:

1
2
3
if (OperatingSystem.current().isWindows()) {
return 'C:\\cocos2d-x-3.17.2\\tools\\cocos2d-console\\bin\\cocos.bat'
}
  • 更改资源输出路径
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
android.applicationVariants.all { variant ->
// delete previous files first
delete "${buildDir}/intermediates/merged_assets/${variant.dirName}"

def outDir = "${buildDir}/intermediates/merged_assets/${variant.dirName}"
if( "${variant.dirName}" == "debug"){
outDir = outDir + "/mergeDebugAssets/out"
}else{
outDir = outDir + "/mergeReleaseAssets/out"
}
def sourceDir = "${buildDir}/../../../../.."
println 'variant : ' + variant
variant.mergeAssetsProvider.get().doLast {
copy {
from "${sourceDir}/res"
into "${outDir}/res"
}

copy {
from "${sourceDir}/src"
into "${outDir}/src"
}

// copy {
// from "${buildDir}/../../../../cocos2d-x/cocos/scripting/lua-bindings/script"
// into "${outDir}/src/cocos"
// }

// 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("${outDir}/src",
"${outDir}/src",
false, false, encryptLua)
break
case 0:
compileLua("${outDir}/src",
"${outDir}/src",
true, false, encryptLua)
break
case 1:
compileLua("${outDir}/src",
"${outDir}/src/64bit",
true, true, encryptLua)

// remove the lua files in src dir
delete fileTree("${outDir}/src") {
include '**/*.lua'
}
delete "${outDir}/src/cocos"
break
case 2:
compileLua("${outDir}/src",
"${outDir}/src/64bit",
true, true, encryptLua)
compileLua("${outDir}/src",
"${outDir}/src",
true, false, encryptLua)
break
}
}
}
}