def andResGuard(): print "###############################" print "Now andResGuard" print "###############################" workPath = glo.getValue(config.KEY_WORK_PATH) lcbaPath = glo.getValue(config.KEY_FINE_PATH) modules_name = config.MODULES_NAME if None == workPath or None == modules_name or None == lcbaPath: print "andResGuard()...work path is empty!!!" util.safeQuit(None, None) pass # apkPath = os.path.join(workPath,const.BUILD_APK_PATH) # useAndResGuard(apkPath,os.path.join(outDirPath,const.AND_RES_GUARD_OUT)) #apk 应该只有一个 for module_name in modules_name: modulePath = os.path.join(workPath, module_name) apkPath = os.path.join(modulePath, config.BUILD_APK_PATH) outDirPath = os.path.join(lcbaPath, module_name) # andres.useAndResGuard(apkPath,os.path.join(outDirPath,"JumeiOut")) configPath = os.path.join( '/Users/tory/working/Codes/JUMEI/android/lcba/lcba_PyPI/examples', 'AndResGuard_config.xml') andres.useAndResGuard(apkPath, os.path.join(outDirPath, "JumeiOut"), configPath) pass
def lintResource(just_check=False): print "###############################" print "Now lint Resource " print "###############################" workPath = glo.getValue(config.KEY_WORK_PATH) moduleNames = config.MODULES_NAME gradlewPath = glo.getValue(config.KEY_GRADLEW_PATH) if None == moduleNames or None == workPath or None == gradlewPath: print "lintResource()...not find value" util.safeQuit(None, None) os.chdir(r'%s' % workPath) #方案一,如果有lint 报告文件,就用已有的报告文件 #缺点:报告是由可能是旧的 for moduleName in moduleNames: modulePath = os.path.join(workPath, moduleName) reportsXml = os.path.join(modulePath, config.LINT_RESULT_PATH) print "report xml is:%s" % reportsXml if os.path.exists(reportsXml): print "###############################" print "Now delete unUsed file" print "###############################" manifest_path = os.path.abspath( os.path.join(modulePath, config.ANDROID_MANIFEST_FILE)) out_ids_path = os.path.abspath( os.path.join(modulePath, config.LAYOUT_IDS_PATH)) clean_app.deleteRes(modulePath, reportsXml, manifest_path, out_ids_path, just_check, config.IGNORE_LAYOUTS_FILE, config.IGNORE_LAYOUTS_VALUE) else: if util.haveGradleTask(workPath, gradlewPath, config.TASK_LINT): print "we will build lint reports with command: %s %s --info --stacktrace" % ( gradlewPath, config.TASK_LINT) os.system('%s %s --info --stacktrace' % (gradlewPath, config.TASK_LINT)) if os.path.exists(reportsXml): print "###############################" print "Now delete unUsed file" print "###############################" manifest_path = os.path.abspath( os.path.join(modulePath, config.ANDROID_MANIFEST_FILE)) out_ids_path = os.path.abspath( os.path.join(modulePath, config.LAYOUT_IDS_PATH)) clean_app.deleteRes(modulePath, reportsXml, manifest_path, out_ids_path, just_check, config.IGNORE_LAYOUTS_FILE, config.IGNORE_LAYOUTS_VALUE) else: print "not find lint reports!!!!" #fixme 这里使用sdk lint 命令来替代 util.safeQuit(None, None) pass else: print "not find task:%s" % config.TASK_LINT pass pass
def lintResource_2(just_check): print "###############################" print "Now lint Resource " print "###############################" workPath = glo.getValue(config.KEY_WORK_PATH) moduleNames = config.MODULES_NAME gradlewPath = glo.getValue(config.KEY_GRADLEW_PATH) if None == moduleNames or None == workPath or None == gradlewPath: print "lintResource()...not find value" util.safeQuit(None, None) for moduleName in moduleNames: modulePath = os.path.join(workPath, moduleName) clean_app.deleteRes(app_dir=modulePath) pass
def initModules(): workPath = findWorkingPath() if not workPath: print "initModules()...not find work path!!!" util.safeQuit(None, None) pass os.chdir(workPath) glo.set_value(KEY_WORK_PATH, workPath) fineDirPath = os.path.join(workPath, "fine_resources") if os.path.exists(fineDirPath): glo.set_value(KEY_FINE_PATH, fineDirPath) pass gradlewPath = os.path.join(workPath, "gradlew") if os.path.exists(gradlewPath): glo.set_value(KEY_GRADLEW_PATH, gradlewPath) pass
def compressPic(just_check=False): # 压缩匹配的文件夹drawable mipmap assert print "###############################" print "Now compress picture " print "###############################" workPath = glo.getValue(config.KEY_WORK_PATH) lcbaPath = glo.getValue(config.KEY_FINE_PATH) print "Current Path is:%s" % (workPath) modules_name = config.MODULES_NAME if not workPath or not modules_name or not lcbaPath: print " ERROR !!! %s %s %s" % (workPath, modules_name, lcbaPath) util.safeQuit(None, None) os.chdir(workPath) for module_name in modules_name: modulePath = os.path.join(workPath, module_name) print "modulePath:%s" % modulePath outDir = os.path.join(lcbaPath, module_name) compress.compressModule(modulePath, outDir, config.ACCOUNT_KEY_LIST, just_check) pass
def main(): config.initModules() signal.signal(signal.SIGINT, util.safeQuit) signal.signal(signal.SIGTERM, util.safeQuit) workPath = glo.getValue(config.KEY_WORK_PATH) print "workpath:%s" % workPath modules_name = config.MODULES_NAME if None == workPath or None == modules_name: print "main()...work path is empty!!!" util.safeQuit(None, None) pass os.chdir(r'%s' % workPath) gradlewPath = glo.getValue(config.KEY_GRADLEW_PATH) if os.path.exists(gradlewPath): os.system('%s clean' % gradlewPath) pass #lint 和删除无用资源 lintRes.lintResource() #压缩png compressRes.compressPic() #编译生成apk if util.haveGradleTask(workPath, gradlewPath, config.BUILD_APK_TASK): #删除build目录自己编译,因为lint资源删除了一些资源,不删除会提示找不到 print "###############################" print "Now build apk" print "###############################" # os.system('rm -rf ../build') # os.system('rm -rf JuMeiYouPinV1.0.0/build/intermediates/') os.chdir(r'%s' % workPath) os.system('%s clean' % gradlewPath) os.system("%s %s --stacktrace" % (gradlewPath, BUILD_APK_TASK)) pass #资源混淆压缩,请配置AndResGuard_config.xml andResGuard.andResGuard()