|
@@ -21,6 +21,7 @@ import json
|
|
|
import sys
|
|
|
import importlib
|
|
|
import uuid
|
|
|
+import zipfile
|
|
|
|
|
|
ignoreLauncher = ['jm_ysdk', 'jm_yijie', 'jm_quick', 'jm_beiyu', 'jm_xq_jrtt']
|
|
|
|
|
@@ -655,7 +656,6 @@ def generateNewRFile(game, sdk, subChannel, config):
|
|
|
生成新的R文件
|
|
|
'''
|
|
|
decompliePath = file_utils.getDecompliePath(game, sdk, subChannel, config['cache'])
|
|
|
- aapt = file_utils.getAAPTPath()
|
|
|
androidPlatforms = file_utils.getAndroidCompileToolPath()
|
|
|
manifest = os.path.join(decompliePath, 'AndroidManifest.xml')
|
|
|
decomplieResPath = file_utils.getFullPath(decompliePath, 'res')
|
|
@@ -664,32 +664,67 @@ def generateNewRFile(game, sdk, subChannel, config):
|
|
|
if not os.path.exists(compliePath):
|
|
|
os.makedirs(compliePath)
|
|
|
|
|
|
- ret = file_utils.getExecPermission(aapt)
|
|
|
- if ret:
|
|
|
- return ret
|
|
|
-
|
|
|
# 生成R文件
|
|
|
print('create R.java ...')
|
|
|
- createRCmd = '"%s" p -f -m -J "%s" -S "%s" -I "%s" -M "%s"' % (aapt, compliePath, decomplieResPath, androidPlatforms, manifest)
|
|
|
- ret = file_utils.execFormatCmd(createRCmd)
|
|
|
- if ret:
|
|
|
- return ret
|
|
|
+ if config['aapt2disable']:
|
|
|
+ aapt = file_utils.getAAPTPath()
|
|
|
+ ret = file_utils.getExecPermission(aapt)
|
|
|
+ if ret:
|
|
|
+ return ret
|
|
|
+ createRCmd = '"%s" p -f -m -J "%s" -S "%s" -I "%s" -M "%s"' % (aapt, compliePath, decomplieResPath, androidPlatforms, manifest)
|
|
|
+ ret = file_utils.execFormatCmd(createRCmd)
|
|
|
+ if ret:
|
|
|
+ return ret
|
|
|
+ else:
|
|
|
+ # compile
|
|
|
+ aapt = file_utils.getAAPT2Path()
|
|
|
+ ret = file_utils.getExecPermission(aapt)
|
|
|
+ if ret:
|
|
|
+ return ret
|
|
|
+
|
|
|
+ print('compiled res ...')
|
|
|
+ complieResPath = os.path.join(compliePath, 'compiled')
|
|
|
+ complieResCmd = '"%s" compile --dir "%s" -o "%s"' % (aapt, decomplieResPath, complieResPath)
|
|
|
+ file_utils.execFormatCmd(complieResCmd)
|
|
|
+
|
|
|
+ # unzip
|
|
|
+ print('unzip compiled res ...')
|
|
|
+ unzipResPath = os.path.join(compliePath, 'aapt2_res')
|
|
|
+ with zipfile.ZipFile(complieResPath) as zf:
|
|
|
+ zf.extractall(unzipResPath)
|
|
|
+ print('create unzip %s' % unzipResPath)
|
|
|
+
|
|
|
+ # link
|
|
|
+ print('link res ...')
|
|
|
+ outApk = os.path.join(compliePath, 'res.apk')
|
|
|
+ linkResCmd = '"%s" link -o "%s" -I "%s" --manifest "%s" --java "%s" --auto-add-overlay' % (aapt, outApk, androidPlatforms, manifest, compliePath)
|
|
|
+ for filename in os.listdir(unzipResPath):
|
|
|
+ linkResCmd += ' -R "%s"' % filename
|
|
|
+ ret = file_utils.execFormatCmd(linkResCmd, unzipResPath)
|
|
|
+ if ret:
|
|
|
+ return ret
|
|
|
|
|
|
# 编译R文件
|
|
|
print('complie R.java ...')
|
|
|
packageName = xml_utils.getPackageName(manifest)
|
|
|
packagePath = file_utils.getPackagePath(compliePath, packageName)
|
|
|
RSourceFile = os.path.join(packagePath, 'R.java')
|
|
|
- complieRCmd = 'javac -source 1.7 -target 1.7 -encoding UTF-8 "%s"' % RSourceFile
|
|
|
+ complieRCmd = 'javac -source 1.8 -target 1.8 -encoding UTF-8 "%s"' % RSourceFile
|
|
|
ret = file_utils.execFormatCmd(complieRCmd)
|
|
|
if ret:
|
|
|
return ret
|
|
|
|
|
|
# 生成dex
|
|
|
print('dex R.class ...')
|
|
|
- dx = file_utils.getDxPath()
|
|
|
outDex = os.path.join(compliePath, 'classes.dex')
|
|
|
- ret = file_utils.execJarCmd(dx, '--dex --output="%s" "%s"' % (outDex, compliePath))
|
|
|
+ if config['aapt2disable']:
|
|
|
+ dx = file_utils.getDxPath()
|
|
|
+ dexCmd = '--dex --no-warning --output="%s" "%s"' % (outDex, compliePath)
|
|
|
+ else:
|
|
|
+ dx = file_utils.getD8Path()
|
|
|
+ clazz = os.path.join(packagePath, '*.class')
|
|
|
+ dexCmd = '--lib "%s" --output "%s" %s' % (androidPlatforms, compliePath, clazz)
|
|
|
+ ret = file_utils.execJarCmd(dx, dexCmd)
|
|
|
if ret:
|
|
|
return ret
|
|
|
|
|
@@ -715,13 +750,17 @@ def packJar(game, sdk, subChannel, config):
|
|
|
splitDex = config['splitDex']
|
|
|
decompliePath = file_utils.getDecompliePath(game, sdk, subChannel, config['cache'])
|
|
|
outPath = file_utils.getFullPath(decompliePath, 'gen')
|
|
|
- dx = file_utils.getDxPath()
|
|
|
|
|
|
if not os.path.exists(outPath):
|
|
|
os.makedirs(outPath)
|
|
|
|
|
|
- # --no-warning
|
|
|
- dexCmd = '--dex --multi-dex --no-warning --output="%s"' % outPath
|
|
|
+ if config['aapt2disable']:
|
|
|
+ dx = file_utils.getDxPath()
|
|
|
+ dexCmd = '--dex --multi-dex --no-warning --output="%s"' % outPath
|
|
|
+ else:
|
|
|
+ dx = file_utils.getD8Path()
|
|
|
+ androidPlatforms = file_utils.getAndroidCompileToolPath()
|
|
|
+ dexCmd = '--lib "%s" --output "%s"' % (androidPlatforms, outPath)
|
|
|
|
|
|
# 找到所有lib依赖
|
|
|
sdkPath = file_utils.getFullSDKPath(sdk)
|
|
@@ -785,13 +824,17 @@ def packLogJar(game, sdk, subChannel, config, logSdk):
|
|
|
'''
|
|
|
decompliePath = file_utils.getDecompliePath(game, sdk, subChannel, config['cache'])
|
|
|
outPath = file_utils.getFullPath(decompliePath, 'gen')
|
|
|
- dx = file_utils.getDxPath()
|
|
|
|
|
|
if not os.path.exists(outPath):
|
|
|
os.makedirs(outPath)
|
|
|
|
|
|
- # --no-warning
|
|
|
- dexCmd = '--dex --multi-dex --no-warning --output="%s"' % outPath
|
|
|
+ if config['aapt2disable']:
|
|
|
+ dx = file_utils.getDxPath()
|
|
|
+ dexCmd = '--dex --multi-dex --no-warning --output="%s"' % outPath
|
|
|
+ else:
|
|
|
+ dx = file_utils.getD8Path()
|
|
|
+ androidPlatforms = file_utils.getAndroidCompileToolPath()
|
|
|
+ dexCmd = '--lib "%s" --output "%s"' % (androidPlatforms, outPath)
|
|
|
|
|
|
# 找到所有lib依赖
|
|
|
sdkPath = file_utils.getFullLogSDKPath(logSdk)
|
|
@@ -953,7 +996,11 @@ def recomplie(game, sdk, subChannel, config):
|
|
|
decompliePath = file_utils.getDecompliePath(game, sdk, subChannel, config['cache'])
|
|
|
outApk = file_utils.getOutApkPath(game, sdk, subChannel, config['cache'])
|
|
|
|
|
|
- return file_utils.execJarCmd(apktoolPath, 'b -f "%s" -o "%s"' % (decompliePath, outApk))
|
|
|
+ useAppt2 = ' --use-aapt2'
|
|
|
+ if config['aapt2disable']:
|
|
|
+ useAppt2 = ''
|
|
|
+
|
|
|
+ return file_utils.execJarCmd(apktoolPath, 'b -f "%s" -o "%s" %s' % (decompliePath, outApk, useAppt2))
|
|
|
|
|
|
def alignApk(game, sdk, subChannel, config):
|
|
|
'''
|