def doAppendIcon(): #复制icons中的图片到game_icon中 if os.path.exists(os.path.dirname(file_utils.curDir) + '/icons'): file_utils.copy_files(os.path.dirname(file_utils.curDir) + '/icons', file_utils.getFullPath('_icon/game_icon')) configFile = file_utils.getFullPath("channels_config.xml") dom = xml.dom.minidom.parse(configFile) root = dom.documentElement channellist = root.getElementsByTagName('channel') #icon处理 for channel in channellist: #获取sdk_name和fs_app_id params = channel.getElementsByTagName("param") sdk_name = "" fs_app_id = "" for param in params: if "sdk_name" == param.getAttribute("name"): sdk_name = param.getAttribute("value") if "fs_app_id" == param.getAttribute("name"): fs_app_id = param.getAttribute("value") #判断是否有sdk对应的game icon if os.path.exists(file_utils.getFullPath("_icon/game_icon/" + fs_app_id + ".png")): #获取demo的res的path sdkDemoPath = channel.getAttribute('path') resDir = os.path.dirname(file_utils.curDir) + "/" + sdkDemoPath #合并icon并存到res中 if os.path.exists( resDir ): file_utils.printF("icon fusion : channel_icon:%s, game_icon:%s \r\n", fs_app_id, sdk_name) appendChannelIconMark(fs_app_id, sdk_name, resDir)
def copyRootResFiles(apkfile, decompileDir): apkfile = file_utils.getFullPath(apkfile) aapt = file_utils.getFullToolPath("aapt") decompileDir = file_utils.getFullPath(decompileDir) igoreFiles = ['AndroidManifest.xml','apktool.yml', 'smali', 'res', 'original','lib','build','assets','unknown'] igoreFileFullPaths = [] for ifile in igoreFiles: fullpath = os.path.join(decompileDir, ifile) igoreFileFullPaths.append(fullpath) addFiles = [] addFiles = file_utils.list_files(decompileDir, addFiles, igoreFileFullPaths) if len(addFiles) <= 0: return addCmd = '"%s" add "%s"' for f in addFiles: fname = f[(len(decompileDir)+1):] addCmd = addCmd + ' ' + fname addCmd = addCmd % (aapt, apkfile) currPath = os.getcwd() os.chdir(decompileDir) file_utils.execFormatCmd(addCmd) os.chdir(currPath)
def handleThirdPlugins(workDir, decompileDir, game, channel, packageName): pluginsFolder = file_utils.getFullPath('config/plugin') gamePluginFolder = file_utils.getFullPath('games/'+game['appName']+'/plugin') plugins = channel.get('third-plugins') if plugins == None or len(plugins) <= 0: log_utils.info("the channel %s has no supported plugins.", channel['name']) return 0 #copy all resources to temp folder. for plugin in plugins: pluginName = plugin['name'] pluginSourceFolder = os.path.join(pluginsFolder, pluginName) if not os.path.exists(pluginSourceFolder): log_utils.warning("the plugin %s config folder is not exists", pluginName) continue pluginTargetFolder = workDir + "/plugins/" + pluginName file_utils.copy_files(pluginSourceFolder, pluginTargetFolder) gamePluginSourceFolder = os.path.join(gamePluginFolder, pluginName) if not os.path.exists(gamePluginSourceFolder): log_utils.warning("the plugin %s is not configed in the game %s", pluginName, game['appName']) continue file_utils.copy_files(gamePluginSourceFolder, pluginTargetFolder) if not os.path.exists(pluginSourceFolder + "/classes.dex"): jar2dex(pluginSourceFolder, pluginTargetFolder) #handle plugins smaliDir = os.path.join(decompileDir, "smali") pluginNum = 0 for plugin in plugins: pluginName = plugin['name'] pluginFolder = workDir + "/plugins/" + pluginName if not os.path.exists(pluginFolder): log_utils.warning("the plugin %s temp folder is not exists", pluginName) continue pluginDexFile = os.path.join(pluginFolder, "classes.dex") ret = dex2smali(pluginDexFile, smaliDir, "baksmali.jar") if ret: return 1 ret = copyResource(game, channel, packageName, pluginFolder, decompileDir, plugin['operations'], pluginName, plugin) if ret: return 1 pluginNum += 1 log_utils.info("Total plugin num:%s;success handle num:%s", str(len(plugins)), str(pluginNum))
def checkApkForU8SDK(workDir, decompileDir): """ 检查母包中接入U8SDK抽象层是否正确 不正确,则自动修正 """ ret = 0 log_utils.info("now to check the u8.apk is correct?") manifestFile = decompileDir + "/AndroidManifest.xml" manifestFile = file_utils.getFullPath(manifestFile) ET.register_namespace('android', androidNS) tree = ET.parse(manifestFile) root = tree.getroot() key = '{'+androidNS+'}name' applicationNode = root.find('application') name = applicationNode.get(key) if not name or name != "com.u8.sdk.U8Application": log_utils.error("the android:name in application element must be 'com.u8.sdk.U8Application'. now change it to com.u8.sdk.U8Application, but maybe something will be wrong .") applicationNode.set(key, 'com.u8.sdk.U8Application') tree.write(manifestFile, 'UTF-8') smaliName = file_utils.getFullPath(decompileDir + "/smali/com/u8/sdk/U8SDK.smali") if not os.path.exists(smaliName): log_utils.error("the u8sdk2.jar is not packaged to the u8.apk. now merge it. but maybe something will be wrong .") u8sdkJarPath = file_utils.getFullPath('config/local/u8sdk2.jar') if not os.path.exists(u8sdkJarPath): log_utils.error("the u8sdk2.jar is not in config/local path. correct failed") return 1 targetPath = file_utils.getFullPath(workDir + "/local") if not os.path.exists(targetPath): os.makedirs(targetPath) file_utils.copy_file(u8sdkJarPath, targetPath+"/u8sdk2.jar") jar2dex(targetPath, targetPath) smaliPath = file_utils.getFullPath(decompileDir + "/smali") ret = dex2smali(targetPath + '/classes.dex', smaliPath) # if not ret: # ret = mergeJar(workDir, decompileDir) log_utils.info("check u8.apk successfully") return ret
def copyAppRootResources(game, decompileDir): """ Copy game root files to apk. the files will be in the root path of apk """ resPath = "games/" + game['appName'] + "/root" resPath = file_utils.getFullPath(resPath) if not os.path.exists(resPath): log_utils.info("the game %s has no root folder", game['appName']) return targetResPath = file_utils.getFullPath(decompileDir) copyResToApk(resPath, targetResPath) return
def decompileApk(source, targetdir, apktool = "apktool2.jar"): """ Decompile apk """ apkfile = file_utils.getFullPath(source) targetdir = file_utils.getFullPath(targetdir) apktool = file_utils.getFullToolPath(apktool) if os.path.exists(targetdir): file_utils.del_file_folder(targetdir) if not os.path.exists(targetdir): os.makedirs(targetdir) cmd = '"%s" -jar -Xms512m -Xmx512m "%s" -q d -b -f "%s" -o "%s"' % (file_utils.getJavaCMD(), apktool, apkfile, targetdir) #cmd = '"%s" -q d -d -f "%s" "%s"' % (apktool, apkfile, targetdir) #print("decompile cmd : "+ cmd) ret = file_utils.execFormatCmd(cmd) return ret
def getAppIconName(decompileDir): """ 从AndroidManifest.xml中获取游戏图标的名称 """ manifestFile = decompileDir + "/AndroidManifest.xml" manifestFile = file_utils.getFullPath(manifestFile) ET.register_namespace('android', androidNS) tree = ET.parse(manifestFile) root = tree.getroot() applicationNode = root.find('application') if applicationNode is None: return "ic_launcher" key = '{'+androidNS+'}icon' iconName = applicationNode.get(key) if iconName is None: return "ic_launcher" name = iconName[10:] return name
def recompileApk(sourcefolder, apkfile, apktool = "apktool2.jar"): """ Recompile apk """ os.chdir(file_utils.curDir) sourcefolder = file_utils.getFullPath(sourcefolder) apkfile = file_utils.getFullPath(apkfile) apktool = file_utils.getFullToolPath(apktool) ret = 1 if os.path.exists(sourcefolder): cmd = '"%s" -jar -Xms512m -Xmx512m "%s" -q b -f "%s" -o "%s"' % (file_utils.getJavaCMD(), apktool, sourcefolder, apkfile) #cmd = '"%s" -q b -f "%s" "%s"' % (apktool, sourcefolder, apkfile) ret = file_utils.execFormatCmd(cmd) return ret
def copyChannelResources(game, channel, decompileDir): """ Copy channel resources to decompile folder. for example icon resources, assets and so on. """ resPath = "games/" + game['appName'] + "/channels/" + channel['id'] resPath = file_utils.getFullPath(resPath) if not os.path.exists(resPath): log_utils.warning("the channel %s special res path is not exists. %s", channel['id'], resPath) return 0 targetResPath = file_utils.getFullPath(decompileDir) copyResToApk(resPath, targetResPath) log_utils.info("copy channel %s special res to apk success.", channel['name']) return 0
def getAllGames(): """ get all games """ configFile = file_utils.getFullPath("games/games.xml") try: tree = ET.parse(configFile) root = tree.getroot() except Exception as e: log_utils.error("can not parse games.xml.path:%s", configFile) return None gamesNode = root.find('games') if gamesNode == None: return None games = gamesNode.findall('game') if games == None or len(games) <= 0: return None lstGames = [] for cNode in games: game = {} params = cNode.findall('param') if params != None and len(params) > 0: for cParam in params: key = cParam.get("name") val = cParam.get("value") game[key] = val lstGames.append(game) return lstGames
def appendSplashActivity(decompileDir, splashType): manifestFile = decompileDir + "/AndroidManifest.xml" manifestFile = file_utils.getFullPath(manifestFile) ET.register_namespace('android', androidNS) key = '{' + androidNS + '}name' screenkey = '{' + androidNS + '}screenOrientation' theme = '{' + androidNS + '}theme' tree = ET.parse(manifestFile) root = tree.getroot() applicationNode = root.find('application') if applicationNode is None: return splashNode = SubElement(applicationNode, 'activity') splashNode.set(key, 'com.u8.sdk.SplashActivity') splashNode.set(theme, '@android:style/Theme.Black.NoTitleBar.Fullscreen') if splashType[:1] == '1': splashNode.set(screenkey, 'landscape') else: splashNode.set(screenkey, 'portrait') intentNode = SubElement(splashNode, 'intent-filter') actionNode = SubElement(intentNode, 'action') actionNode.set(key, 'android.intent.action.MAIN') categoryNode = SubElement(intentNode, 'category') categoryNode.set(key, 'android.intent.category.LAUNCHER') tree.write(manifestFile, 'UTF-8')
def generateNewRFile(newPackageName, decompileDir): """ Use all new resources to generate the new R.java, and compile it ,then copy it to the target smali dir """ ret = checkValueResources(decompileDir) if ret: return 1 decompileDir = file_utils.getFullPath(decompileDir) tempPath = os.path.dirname(decompileDir) tempPath = tempPath + "/temp" log_utils.debug("generate R:the temp path is %s", tempPath) if os.path.exists(tempPath): file_utils.del_file_folder(tempPath) if not os.path.exists(tempPath): os.makedirs(tempPath) resPath = os.path.join(decompileDir, "res") targetResPath = os.path.join(tempPath, "res") file_utils.copy_files(resPath, targetResPath) genPath = os.path.join(tempPath, "gen") if not os.path.exists(genPath): os.makedirs(genPath) aaptPath = file_utils.getFullToolPath("aapt") androidPath = file_utils.getFullToolPath("android.jar") manifestPath = os.path.join(decompileDir, "AndroidManifest.xml") cmd = '"%s" p -f -m -J "%s" -S "%s" -I "%s" -M "%s"' % (aaptPath, genPath, targetResPath, androidPath, manifestPath) ret = file_utils.execFormatCmd(cmd) if ret: return 1 rPath = newPackageName.replace('.', '/') rPath = os.path.join(genPath, rPath) rPath = os.path.join(rPath, "R.java") cmd = '"%sjavac" -source 1.7 -target 1.7 -encoding UTF-8 "%s"' % (file_utils.getJavaBinDir(), rPath) ret = file_utils.execFormatCmd(cmd) if ret: return 1 targetDexPath = os.path.join(tempPath, "classes.dex") dexToolPath = file_utils.getFullToolPath("/lib/dx.jar") cmd = file_utils.getJavaCMD() + ' -jar -Xmx512m -Xms512m "%s" --dex --output="%s" "%s"' % (dexToolPath, targetDexPath, genPath) ret = file_utils.execFormatCmd(cmd) if ret: return 1 smaliPath = os.path.join(decompileDir, "smali") ret = dex2smali(targetDexPath, smaliPath, "baksmali.jar") return ret
def doGamePostScript(game, channel, decompileDir, packageName): scriptDir = file_utils.getFullPath("games/"+game['appName']+"/scripts") if not os.path.exists(scriptDir): log_utils.info("the game post script is not exists. if you have some specail logic, you can do it in games/[yourgame]/scripts/post_script.py") return 0 sdkScript = os.path.join(scriptDir, "post_script.py") if not os.path.exists(sdkScript): log_utils.info("the game post script is not exists. if you have some specail logic, you can do it in games/[yourgame]/scripts/post_script.py") return 0 sys.path.append(scriptDir) import post_script log_utils.info("now to execute post_script.py of game %s ", game['appName']) ret = post_script.execute(game, channel, decompileDir, packageName) del sys.modules['post_script'] sys.path.remove(scriptDir) return ret
def getAllKeystores(appName): fileName = "games/" + appName + "/keystore.xml" configFile = file_utils.getFullPath(fileName) try: tree = ET.parse(configFile) root = tree.getroot() except Exception as e: log_utils.error("can not parse keystore.xml.path:%s", configFile) return None channels = root.find("keystores").findall("channel") lstKeystores = [] for cNode in channels: channel = {} params = cNode.findall("param") for cParam in params: key = cParam.get('name') val = cParam.get('value') channel[key] = val lstKeystores.append(channel) return lstKeystores
def mergeJar(workDir, decompileDir): u8sdkJarPath = file_utils.getFullPath('config/local/u8sdkanelib.jar') if not os.path.exists(u8sdkJarPath): log_utils.error("the file is not exists:"+u8sdkJarPath) return 1 targetPath = file_utils.getFullPath(workDir + "/ane") if not os.path.exists(targetPath): os.makedirs(targetPath) file_utils.copy_file(u8sdkJarPath, targetPath+"/u8sdkanelib.jar") jar2dex(targetPath, targetPath) smaliPath = file_utils.getFullPath(decompileDir + "/smali") return dex2smali(targetPath + '/classes.dex', smaliPath)
def appendAppIdForQZone(pluginInfo, decompileDir): qzoneAppID = None subplugins = pluginInfo.get('subplugins') appId = 0 if subplugins != None and len(subplugins) > 0: for subplg in subplugins: if subplg['name'] == "QZone": params = subplg.get('params') for param in params: if param['name'] == 'AppId': appId = int(param['value']) break if appId > 0: break if appId == 0: return manifestFile = decompileDir + "/AndroidManifest.xml" manifestFile = file_utils.getFullPath(manifestFile) ET.register_namespace('android', androidNS) tree = ET.parse(manifestFile) root = tree.getroot() applicationNode = root.find('application') if applicationNode is None: return key = '{'+androidNS+'}name' scheme = '{'+androidNS+'}scheme' activityNodes = applicationNode.findall('activity') if activityNodes != None and len(activityNodes) > 0: for activityNode in activityNodes: name = activityNode.get(key) if name == 'cn.sharesdk.framework.ShareSDKUIShell': intentNodes = activityNode.findall('intent-filter') if intentNodes != None and len(intentNodes) > 0: for intentNode in intentNodes: dataNode = SubElement(intentNode, 'data') dataNode.set(scheme, 'tencent'+str(appId)) break else: intentNode = SubElement(activityNode, 'intent-filter') dataNode = SubElement(intentNode, 'data') dataNode.set(scheme, 'tencent'+str(appId)) actionNode = SubElement(intentNode, 'action') actionNode.set(key, 'android.intent.action.VIEW') categoryNode = SubElement(intentNode, 'category') categoryNode.set(key, 'android.intent.category.DEFAULT') categoryNode2 = SubElement(intentNode, 'category') categoryNode2.set(key, 'android.intent.category.BROWSABLE') tree.write(manifestFile, 'UTF-8')
def removeStartActivity(decompileDir): manifestFile = decompileDir + "/AndroidManifest.xml" manifestFile = file_utils.getFullPath(manifestFile) ET.register_namespace('android', androidNS) key = '{' + androidNS + '}name' tree = ET.parse(manifestFile) root = tree.getroot() applicationNode = root.find('application') if applicationNode is None: return activityNodeLst = applicationNode.findall('activity') if activityNodeLst is None: return activityName = '' for activityNode in activityNodeLst: bMain = False intentNodeLst = activityNode.findall('intent-filter') if intentNodeLst is None: break for intentNode in intentNodeLst: bFindAction = False bFindCategory = False actionNodeLst = intentNode.findall('action') if actionNodeLst is None: break for actionNode in actionNodeLst: if actionNode.attrib[key] == 'android.intent.action.MAIN': bFindAction = True break categoryNodeLst = intentNode.findall('category') if categoryNodeLst is None: break for categoryNode in categoryNodeLst: if categoryNode.attrib[key] == 'android.intent.category.LAUNCHER': bFindCategory = True break if bFindAction and bFindCategory: bMain = True intentNode.remove(actionNode) intentNode.remove(categoryNode) break if bMain: activityName = activityNode.attrib[key] break tree.write(manifestFile, 'UTF-8') return activityName
def modifyActivityForSingleTop(channel, decompileDir, packageName): manifestFile = decompileDir + "/AndroidManifest.xml" manifestFile = file_utils.getFullPath(manifestFile) ET.register_namespace('android', androidNS) key = '{' + androidNS + '}launchMode' keyName = '{' + androidNS + '}name' tree = ET.parse(manifestFile) root = tree.getroot() applicationNode = root.find('application') if applicationNode is None: return 1 activityNodeLst = applicationNode.findall('activity') if activityNodeLst is None: return activityName = '' for activityNode in activityNodeLst: bMain = False intentNodeLst = activityNode.findall('intent-filter') if intentNodeLst is None: break for intentNode in intentNodeLst: bFindAction = False bFindCategory = False actionNodeLst = intentNode.findall('action') if actionNodeLst is None: break for actionNode in actionNodeLst: if actionNode.attrib[keyName] == 'android.intent.action.MAIN': bFindAction = True break categoryNodeLst = intentNode.findall('category') if categoryNodeLst is None: break for categoryNode in categoryNodeLst: if categoryNode.attrib[keyName] == 'android.intent.category.LAUNCHER': bFindCategory = True break if bFindAction and bFindCategory: bMain = True break if bMain: activityNode.set(key, "singleTop") break tree.write(manifestFile, 'UTF-8') return 0
def generateNewChannelApk(sourceApkFile, empty_file, channelID): file_utils.printF("Now to generate channel %s", channelID) targetApk = file_utils.getFullPath("channels/u8-"+channelID+".apk") file_utils.copy_file(sourceApkFile, targetApk) zipped = zipfile.ZipFile(targetApk, 'a', zipfile.ZIP_DEFLATED) emptyChannelFile = "META-INF/u8channel_{channel}".format(channel=channelID) zipped.write(empty_file, emptyChannelFile) zipped.close()
def dex2smali(dexFile, targetdir, dextool = "baksmali.jar"): """ Transfer the dex to smali. """ if not os.path.exists(dexFile): log_utils.error("the dexfile is not exists. path:%s", dexFile) return 1 if not os.path.exists(targetdir): os.makedirs(targetdir) dexFile = file_utils.getFullPath(dexFile) smaliTool = file_utils.getFullToolPath(dextool) targetdir = file_utils.getFullPath(targetdir) cmd = '"%s" -jar "%s" -o "%s" "%s"' % (file_utils.getJavaCMD(), smaliTool, targetdir, dexFile) ret = file_utils.execFormatCmd(cmd) return ret
def entry(): sourceApkFile = file_utils.getFullPath("u8source.apk") channelsFile = file_utils.getFullPath("channels.txt") if not os.path.exists(channelsFile): file_utils.printF("The channels.txt file is not exists.") return f = open(channelsFile) channelLines = f.readlines() f.close() channels = [] if channelLines != None and len(channelLines) > 0: for line in channelLines: targetChannel = line.strip() channels.append(targetChannel) else: file_utils.printF("There is no channel configed in channels.txt") modify(channels, sourceApkFile)
def getPackageName(decompileDir): """ Get The package attrib of application node in AndroidManifest.xml """ manifestFile = decompileDir + "/AndroidManifest.xml" manifestFile = file_utils.getFullPath(manifestFile) ET.register_namespace('android', androidNS) tree = ET.parse(manifestFile) root = tree.getroot() package = root.attrib.get('package') return package
def copyAppResources(game, decompileDir): """ Copy game res files to apk. """ resPath = "games/" + game['appName'] + "/res" resPath = file_utils.getFullPath(resPath) if not os.path.exists(resPath): log_utils.warning("the game %s has no extra res folder", game['appName']) return assetsPath = os.path.join(resPath, 'assets') libsPath = os.path.join(resPath, 'libs') resourcePath = os.path.join(resPath, 'res') targetAssetsPath = os.path.join(decompileDir, 'assets') targetLibsPath = os.path.join(decompileDir, 'lib') targetResourcePath = os.path.join(decompileDir, 'res') decompileDir = file_utils.getFullPath(decompileDir) copyResToApk(assetsPath, targetAssetsPath) copyResToApk(libsPath, targetLibsPath) copyResToApk(resourcePath, targetResourcePath)
def generateShareSDKXmlFile(pluginInfo, decompileDir): assetsPath = file_utils.getFullPath(decompileDir) + "/assets" if not os.path.exists(assetsPath): os.makedirs(assetsPath) shareSdkXml = assetsPath + "/ShareSDK.xml" if os.path.exists(shareSdkXml): os.remove(shareSdkXml) tree = ElementTree() root = Element('DevInfor') tree._setroot(root) shareNode = SubElement(root, 'ShareSDK') if 'params' in pluginInfo and pluginInfo['params'] != None and len(pluginInfo['params']) > 0: for param in pluginInfo['params']: paramName = param.get('name') if paramName == 'AppKey': paramValue = param.get('value') shareNode.set('AppKey', paramValue) break subplugins = pluginInfo.get('subplugins') if subplugins != None and len(subplugins) > 0: index = 1 for subplg in subplugins: subplgNode = SubElement(root, subplg['name']) subparams = subplg.get('params') if subparams != None and len(subparams) > 0: for subparam in subparams: subplgNode.set(subparam['name'], subparam['value']) if subplgNode.get('Id') == None: subplgNode.set('Id', str(index)) else: subplgNode.attrib['Id'] = str(index) if subplgNode.get('Enable') == None: subplgNode.set('Enable', 'true') else: subplgNode.attrib['Enable'] = 'true' index = index + 1 tree.write(shareSdkXml, 'UTF-8')
def signApkInternal(apkfile, keystore, password, alias, aliaspwd): apkfile = file_utils.getFullPath(apkfile) keystore = file_utils.getFullPath(keystore) aapt = file_utils.getFullToolPath("aapt") if not os.path.exists(keystore): log_utils.error("the keystore file is not exists. %s", keystore) return 1 listcmd = '%s list %s' % (aapt, apkfile) output = os.popen(listcmd).read() for filename in output.split('\n'): if filename.find('META_INF') == 0: rmcmd = '"%s" remove "%s" "%s"' % (aapt, apkfile, filename) file_utils.execFormatCmd(rmcmd) signcmd = '"%sjarsigner" -digestalg SHA1 -sigalg SHA1withRSA -keystore "%s" -storepass "%s" -keypass "%s" "%s" "%s" ' % (file_utils.getJavaBinDir(), keystore, password, aliaspwd, apkfile, alias) ret = file_utils.execFormatCmd(signcmd) return ret
def getLocalConfig(): configFile = file_utils.getFullPath("config/local/local.properties") if not os.path.exists(configFile): print("local.properties is not exists. %s " % configFile) return None cf = open(configFile, "r") lines = cf.readlines() cf.close() config = {} for line in lines: line = line.strip() dup = line.split('=') config[dup[0]] = dup[1] return config
def getDefaultKeystore(appName): fileName = "games/" + appName + "/keystore.xml" configFile = file_utils.getFullPath(fileName) try: tree = ET.parse(configFile) root = tree.getroot() except Exception as e: log_utils.error("can not parse keystore.xml.path:%s", configFile) return None params = root.find("default").findall("param") channel = {} for cParam in params: key = cParam.get('name') val = cParam.get('value') channel[key] = val return channel
def main(game, isPublic, target): appName = game['appName'] channels = config_utils.getAllChannels(appName, isPublic) if channels is None or len(channels) == 0: print("没有任何可以打包的渠道") return 3 selected = [] if target == '*': selected = channels else: for t in target.split(','): t = t.strip() matchChannels = [c for c in channels if c['name'].lower() == t.lower()] if len(matchChannels) > 0: selected.append(matchChannels[0]) clen = len(selected) log_utils.info("now hava %s channels to package...", clen) baseApkPath = file_utils.getFullPath('games/'+game['appName']+'/u8.apk') log_utils.info("the base apk file is : %s", baseApkPath) if not os.path.exists(baseApkPath): log_utils.error('the base apk file is not exists, must named with u8.apk') return 2 sucNum = 0 failNum = 0 for channel in selected: ret = core.pack(game, channel, baseApkPath, isPublic) if ret: exit(1) failNum = failNum + 1 else: sucNum = sucNum + 1 log_utils.info("<< success num:%s; failed num:%s >>", sucNum, failNum) if failNum > 0: log_utils.error("<< all done with error >>") else: log_utils.info("<< all nice done >>") return 0
def getAppKey(): configFile = file_utils.getFullPath("config/config.xml") try: tree = ET.parse(configFile) root = tree.getroot() except Exception as e: log_utils.error("can not parse config.xml.path:%s", configFile) return None gameNode = root.find("game") if gameNode == None: return None appID = gameNode.get('appKey') return appID
def writeDeveloperProperties(appID, appKey, channel, targetFilePath): targetFilePath = file_utils.getFullPath(targetFilePath) proStr = "" if channel['params'] != None and len(channel['params']) > 0: for param in channel['params']: if param['bWriteInClient'] == '1': proStr = proStr + param['name'] + "=" + param['value'] + "\n" if "sdkLogicVersionCode" in channel: proStr = proStr + "U8_SDK_VERSION_CODE=" + channel["sdkLogicVersionCode"] + "\n" proStr = proStr + "U8_Channel=" + channel['id'] + "\n" proStr = proStr + "U8_APPID=" + appID + "\n" proStr = proStr + "U8_APPKEY=" + appKey + "\n" #append u8 local config local_config = getLocalConfig() if "use_u8_auth" not in local_config or "u8_auth_url" not in local_config: log_utils.error("the use_u8_auth or u8_auth_url is not exists in local.properties. don't use u8 auth.") return if local_config['use_u8_auth'] == "1": proStr = proStr + "U8_AUTH_URL=" + local_config['u8_auth_url'] + "\n" #write third plugin info: plugins = channel.get('third-plugins') if plugins != None and len(plugins) > 0: for plugin in plugins: if 'params' in plugin and plugin['params'] != None and len(plugin['params']) > 0: for param in plugin['params']: if param['bWriteInClient'] == '1': proStr = proStr + param['name'] + "=" + param['value'] + "\n" log_utils.debug("the develop info is %s", proStr) targetFile = open(targetFilePath, 'wb') proStr = proStr.encode('UTF-8') targetFile.write(proStr) targetFile.close()
def loadChannelUserConfig(appName, channel): configFile = file_utils.getFullPath("config/sdk/" + channel['sdk'] + "/config.xml") if not os.path.exists(configFile): log_utils.error("the config.xml is not exists of sdk %s.path:%s", channel['name'], configFile) return 0 try: tree = ET.parse(configFile) root = tree.getroot() except: log_utils.error("can not parse config.xml.path:%s", configFile) return 0 configNode = root paramNodes = configNode.find("params") channel['params'] = [] if paramNodes != None and len(paramNodes) > 0: for paramNode in paramNodes: param = {} param['name'] = paramNode.get('name') param['required'] = paramNode.get('required') if param['required'] == '1': key = param['name'] if key in channel['sdkParams'] and channel['sdkParams'][key] != None: param['value'] = channel['sdkParams'][key] else: log_utils.error("the sdk %s 'sdkParam's is not all configed in the config.xml.path:%s", channel['name'], configFile) return 0 else: param['value'] = paramNode.get('value') param['showName'] = paramNode.get('showName') param['bWriteInManifest'] = paramNode.get('bWriteInManifest') param['bWriteInClient'] = paramNode.get('bWriteInClient') channel['params'].append(param) operationNodes = configNode.find("operations") channel['operations'] = [] if operationNodes != None and len(operationNodes) > 0: for opNode in operationNodes: op = {} op['type'] = opNode.get('type') op['from'] = opNode.get('from') op['to'] = opNode.get('to') channel['operations'].append(op) pluginNodes = configNode.find("plugins") if pluginNodes != None and len(pluginNodes) > 0: channel['plugins'] = [] for pNode in pluginNodes: p = {} p['name'] = pNode.get('name') p['type'] = pNode.get('type') channel['plugins'].append(p) versionNode = configNode.find("version") if versionNode != None and len(versionNode) > 0: versionCodeNode = versionNode.find("versionCode") versionNameNode = versionNode.find("versionName") # the sdk version code is used to check version update for the sdk. if versionCodeNode != None and versionNameNode != None: channel['sdkVersionCode'] = versionCodeNode.text channel['sdkVersionName'] = versionNameNode.text return 1
def load_plugin_config(channel, plugin, tblSDKParams): configFile = file_utils.getFullPath("config/plugin/" + plugin["name"] + "/config.xml") if not os.path.exists(configFile): log_utils.error("the plugin %s config.xml file is not exists.path:%s", plugin["name"], configFile) return 1 try: tree = ET.parse(configFile) root = tree.getroot() except: log_utils.error("can not parse config.xml.path:%s", configFile) return 1 configNode = root # subpluginNodes = configNode.find("subplugins") # if subpluginNodes != None and len(subpluginNodes) > 0: # plugin['subplugins'] = [] # for subNode in subpluginNodes: # subplugin = {} # subplugin['name'] = subNode.get('name') # subplugin['desc'] = subNode.get('desc') # subParamNodes = subNode.findall('param') # subplugin['params'] = [] # if subParamNodes != None and len(subParamNodes) > 0: # for subParamNode in subParamNodes: # param = {} # param['name'] = subParamNode.get('name') # param['value'] = subParamNode.get('value') # #log_utils.debug("name:"+param['name']+";val:"+param['value']) # param['required'] = subParamNode.get('required') # param['showName'] = subParamNode.get('showName') # param['bWriteInManifest'] = subParamNode.get('bWriteInManifest') # param['bWriteInClient'] = subParamNode.get('bWriteInClient') # subplugin['params'].append(param) # plugin['subplugins'].append(subplugin) paramNodes = configNode.find("params") plugin['params'] = [] if paramNodes != None and len(paramNodes) > 0: for paramNode in paramNodes: param = {} param['name'] = paramNode.get('name') param['value'] = paramNode.get('value') param['required'] = paramNode.get('required') param['showName'] = paramNode.get('showName') param['bWriteInManifest'] = paramNode.get('bWriteInManifest') param['bWriteInClient'] = paramNode.get('bWriteInClient') if param['name'] in tblSDKParams: param['value'] = tblSDKParams[param["name"]] plugin['params'].append(param) operationNodes = configNode.find("operations") plugin['operations'] = [] if operationNodes != None and len(operationNodes) > 0: for opNode in operationNodes: op = {} op['type'] = opNode.get('type') op['from'] = opNode.get('from') op['to'] = opNode.get('to') plugin['operations'].append(op) pluginNodes = configNode.find("plugins") if pluginNodes != None and len(pluginNodes) > 0: plugin['plugins'] = [] for pNode in pluginNodes: p = {} p['name'] = pNode.get('name') p['type'] = pNode.get('type') plugin['plugins'].append(p) extraRNodes = configNode.find("extraR") if extraRNodes != None and len(extraRNodes) > 0: if "extraRList" not in plugin: plugin["extraRList"] = [] for rNode in extraRNodes: name = rNode.get('name') if name != None and len( name) > 0 and name not in plugin["extraRList"]: plugin["extraRList"].append(name) # log_utils.debug("add a new extra R package:"+name) if "dependencyList" not in plugin: plugin["dependencyList"] = [] dependencyNodes = configNode.find('dependencies') if dependencyNodes != None and len(dependencyNodes) > 0: for rNode in dependencyNodes: name = rNode.get('name') if name != None and len(name) > 0: dependencyItem = dict() dependencyItem["name"] = name excludes = rNode.get('excludes') if excludes != None and len(excludes) > 0: dependencyItem["excludes"] = excludes plugin["dependencyList"].append(dependencyItem) return 0
def load_channel_user_config(game, channel, tblSDKParams): configFile = file_utils.getFullPath("config/sdk/" + channel['sdk'] + "/config.xml") if not os.path.exists(configFile): log_utils.error("the config.xml is not exists of sdk %s.path:%s", channel['name'], configFile) return 1 try: tree = ET.parse(configFile) root = tree.getroot() except: log_utils.error("can not parse config.xml.path:%s", configFile) return 1 configNode = root channel['params'] = [] for pkey in tblSDKParams: param = {} param['name'] = pkey param['value'] = tblSDKParams[pkey]["value"] param['required'] = '1' param['showName'] = '' param['bWriteInManifest'] = tblSDKParams[pkey]["toMetaData"] param['bWriteInClient'] = tblSDKParams[pkey]["toConfig"] channel['params'].append(param) paramNodes = configNode.find("params") if paramNodes != None and len(paramNodes) > 0: for paramNode in paramNodes: param = {} param['name'] = paramNode.get('name') param['required'] = paramNode.get('required') if param['required'] == '1': log_utils.warning( "all params in config.xml must be not required to config in web client. so required must be 0 for param %s", param['name']) continue if param['name'] in tblSDKParams: log_utils.warning( "key %s both configed in web client and config.xml. select the one in web client." ) continue param['value'] = paramNode.get('value') param['showName'] = paramNode.get('showName') param['bWriteInManifest'] = paramNode.get('bWriteInManifest') param['bWriteInClient'] = paramNode.get('bWriteInClient') channel['params'].append(param) # 支持sdk-params里面配置额外的参数,默认写到assets下面u8_developer_config.properties中 # begin # if channel['sdkParams'] is not None: # for key in channel['sdkParams']: # extraKey = True # if channel['params'] is not None and len(channel['params']) > 0: # for p in channel['params']: # if p['name'] == key: # extraKey = False # break # if extraKey: # param = {} # param['name'] = key # param['value'] = channel['sdkParams'][key] # param['required'] = "1" # param['showName'] = key # param['bWriteInManifest'] = "0" # param['bWriteInClient'] = "1" # channel['params'].append(param) # end # 支持sdk-params里面配置额外的参数,默认写到assets下面u8_developer_config.properties中 operationNodes = configNode.find("operations") channel['operations'] = [] if operationNodes != None and len(operationNodes) > 0: for opNode in operationNodes: op = {} op['type'] = opNode.get('type') op['from'] = opNode.get('from') op['to'] = opNode.get('to') channel['operations'].append(op) pluginNodes = configNode.find("plugins") if pluginNodes != None and len(pluginNodes) > 0: channel['plugins'] = [] for pNode in pluginNodes: p = {} p['name'] = pNode.get('name') p['type'] = pNode.get('type') channel['plugins'].append(p) versionNode = configNode.find("version") if versionNode != None and len(versionNode) > 0: versionCodeNode = versionNode.find("versionCode") versionNameNode = versionNode.find("versionName") # the sdk version code is used to check version update for the sdk. if versionCodeNode != None and versionNameNode != None: channel['sdkVersionCode'] = versionCodeNode.text channel['sdkVersionName'] = versionNameNode.text extraRNodes = configNode.find("extraR") if extraRNodes != None and len(extraRNodes) > 0: if "extraRList" not in channel: channel["extraRList"] = [] for rNode in extraRNodes: name = rNode.get('name') if name != None and len( name) > 0 and name not in channel["extraRList"]: channel["extraRList"].append(name) # log_utils.debug("add a new extra R package:"+name) if "dependencyList" not in channel: channel["dependencyList"] = [] dependencyNodes = configNode.find('dependencies') if dependencyNodes != None and len(dependencyNodes) > 0: for rNode in dependencyNodes: name = rNode.get('name') if name != None and len(name) > 0: dependencyItem = dict() dependencyItem["name"] = name excludes = rNode.get('excludes') if excludes != None and len(excludes) > 0: dependencyItem["excludes"] = excludes channel["dependencyList"].append(dependencyItem) return 0
def writeDeveloperProperties(game, channel, targetFilePath): targetFilePath = file_utils.getFullPath(targetFilePath) if os.path.exists(targetFilePath): file_utils.del_file_folder(targetFilePath) proStr = "" if channel['params'] != None and len(channel['params']) > 0: for param in channel['params']: if param['bWriteInClient'] == '1': proStr = proStr + param['name'] + "=" + param['value'] + "\n" if "sdkLogicVersionCode" in channel: proStr = proStr + "U8_SDK_VERSION_CODE=" + channel[ "sdkLogicVersionCode"] + "\n" proStr = proStr + "U8_Channel=" + channel['id'] + "\n" proStr = proStr + "U8_APPID=" + game["appID"] + "\n" proStr = proStr + "U8_APPKEY=" + game["appKey"] + "\n" if "payPrivateKey" in game: proStr = proStr + "U8_PAY_PRIVATEKEY=" + game["payPrivateKey"] + "\n" showSplash = "false" if "splash" in channel and int(channel["splash"]) > 0: showSplash = "true" proStr = proStr + "U8_SDK_SHOW_SPLASH=" + showSplash + "\n" authUrl = None orderUrl = None analyticsUrl = None u8serverUrl = None u8analytics = None if "u8_auth_url" in game: authUrl = game["u8_auth_url"] if "u8_order_url" in game: orderUrl = game["u8_order_url"] if "u8_analytics_url" in game: analyticsUrl = game["u8_analytics_url"] if "u8server_url" in game: u8serverUrl = game["u8server_url"] if "u8_analytics" in game: u8analytics = game["u8_analytics"] #append u8 local config local_config = getLocalConfig() if authUrl is None and "u8_auth_url" in local_config: authUrl = local_config['u8_auth_url'] if orderUrl is None and "u8_order_url" in local_config: orderUrl = local_config['u8_order_url'] if u8serverUrl is None and "u8server_url" in local_config: u8serverUrl = local_config['u8server_url'] if u8analytics is None and "u8_analytics" in local_config: u8analytics = local_config['u8_analytics'] if analyticsUrl is None and "u8_analytics_url" in local_config: analyticsUrl = local_config['u8_analytics_url'] if authUrl is not None: proStr = proStr + "U8_AUTH_URL=" + authUrl + "\n" if orderUrl is not None: proStr = proStr + "U8_ORDER_URL=" + orderUrl + "\n" if analyticsUrl is not None: proStr = proStr + "U8_ANALYTICS_URL=" + analyticsUrl + "\n" if u8serverUrl is not None: proStr = proStr + "U8SERVER_URL=" + u8serverUrl + "\n" if u8analytics is not None: proStr = proStr + "U8_ANALYTICS=" + u8analytics + "\n" #write third plugin info: plugins = channel.get('third-plugins') if plugins != None and len(plugins) > 0: for plugin in plugins: if 'params' in plugin and plugin['params'] != None and len( plugin['params']) > 0: for param in plugin['params']: if param['bWriteInClient'] == '1': proStr = proStr + param['name'] + "=" + param[ 'value'] + "\n" log_utils.debug("the develop info is %s", proStr) targetFile = open(targetFilePath, 'wb') proStr = proStr.encode('UTF-8') targetFile.write(proStr) targetFile.close()
def pack(game, channel, sourcepath, isPublic): sourcepath = sourcepath.replace('\\', '/') if not os.path.exists(sourcepath): return 1 appID = game['appID'] appKey = game['appKey'] appName = game['appName'] channelId = channel["id"] channelName = channel["name"] sdkName = channel["sdk"] log_utils.info("now to package %s...", channelName) workDir = 'workspace/' + appName + '/' + channelName workDir = file_utils.getFullPath(workDir) file_utils.del_file_folder(workDir) tempApkSource = workDir + "/temp.apk" file_utils.copy_file(sourcepath, tempApkSource) decompileDir = workDir + "/decompile" smaliDir = decompileDir + "/smali" #反编译APK ret = apk_utils.decompileApk(tempApkSource, decompileDir) if ret: return 1 #检查母包接入是否正确 ret = apk_utils.checkApkForU8SDK(workDir, decompileDir) if ret: return 1 #change xml config and so on newPackageName = apk_utils.renamePackageName(channel, decompileDir, channel['suffix'], isPublic) #copy third-plugins resources. note:The third plugins must be operated before the main sdk. ret = apk_utils.handleThirdPlugins(workDir, decompileDir, game, channel, newPackageName) if ret: return 1 #copy sdk code to decompileDir sdkSourceDir = 'config/sdk/' + sdkName sdkSourceDir = file_utils.getFullPath(sdkSourceDir) sdkDestDir = workDir + "/sdk/" + sdkName file_utils.copy_files(sdkSourceDir, sdkDestDir) #将公共库复制到临时目录,除了moyoihw渠道 if sdkName != 'moyoihw': promptDir = 'config/local/common-release.aar' promptDestDir = sdkDestDir + '/libs/common-release.aar'; file_utils.copy_files(promptDir, promptDestDir) #处理需要Gradle自动下载的库 if 'dependencies' in channel and channel['dependencies'] != None and len(channel['dependencies']) > 0: #将build.gradle复制到临时目录 localSourceDir = 'config/local/build.gradle' file_utils.copy_files(localSourceDir, sdkDestDir + '/build.gradle') #修改build.gradle config_utils.writeGradleDependencies(channel['dependencies'], sdkDestDir) #将SDK中所有aar文件解压,然后将里面各个类型的资源文件合并到SDK对应目录 file_utils.decomAAR(sdkDestDir) ret = apk_utils.jar2dex(sdkDestDir, sdkDestDir) if ret: return 1 ret = apk_utils.dexes2smali(sdkDestDir, smaliDir, "baksmali.jar") if ret: return 1 #copy main sdk resources. ret = apk_utils.copyResource(game, channel, newPackageName, sdkDestDir, decompileDir, channel['operations'], channelName) if ret: return 1 #auto handle icon apk_utils.appendChannelIconMark(game, channel, decompileDir) #copy channel special resources ret = apk_utils.copyChannelResources(game, channel, decompileDir) if ret: return 1 #copy game root resources and res resources apk_utils.copyAppResources(game, decompileDir) apk_utils.copyAppRootResources(game, decompileDir) #generate config files for apk to run. apk_utils.writeDevelopInfo(game, channel, decompileDir) apk_utils.writePluginInfo(channel, decompileDir) apk_utils.writeManifestMetaInfo(channel, decompileDir) apk_utils.writeLogConfig(game, decompileDir) #if the main sdk has special logic. execute the special logic script. ret = apk_utils.doSDKScript(channel, decompileDir, newPackageName, sdkDestDir) if ret: return 1 #if the game has some special logic. execute the special logic script.called post_script.py ret = apk_utils.doGamePostScript(game, channel, decompileDir, newPackageName) if ret: return 1 #here to config the splash screen. ret = apk_utils.addSplashScreen(workDir, channel, decompileDir) if ret: return 1 #check cpu supports apk_utils.checkCpuSupport(game, decompileDir) #modify game name if channel specified. apk_utils.modifyGameName(channel, decompileDir) #modify yml apk_utils.modifyYml(game, newPackageName, decompileDir) #generate new R.java ret = apk_utils.generateNewRFile(newPackageName, decompileDir, channel) if ret: return 1 #check to split dex apk_utils.splitDex(workDir, decompileDir) targetApk = workDir + "/output.apk" log_utils.debug("now to recompileApk....") ret = apk_utils.recompileApk(decompileDir, targetApk) if ret: return 1 apk_utils.copyRootResFiles(targetApk, decompileDir) if 'signApk' not in channel or channel['signApk'] != '0': apk_utils.xsigncode(workDir, game, channel, targetApk) apk_utils.signApk(workDir, game, channel, targetApk) else: log_utils.debug("the apk is set to unsigned.") channelNameStr = channelName.replace(' ', '') if isPublic: destApkName = apk_utils.getOutputApkName(game, channel, newPackageName, decompileDir) else: destApkName = channelNameStr + '-' + time.strftime('%Y%m%d%H') + '-debug.apk' destApkPath = file_utils.getFullOutputPath(appName, channelName) destApkPath = os.path.join(destApkPath, destApkName) ret = apk_utils.alignApk(targetApk, destApkPath) if ret: return 1 log_utils.info("channel %s package success.", channelName) return 0
def pack(game, channel, sourcepath, isPublic): sourcepath = sourcepath.replace('\\', '/') if not os.path.exists(sourcepath): return 1 appID = game['appID'] appKey = game['appKey'] appName = game['appName'] channelId = channel["id"] channelName = channel["name"] sdkName = channel["sdk"] log_utils.info("now to package %s...", channelName) workDir = 'workspace/' + appName + '/' + channelName workDir = file_utils.getFullPath(workDir) file_utils.del_file_folder(workDir) tempApkSource = workDir + "/temp.apk" file_utils.copy_file(sourcepath, tempApkSource) decompileDir = workDir + "/decompile" ret = apk_utils.decompileApk(tempApkSource, decompileDir) if ret: return 1 #检查母包接入是否正确 # ret = apk_utils.checkApkForU8SDK(workDir, decompileDir) # if ret: # return 1 apk_utils.addLocalJars(workDir, decompileDir) #检查multidex那个jar包 apk_utils.checkMultiDexJar(workDir, decompileDir) #change xml config and so on newPackageName = apk_utils.renamePackageName(channel, decompileDir, channel['suffix'], isPublic) #copy third-plugins resources. note:The third plugins must be operated before the main sdk. ret = apk_utils.handleThirdPlugins(workDir, decompileDir, game, channel, newPackageName) if ret: return 1 #copy sdk code to decompileDir sdkSourceDir = file_utils.getFullPath('config/sdk/' + sdkName) smaliDir = decompileDir + "/smali" sdkDestDir = workDir + "/sdk/" + sdkName file_utils.copy_files(sdkSourceDir, sdkDestDir) if (not os.path.exists(sdkSourceDir + "/classes.dex")): ret = apk_utils.jar2dex(sdkSourceDir, sdkDestDir) if ret: return 1 ret = apk_utils.dexes2smali(sdkDestDir, smaliDir, "baksmali.jar") if ret: return 1 #copy main sdk resources. ret = apk_utils.copyResource(game, channel, newPackageName, sdkDestDir, decompileDir, channel['operations'], channelName) if ret: return 1 #auto handle icon apk_utils.appendChannelIconMark(game, channel, decompileDir) #copy channel special resources ret = apk_utils.copyChannelResources(game, channel, decompileDir) if ret: return 1 #copy game root resources and res resources apk_utils.copyAppResources(game, decompileDir) apk_utils.copyAppRootResources(game, decompileDir) #generate config files for apk to run. apk_utils.writeDevelopInfo(game, channel, decompileDir) apk_utils.writePluginInfo(channel, decompileDir) apk_utils.writeManifestMetaInfo(channel, decompileDir) apk_utils.writeLogConfig(game, decompileDir) #if the main sdk has special logic. execute the special logic script. ret = apk_utils.doSDKScript(channel, decompileDir, newPackageName, sdkDestDir) if ret: return 1 #if the game has some special logic. execute the special logic script.called post_script.py ret = apk_utils.doGamePostScript(game, channel, decompileDir, newPackageName) if ret: return 1 #here to config the splash screen. ret = apk_utils.addSplashScreen(workDir, channel, decompileDir) if ret: return 1 #check cpu supports apk_utils.checkCpuSupport(game, decompileDir) #modify game name if channel specified. apk_utils.modifyGameName(channel, decompileDir) #modify yml apk_utils.modifyYml(game, newPackageName, decompileDir) #generate new R.java ret = apk_utils.generateNewRFile(newPackageName, decompileDir, channel) if ret: return 1 #check to split dex timeBefore = time.time() apk_utils.splitDex(workDir, decompileDir) log_utils.debug("split cost time(s):" + str(time.time() - timeBefore)) if isPublic: #destApkName = channelNameStr + '-' + time.strftime('%Y%m%d%H') + '.apk' destApkName = apk_utils.getOutputApkName(game, channel, newPackageName, decompileDir) else: channelNameStr = channelName.replace(' ', '') destApkName = channelNameStr + '-' + time.strftime( '%Y%m%d%H') + '-debug.apk' ret = recompileApk(workDir, decompileDir, game, channel, destApkName) if ret: return 1 if "subIDs" in channel and len(channel["subIDs"]) > 0: #generate sub channel packages for t in channel["subIDs"].split(','): t = t.strip() log_utils.debug("now to package sub channel %s", t) ret = apk_utils.writeSubChannel(t, decompileDir) if ret: return 1 destApkName = apk_utils.getOutputApkName(game, channel, newPackageName, decompileDir) fname, fext = os.path.splitext(destApkName) destApkName = fname + "_" + t + fext ret = recompileApk(workDir, decompileDir, game, channel, destApkName) if ret: return 1 # targetApk = workDir + "/output.apk" # log_utils.debug("now to recompileApk....") # ret = apk_utils.recompileApk(decompileDir, targetApk) # if ret: # return 1 # apk_utils.copyRootResFiles(targetApk, decompileDir) # if 'signApk' not in channel or channel['signApk'] != '0': # ret = apk_utils.signApk(workDir, game, channel, targetApk) # if ret: # return 1 # else: # log_utils.debug("the apk is set to unsigned.") # #destApkName = channelName + '.apk' # channelNameStr = channelName.replace(' ', '') # if isPublic: # #destApkName = channelNameStr + '-' + time.strftime('%Y%m%d%H') + '.apk' # destApkName = apk_utils.getOutputApkName(game, channel, newPackageName, decompileDir) # else: # destApkName = channelNameStr + '-' + time.strftime('%Y%m%d%H') + '-debug.apk' # destApkPath = file_utils.getFullOutputPath(appName, channelName) # destApkPath = os.path.join(destApkPath, destApkName) # ret = apk_utils.alignApk(targetApk, destApkPath) # if ret: # return 1 #clear workspace #file_utils.del_file_folder(workDir) log_utils.info("channel %s package success.", channelName) return 0
def modifyActivityForSingleTop(channel, decompileDir, packageName): manifestFile = decompileDir + "/AndroidManifest.xml" manifestFile = file_utils.getFullPath(manifestFile) ET.register_namespace('android', androidNS) key = '{' + androidNS + '}launchMode' keyName = '{' + androidNS + '}name' screenKey = '{' + androidNS + '}screenOrientation' tree = ET.parse(manifestFile) root = tree.getroot() applicationNode = root.find('application') if applicationNode is None: return 1 activityNodeLst = applicationNode.findall('activity') if activityNodeLst is None: return activityName = '' screenOrientation = 'sensorLandscape' for activityNode in activityNodeLst: bMain = False intentNodeLst = activityNode.findall('intent-filter') if intentNodeLst is None: break for intentNode in intentNodeLst: bFindAction = False bFindCategory = False actionNodeLst = intentNode.findall('action') if actionNodeLst is None: break for actionNode in actionNodeLst: if actionNode.attrib[keyName] == 'android.intent.action.MAIN': bFindAction = True break categoryNodeLst = intentNode.findall('category') if categoryNodeLst is None: break for categoryNode in categoryNodeLst: if categoryNode.attrib[ keyName] == 'android.intent.category.LAUNCHER': bFindCategory = True break if bFindAction and bFindCategory: bMain = True break if bMain: activityNode.set(key, "singleTop") screenOrientation = activityNode.get(screenKey) break activityNodes = applicationNode.findall('activity') if activityNodes != None and len(activityNodes) > 0: for activityNode in activityNodes: activityName = activityNode.get(keyName) if activityName == 'com.tencent.midas.proxyactivity.APMidasPayProxyActivity': if screenOrientation and len(screenOrientation) > 0: activityNode.set(screenKey, screenOrientation) else: activityNode.set(screenKey, 'portrait') break tree.write(manifestFile, 'UTF-8') return 0
def execute(channel, pluginInfo, decompileDir, packageName): if 'params' in pluginInfo and len(pluginInfo['params']) > 0: for param in pluginInfo['params']: name = param.get('name') if name == 'UMENG_CHANNEL': param['value'] = channel['name'] break manifestFile = decompileDir + "/AndroidManifest.xml" manifestFile = file_utils.getFullPath(manifestFile) ET.register_namespace('android', androidNS) key = '{' + androidNS + '}launchMode' tree = ET.parse(manifestFile) root = tree.getroot() package = root.attrib.get('package') applicationNode = root.find('application') if applicationNode is None: return 1 key = '{' + androidNS + '}name' receiverNodeList = applicationNode.findall('receiver') if receiverNodeList != None: for node in receiverNodeList: if node.attrib[key] == 'com.umeng.message.RegistrationReceiver': intentNodeLst = node.findall('intent-filter') if intentNodeLst is None: break for intentNode in intentNodeLst: actionNodeList = intentNode.findall('action') if actionNodeList is None: break for actionNode in actionNodeList: if actionNode.attrib[key].endswith( 'intent.action.COMMAND'): newVal = package + ".intent.action.COMMAND" actionNode.set(key, newVal) serviceNodeList = applicationNode.findall('service') if serviceNodeList != None: for node in serviceNodeList: if node.attrib[key] == 'com.umeng.message.UmengService': intentNodeLst = node.findall('intent-filter') if intentNodeLst is None: break for intentNode in intentNodeLst: actionNodeList = intentNode.findall('action') if actionNodeList is None: break for actionNode in actionNodeList: if actionNode.attrib[key].endswith( 'intent.action.START'): newVal = package + '.intent.action.START' actionNode.set(key, newVal) if actionNode.attrib[key].endswith( 'intent.action.COCKROACH'): newVal = package + '.intent.action.COCKROACH' actionNode.set(key, newVal) tree.write(manifestFile, 'UTF-8') return 0
def getAllChannels(appName, isPublic): fileName = "games/" + appName + "/config.xml" configFile = file_utils.getFullPath(fileName) try: tree = ET.parse(configFile) root = tree.getroot() except Exception as e: log_utils.error("can not parse config.xml.path:%s",configFile) return None lstGPlugins = [] globalPluginsNode = root.find("global-plugins") if globalPluginsNode is not None: globalPlugins = globalPluginsNode.findall("plugin") if globalPlugins is not None and len(globalPlugins) > 0: for pluginNode in globalPlugins: plugin = {} plugin['name'] = pluginNode.get("name") plugin['desc'] = pluginNode.get("desc") lstGPlugins.append(plugin) channels = root.find("channels").findall("channel") lstChannels = [] for cNode in channels: channel = {} params = cNode.findall("param") for cParam in params: key = cParam.get('name') val = cParam.get('value') channel[key] = val sdkVersionNode = cNode.find('sdk-version') if sdkVersionNode != None and len(sdkVersionNode) > 0: versionCodeNode = sdkVersionNode.find('versionCode') versionNameNode = sdkVersionNode.find('versionName') if versionCodeNode != None and versionNameNode != None: # yxmeserver use the logic version code to decide which sdk version to use channel['sdkLogicVersionCode'] = versionCodeNode.text channel['sdkLogicVersionName'] = versionNameNode.text sdkParams = cNode.find("sdk-params") tblSDKParams = {} if sdkParams != None: sdkParamNodes = sdkParams.findall('param') if sdkParamNodes != None and len(sdkParamNodes) > 0: for cParam in sdkParamNodes: key = cParam.get('name') val = cParam.get('value') tblSDKParams[key] = val channel['sdkParams'] = tblSDKParams if len(lstGPlugins) > 0: for p in lstGPlugins: loadThirdPluginUserConfig(appName, channel, p, p['name']) ret = loadChannelUserConfig(appName, channel) if ret: lstPlugins = [] + lstGPlugins pluginsNode = cNode.find("plugins") if pluginsNode != None: pluginNodeLst = pluginsNode.findall("plugin") if pluginNodeLst != None and len(pluginNodeLst) > 0: for cPlugin in pluginNodeLst: plugin = {} plugin['name'] = cPlugin.get('name') exists = False for p in lstPlugins: if p['name'] == plugin['name']: exists = True break if not exists: plugin['desc'] = cPlugin.get('desc') loadThirdPluginUserConfig(appName, channel, plugin, plugin['name']) lstPlugins.append(plugin) channel['third-plugins'] = lstPlugins lstChannels.append(channel) return lstChannels
def loadChannelUserConfig(appName, channel): #读取config/sdk/渠道/config.xml里的信息 configFile = file_utils.getFullPath("config/sdk/" + channel['sdk'] + "/config.xml") if not os.path.exists(configFile): log_utils.error("the config.xml is not exists of sdk %s.path:%s", channel['name'], configFile) return 0 try: tree = ET.parse(configFile) root = tree.getroot() except: log_utils.error("can not parse config.xml.path:%s", configFile) return 0 configNode = root paramNodes = configNode.find("params") channel['params'] = [] if paramNodes != None and len(paramNodes) > 0: for paramNode in paramNodes: param = {} param['name'] = paramNode.get('name') param['required'] = paramNode.get('required') if param['required'] == '1': key = param['name'] if key in channel['sdkParams'] and channel['sdkParams'][key] != None: param['value'] = channel['sdkParams'][key] else: log_utils.error("the sdk %s 'sdkParam's is not all configed in the config.xml.path:%s", channel['name'], configFile) return 0 else: param['value'] = paramNode.get('value') param['showName'] = paramNode.get('showName') param['bWriteInManifest'] = paramNode.get('bWriteInManifest') param['bWriteInClient'] = paramNode.get('bWriteInClient') channel['params'].append(param) operationNodes = configNode.find("operations") channel['operations'] = [] if operationNodes != None and len(operationNodes) > 0: for opNode in operationNodes: op = {} op['type'] = opNode.get('type') op['from'] = opNode.get('from') op['to'] = opNode.get('to') channel['operations'].append(op) pluginNodes = configNode.find("plugins") if pluginNodes != None and len(pluginNodes) > 0: channel['plugins'] = [] for pNode in pluginNodes: p = {} p['name'] = pNode.get('name') p['type'] = pNode.get('type') channel['plugins'].append(p) #卢-->判断config。xml中是否有dependencies标签,并拼接到channel中 dependencyNodes = configNode.find("dependencies") if dependencyNodes != None and len(dependencyNodes) > 0: channel['dependencies'] = [] for depenNode in dependencyNodes: depen = {} depen['name'] = depenNode.get('name') if('group' in depenNode.keys()): depen['group'] = depenNode.get('group') if('module' in depenNode.keys()): depen['module'] = depenNode.get('module') if('processor' in depenNode.keys()): depen['processor'] = depenNode.get('processor') channel['dependencies'].append(depen) return 1
def modifyStartActivity(decompileDir, appid, packageName): manifestFile = decompileDir + "/AndroidManifest.xml" manifestFile = file_utils.getFullPath(manifestFile) ET.register_namespace('android', androidNS) key = '{' + androidNS + '}name' valKey = '{'+androidNS+'}value' tree = ET.parse(manifestFile) root = tree.getroot() applicationNode = root.find('application') if applicationNode is None: return metaNode = SubElement(applicationNode, 'meta-data') metaNode.set(key, 'lenovo:channel') metaNode.set(valKey, appid) activityNodeLst = applicationNode.findall('activity') if activityNodeLst is None: return activityName = '' for activityNode in activityNodeLst: bMain = False intentNodeLst = activityNode.findall('intent-filter') if intentNodeLst is None: break for intentNode in intentNodeLst: bFindAction = False bFindCategory = False actionNodeLst = intentNode.findall('action') if actionNodeLst is None: break for actionNode in actionNodeLst: if actionNode.attrib[key] == 'android.intent.action.MAIN': bFindAction = True break categoryNodeLst = intentNode.findall('category') if categoryNodeLst is None: break for categoryNode in categoryNodeLst: if categoryNode.attrib[key] == 'android.intent.category.LAUNCHER': bFindCategory = True break if bFindAction and bFindCategory: bMain = True intentNode.remove(actionNode) actionNode = SubElement(intentNode, 'action') actionNode.set(key, 'lenovoid.MAIN') intentNode.remove(categoryNode) categoryNode = SubElement(intentNode, 'category') categoryNode.set(key, 'android.intent.category.DEFAULT') break if bMain: activityName = activityNode.attrib[key] break for activityNode in activityNodeLst: name = activityNode.get(key) if name == 'com.lenovo.lsf.gamesdk.ui.WelcomeActivity': intentNode = SubElement(activityNode, 'intent-filter') actionNode = SubElement(intentNode, 'action') actionNode.set(key, 'android.intent.action.MAIN') categoryNode = SubElement(intentNode, 'category') categoryNode.set(key, 'android.intent.category.LAUNCHER') receiverNodeLst = applicationNode.findall('receiver') if receiverNodeLst != None: for receiverNode in receiverNodeLst: name = receiverNode.get(key) if name == 'com.lenovo.lsf.gamesdk.receiver.GameSdkReceiver': intentNodeLst = receiverNode.findall('intent-filter') for intentNode in intentNodeLst: actionNode = SubElement(intentNode, 'action') actionNode.set(key, appid) categoryNode = SubElement(intentNode, 'category') categoryNode.set(key, packageName) break elif name == 'com.lenovo.lsf.gamesdk.receiver.GameSdkAndroidLReceiver': intentNodeLst = receiverNode.findall('intent-filter') for intentNode in intentNodeLst: categoryNode = SubElement(intentNode, 'category') categoryNode.set(key, packageName) break providerNodeLst = applicationNode.findall('provider') if providerNodeLst != None: for providerNode in providerNodeLst: name = providerNode.get(key) if name == 'android.support.v4.content.FileProvider': providerNode.set('{'+androidNS+'}authorities',packageName+'.fileprovider') break tree.write(manifestFile, 'UTF-8') return activityName
def loadThirdPluginUserConfig(appName, channel, plugin, pluginName): #configFile = file_utils.getFullPath("config/plugin/" + pluginName + "/config.xml") configFile = file_utils.getFullPath("games/" + appName + "/channels/" + channel['id'] + "/plugin/" + pluginName + "/config.xml") if not os.path.exists(configFile): configFile = file_utils.getFullPath("games/"+appName+"/plugin/"+pluginName+"/config.xml") if not os.path.exists(configFile): log_utils.error("the plugin %s config.xml file is not exists.path:%s", pluginName, configFile) return 0 try: tree = ET.parse(configFile) root = tree.getroot() except: log_utils.error("can not parse config.xml.path:%s", configFile) return 0 configNode = root subpluginNodes = configNode.find("subplugins") if subpluginNodes != None and len(subpluginNodes) > 0: plugin['subplugins'] = [] for subNode in subpluginNodes: subplugin = {} subplugin['name'] = subNode.get('name') subplugin['desc'] = subNode.get('desc') subParamNodes = subNode.findall('param') subplugin['params'] = [] if subParamNodes != None and len(subParamNodes) > 0: for subParamNode in subParamNodes: param = {} param['name'] = subParamNode.get('name') param['value'] = subParamNode.get('value') param['required'] = subParamNode.get('required') param['showName'] = subParamNode.get('showName') param['bWriteInManifest'] = subParamNode.get('bWriteInManifest') param['bWriteInClient'] = subParamNode.get('bWriteInClient') subplugin['params'].append(param) plugin['subplugins'].append(subplugin) paramNodes = configNode.find("params") plugin['params'] = [] if paramNodes != None and len(paramNodes) > 0: for paramNode in paramNodes: param = {} param['name'] = paramNode.get('name') param['value'] = paramNode.get('value') param['required'] = paramNode.get('required') param['showName'] = paramNode.get('showName') param['bWriteInManifest'] = paramNode.get('bWriteInManifest') param['bWriteInClient'] = paramNode.get('bWriteInClient') plugin['params'].append(param) operationNodes = configNode.find("operations") plugin['operations'] = [] if operationNodes != None and len(operationNodes) > 0: for opNode in operationNodes: op = {} op['type'] = opNode.get('type') op['from'] = opNode.get('from') op['to'] = opNode.get('to') plugin['operations'].append(op) pluginNodes = configNode.find("plugins") if pluginNodes != None and len(pluginNodes) > 0: plugin['plugins'] = [] for pNode in pluginNodes: p = {} p['name'] = pNode.get('name') p['type'] = pNode.get('type') plugin['plugins'].append(p) return 1
if not manifest.can_merge_to(baseManifest): log_utils.error("manifest merge failed. %s and %s has same node.", manifest.path(), baseManifest.path()) return False ret = baseManifest.merge_with(manifest) if not ret: return False return True def merge2(baseManifestFile, targetManifestFile): files = [baseManifestFile, targetManifestFile] return merge(files) if __name__ == "__main__": res1 = file_utils.getFullPath("Base_AndroidManifest.xml") res2 = file_utils.getFullPath("SDKManifest.xml") resPaths = [res2, res1] merge2(res2, res1)
def execute(game, channel, decompileDir, packageName): log_utils.debug("now to execute post_script") manifest = decompileDir + '/AndroidManifest.xml' ET.register_namespace('android', androidNS) key = '{' + androidNS + '}name' name = key keyVal = '{' + androidNS + '}value' pLevel = '{' + androidNS + '}protectionLevel' tree = ET.parse(manifest) root = tree.getroot() appNode = root.find('application') if appNode is None: return 1 #设置包名和权限 log_utils.debug("now to change permission and meta-data") permissionLst = root.findall('permission') if permissionLst: for p in permissionLst: pname = p.get(name) if pname == 'com.yxg.juhe.permission.JPUSH_MESSAGE': p.set(name, packageName + ".permission.JPUSH_MESSAGE") break upermissionLst = root.findall('uses-permission') if upermissionLst: for p in upermissionLst: pname = p.get(name) if pname == 'com.yxg.juhe.permission.JPUSH_MESSAGE': p.set(name, packageName + ".permission.JPUSH_MESSAGE") break metaLst = appNode.findall('meta-data') if metaLst: for p in metaLst: pname = p.get(name) if pname == 'CASTLE_PACKAGE_NAME': p.set(keyVal, packageName) break for p in metaLst: pname = p.get(name) if pname == 'JPUSH_APPKEY': appNode.remove(p) #设置包名和权限 #替换包名 log_utils.debug("now to change packageName") activityNodeLst = appNode.findall('activity') if activityNodeLst is None: return for activityNode in activityNodeLst: activityName = activityNode.get(name) if activityName == 'cn.jpush.android.ui.PushActivity': intentFilters = activityNode.findall('intent-filter') for intentNode in intentFilters: categoryNodeLst = intentNode.findall('category') if categoryNodeLst is None: break for categoryNode in categoryNodeLst: if categoryNode.attrib[key] == 'com.yxg.juhe': categoryNode.set(key, packageName) break serviceNodeLst = appNode.findall('service') if serviceNodeLst is None: return for serviceNode in serviceNodeLst: serviceName = serviceNode.get(name) if serviceName == 'cn.jpush.android.service.DaemonService': intentFilters = serviceNode.findall('intent-filter') for intentNode in intentFilters: categoryNodeLst = intentNode.findall('category') if categoryNodeLst is None: break for categoryNode in categoryNodeLst: if categoryNode.attrib[key] == 'com.yxg.juhe': categoryNode.set(key, packageName) break receiverNodeLst = appNode.findall('receiver') if receiverNodeLst is None: return for receiverNode in receiverNodeLst: receiverName = receiverNode.get(name) if receiverName == 'cn.jpush.android.service.PushReceiver': intentFilters = receiverNode.findall('intent-filter') for intentNode in intentFilters: actionNodeLst = intentNode.findall('action') if actionNodeLst is None: break bFindAction = False for actionNode in actionNodeLst: if actionNode.attrib[ key] == 'cn.jpush.android.intent.NOTIFICATION_RECEIVED_PROXY': bFindAction = True break if bFindAction: categoryNodeLst = intentNode.findall('category') if categoryNodeLst is None: break for categoryNode in categoryNodeLst: if categoryNode.attrib[key] == 'com.yxg.juhe': categoryNode.set(key, packageName) break elif receiverName == 'com.Castle.jpushjar.JPushReceiver': intentFilters = receiverNode.findall('intent-filter') for intentNode in intentFilters: categoryNodeLst = intentNode.findall('category') if categoryNodeLst is None: break for categoryNode in categoryNodeLst: if categoryNode.attrib[key] == 'com.yxg.juhe': categoryNode.set(key, packageName) break break #替换包名结束 #读取jpush_keys文件中的JPUSH_APPKEY log_utils.debug("now to set JPUSH_APPKEY") configFile = file_utils.getFullPath('games/' + game['appName'] + '/jpush_keys.properties') if not os.path.exists(configFile): log_utils.debug("jpush_keys file not exists." + configFile) return 1 f = open(configFile, 'r') for line in f.readlines(): item = line.strip().split('=') if item[0] == channel['id']: metaDataNode = SubElement(appNode, 'meta-data') metaDataNode.set(key, 'JPUSH_APPKEY') metaDataNode.set(keyVal, item[1]) break f.close() #JPUSH_APPKEY处理完毕 tree.write(manifest, 'UTF-8') log_utils.debug("post_script execute successfully") return 0
def main(game, isPublic, channelName): appName = game['appName'] baseApkPath = file_utils.getFullPath('games/' + appName + '/u8.apk') log_utils.info("the base apk file is : %s", baseApkPath) if not os.path.exists(baseApkPath): log_utils.error( 'the base apk file is not exists, must named with u8.apk') return channels = config_utils.getAllChannels(appName, isPublic) if channels is None or len(channels) == 0: log_utils.info("没有任何可以打包的渠道") return if channelName is not None: if channelName == '*': packChannels(game, channels, baseApkPath, isPublic) return selectChannel = getChannelByName(channelName, channels) if selectChannel is None: log_utils.info("指定的渠道名不存在") return ret = core.pack(game, selectChannel, baseApkPath, isPublic) if ret: log_utils.error("<< all done with error >>") else: log_utils.info("<< all nice done >>") return print(u"################################################################") print(u"\t%-15s%-20s%-20s\n" % (u"渠道名", u"渠道号", u"渠道")) for ch in channels: print(u"\t%-20s%-20s%-20s" % (ch['name'], ch['id'], ch['desc'])) print("") selected = [] while (True): sys.stdout.write(u"请选择需要打包的渠道(渠道名),全部输入*,多个用逗号分割:") sys.stdout.flush() target = raw_input() if target == '*': selected = channels else: for t in target.split(','): t = t.strip() matchChannels = [ c for c in channels if c['name'].lower() == t.lower() ] if len(matchChannels) > 0: selected.append(matchChannels[0]) if len(selected) == 0: print(u"\n无效的渠道名,请重新输入!!\n") else: break packChannels(game, selected, baseApkPath, isPublic)
def execute(channel, decompileDir, packageName): manifestFile = decompileDir + "/AndroidManifest.xml" manifestFile = file_utils.getFullPath(manifestFile) ET.register_namespace('android', androidNS) key = '{' + androidNS + '}name' schemeKey = '{' + androidNS + '}scheme' tree = ET.parse(manifestFile) root = tree.getroot() applicationNode = root.find('application') if applicationNode is None: return 1 # perNode = SubElement(root, 'uses-permission') # perNode.set(key, 'baidu.push.permission.WRITE_PUSHINFOPROVIDER.'+packageName) # perNode = SubElement(root, 'permission') # perNode.set(key, 'baidu.push.permission.WRITE_PUSHINFOPROVIDER.'+packageName) # perNode.set('{' + androidNS + '}protectionLevel', 'normal') activityNodeLst = applicationNode.findall('activity') if activityNodeLst is None: return 1 for activityNode in activityNodeLst: name = activityNode.get(key) if name == 'com.baidu.platformsdk.pay.channel.qqwallet.QQPayActivity': intentNodes = activityNode.findall('intent-filter') if intentNodes is not None and len(intentNodes) > 0: for intentNode in intentNodes: dataNodes = intentNode.findall('data') if dataNodes is not None and len(dataNodes) > 0: for dataNode in dataNodes: scheme = dataNode.get(schemeKey) if scheme.startswith('qwallet'): intentNode.remove(dataNode) break dataNode = SubElement(intentNode, 'data') dataNode.set(schemeKey, 'qwallet' + packageName) break elif name == 'com.baidu.platformsdk.pay.channel.ali.AliPayActivity': intentNodes = activityNode.findall('intent-filter') if intentNodes is not None and len(intentNodes) > 0: for intentNode in intentNodes: dataNodes = intentNode.findall('data') if dataNodes is not None and len(dataNodes) > 0: for dataNode in dataNodes: scheme = dataNode.get(schemeKey) if scheme.startswith('bdpsdk'): intentNode.remove(dataNode) break dataNode = SubElement(intentNode, 'data') dataNode.set(schemeKey, 'bdpsdk' + packageName) dataNode.set('{' + androidNS + '}host', "alipay.app") dataNode.set('{' + androidNS + '}pathPrefix', "/result") break activityNodeLst = applicationNode.findall('provider') for activityNode in activityNodeLst: name = activityNode.get(key) if name == 'com.tencent.mid.api.MidProvider': activityNode.set('{' + androidNS + '}authorities', packageName + ".TENCENT.MID.V3") elif name == 'com.baidu.platformsdk.BDGameFileProvider': activityNode.set('{' + androidNS + '}authorities', packageName + ".bdgame.fileprovider") # elif name == 'com.baidu.android.pushservice.PushInfoProvider': # activityNode.set('{'+androidNS+'}writePermission', "baidu.push.permission.WRITE_PUSHINFOPROVIDER."+packageName) # activityNode.set('{'+androidNS+'}authorities', packageName+".bdpush") tree.write(manifestFile, 'UTF-8') return 0
def modifyManifest(channel, decompileDir, packageName): manifestFile = decompileDir + "/AndroidManifest.xml" manifestFile = file_utils.getFullPath(manifestFile) ET.register_namespace('android', androidNS) key = '{' + androidNS + '}name' authorityKey = '{' + androidNS + '}authorities' metaValue = '{' + androidNS + '}value' tree = ET.parse(manifestFile) root = tree.getroot() applicationNode = root.find('application') if applicationNode is None: return providerNodeLst = applicationNode.findall('provider') if providerNodeLst is None: return 1 receiverNodeLst = applicationNode.findall('receiver') if receiverNodeLst is None: return 1 appid = "" cpid = "" if 'params' in channel: params = channel['params'] for param in params: if param['name'] == 'com.huawei.hms.client.appid': appid = param['value'] elif param['name'] == 'com.huawei.hms.client.cpid': cpid = param['value'] break metaNodeLst = applicationNode.findall('meta-data') if metaNodeLst is None: return 1 for metaNode in metaNodeLst: name = metaNode.get(key) if name == 'com.huawei.hms.client.appid': metaNode.set(metaValue, "appid=" + appid) if name == 'com.huawei.hms.client.cpid': metaNode.set(metaValue, "cpid=" + cpid) break activityName = '' for providerNode in providerNodeLst: name = providerNode.get(key) if name == 'com.huawei.hms.update.provider.UpdateProvider': providerNode.set(authorityKey, packageName + ".hms.update.provider") if name == 'com.huawei.updatesdk.fileprovider.UpdateSdkFileProvider': providerNode.set(authorityKey, packageName + ".updateSdk.fileProvider") for receiverNode in receiverNodeLst: intentNodes = receiverNode.findall('intent-filter') if intentNodes is not None and len(intentNodes) > 0: for intentNode in intentNodes: actionNodes = intentNode.findall('action') if actionNodes is not None and len(actionNodes) > 0: for actionNode in actionNodes: actionName = actionNode.get(key) if actionName == 'com.huawei.android.push.intent.REGISTRATION': receiverNode.set(key, 'com.u8.sdk.HuaweiPushRevicer') break tree.write(manifestFile, 'UTF-8') return activityName
def writeDeveloperProperties(game, channel, targetFilePath): targetFilePath = file_utils.getFullPath(targetFilePath) proStr = "" if channel['params'] != None and len(channel['params']) > 0: for param in channel['params']: if param['bWriteInClient'] == '1': proStr = proStr + param['name'] + "=" + param['value'] + "\n" if "sdkLogicVersionCode" in channel: proStr = proStr + "YX_SDK_VERSION_CODE=" + channel["sdkLogicVersionCode"] + "\n" proStr = proStr + "YX_Channel=" + channel['id'] + "\n" proStr = proStr + "YX_APPID=" + game["appID"] + "\n" proStr = proStr + "YX_APPKEY=" + game["appKey"] + "\n" showSplash = "false" if "splash" in channel and int(channel["splash"]) > 0 : showSplash = "true" proStr = proStr + "YX_SDK_SHOW_SPLASH=" + showSplash + "\n" useU8Auth = None authUrl = None if "use_u8_auth" in game: useU8Auth = game["use_u8_auth"] if "u8_auth_url" in game: authUrl = game["u8_auth_url"] #append yxme local config local_config = getLocalConfig() if useU8Auth is None or authUrl is None: if "use_u8_auth" not in local_config or "u8_auth_url" not in local_config: log_utils.error("the use_u8_auth or u8_auth_url is not exists in local.properties. don't use u8 auth.") return if local_config['use_u8_auth'] == "1": useU8Auth = "1" authUrl = local_config['u8_auth_url'] if useU8Auth == "1": proStr = proStr + "YX_AUTH_URL=" + authUrl + "\n" #write third plugin info: plugins = channel.get('third-plugins') if plugins != None and len(plugins) > 0: for plugin in plugins: if 'params' in plugin and plugin['params'] != None and len(plugin['params']) > 0: for param in plugin['params']: if param['bWriteInClient'] == '1': proStr = proStr + param['name'] + "=" + param['value'] + "\n" log_utils.debug("the develop info is %s", proStr) targetFile = open(targetFilePath, 'wb') proStr = proStr.encode('UTF-8') targetFile.write(proStr) targetFile.close()