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
| android.applicationVariants.all { variant -> // delete previous files first // 每次打包要编译两次,第一次把下面delete注释去掉,第二次再注销,否则打包的还是老资源 // delete "assets/res" // delete "assets/src"
def outDir = "assets"
variant.mergeAssetsProvider.get().doLast { copy { from "${buildDir}/../../../../../res" into "${outDir}/res" }
copy { from "${buildDir}/../../../../../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 } } } }
|