Пример #1
0
def compileWXEntryActivity(channel, decompileDir, packageName):

    sdkDir = decompileDir + '/../sdk/' + channel['sdk']
    if not os.path.exists(sdkDir):
        file_utils.printF("The sdk temp folder is not exists. path:" + sdkDir)
        return 1

    extraFilesPath = sdkDir + '/extraFiles'
    relatedJar = os.path.join(extraFilesPath, 'YSDK.jar')
    WXPayEntryActivity = os.path.join(extraFilesPath, 'WXEntryActivity.java')
    file_utils.modifyFileContent(WXPayEntryActivity,
                                 'com.example.wegame.wxapi',
                                 packageName + ".wxapi")

    splitdot = ';'
    if platform.system() == 'Darwin':
        splitdot = ':'

    cmd = '"%sjavac" -source 1.7 -target 1.7 "%s" -classpath "%s"%s"%s"' % (
        file_utils.getJavaBinDir(), WXPayEntryActivity, relatedJar, splitdot,
        file_utils.getFullToolPath('android.jar'))

    ret = file_utils.execFormatCmd(cmd)
    if ret:
        return 1

    packageDir = packageName.replace('.', '/')
    srcDir = sdkDir + '/tempDex'
    classDir = srcDir + '/' + packageDir + '/wxapi'

    if not os.path.exists(classDir):
        os.makedirs(classDir)

    sourceClassFilePath = os.path.join(extraFilesPath, 'WXEntryActivity.class')
    targetClassFilePath = classDir + '/WXEntryActivity.class'

    file_utils.copy_file(sourceClassFilePath, targetClassFilePath)

    targetDexPath = os.path.join(sdkDir, 'WXEntryActivity.dex')

    dxTool = file_utils.getFullToolPath("/lib/dx.jar")

    cmd = file_utils.getJavaCMD(
    ) + ' -jar -Xmx512m -Xms512m "%s" --dex --output="%s" "%s"' % (
        dxTool, targetDexPath, srcDir)

    ret = file_utils.execFormatCmd(cmd)

    if ret:
        return 1

    ret = apk_utils.dex2smali(targetDexPath, decompileDir + '/smali',
                              "baksmali.jar")

    if ret:
        return 1
Пример #2
0
def compileWXEntryActivity(channel, decompileDir, packageName):

	sdkDir = decompileDir + '/../sdk/' + channel['sdk']
	if not os.path.exists(sdkDir):
		file_utils.printF("The sdk temp folder is not exists. path:"+sdkDir)
		return 1

	extraFilesPath = sdkDir + '/extraFiles'
	relatedJar = os.path.join(extraFilesPath, 'MSDK_Android.jar')
	WXPayEntryActivity = os.path.join(extraFilesPath, 'WXEntryActivity.java')
	file_utils.modifyFileContent(WXPayEntryActivity, 'com.example.wegame.wxapi', packageName+".wxapi")

	splitdot = ';'
	if platform.system() == 'Darwin':
		splitdot = ':'

	cmd = '"%sjavac" -source 1.7 -target 1.7 "%s" -classpath "%s"%s"%s"' % (file_utils.getJavaBinDir(), WXPayEntryActivity, relatedJar, splitdot, file_utils.getFullToolPath('android.jar'))


	ret = file_utils.execFormatCmd(cmd)
	if ret:
		return 1

	packageDir = packageName.replace('.', '/')
	srcDir = sdkDir + '/tempDex'
	classDir = srcDir + '/' + packageDir + '/wxapi'

	if not os.path.exists(classDir):
		os.makedirs(classDir)

	sourceClassFilePath = os.path.join(extraFilesPath, 'WXEntryActivity.class')
	targetClassFilePath = classDir + '/WXEntryActivity.class'

	file_utils.copy_file(sourceClassFilePath, targetClassFilePath)

	targetDexPath = os.path.join(sdkDir, 'WXEntryActivity.dex')

	dxTool = file_utils.getFullToolPath("/lib/dx.jar")

	cmd = file_utils.getJavaCMD() + ' -jar -Xmx512m -Xms512m "%s" --dex --output="%s" "%s"' % (dxTool, targetDexPath, srcDir)

	ret = file_utils.execFormatCmd(cmd)

	if ret:
		return 1

	ret = apk_utils.dex2smali(targetDexPath, decompileDir+'/smali', "baksmali.jar")

	if ret:
		return 1
Пример #3
0
def doPack(package_info):
    channelConfig, logger, logfilepath = getChannelConfig(package_info)
    workDirCls = dir_utils.WorkDirCls(
        rootDir, channelConfig['game_info']['game_id'],
        channelConfig['game_info']['game_bundle_id'],
        channelConfig['game_info']['channel_flag'],
        channelConfig['game_info']['channel_version'])
    logger.info(channelConfig)
    workDir = workDirCls.workRootDir
    if not os.path.exists(workDir):
        os.makedirs(workDir)
    # 反编译apk
    logger.info('clean workdir')
    file_utils.del_file_folder(workDir)
    logger.info("copy sourceapk to workdir")
    apkSource = os.path.join(workDir, 'temp.apk')
    file_utils.copy_file(channelConfig['game_info']['source_apk'], apkSource)
    logger.info("decompile apk")
    ret, cmd, result = apk_utils.decompileApk(apkSource,
                                              workDirCls.workDecompileDir,
                                              apktoolPath)  ###反编译
    logger.info(cmd)
    logger.info(str(ret) + "======" + result)
    #删除原SDK相关内容
    logger.info("delete default sdk info")
    ret, result = apk_utils.removeDefaultSDKInfo(workDirCls.workDecompileDir,
                                                 defaultSDKInfoConfigFile)
    logger.info(str(ret) + "======" + result)
    # 对资源进行特殊处理(删除layout-v26/abc_screen_toolbar.xml中的android:keyboardNavigationCluster、删除drawable-v24/ic_launcher_foreground.xml中的android:fillType)
    logger.info("handle special resource")
    ret, result = apk_utils.handleSpecialResource(workDirCls.workDecompileDir)
    logger.info(str(ret) + "======" + result)
    #拷贝sdk插件到工作目录
    logger.info("copy sdk plugin to workdir")

    #拷贝渠道SDK到工作目录
    channelSdk = os.path.join(channelSdkPath,
                              channelConfig['game_info']['channel_flag'],
                              channelConfig['game_info']['channel_version'])
    file_utils.copy_files(channelSdk, workDirCls.workSDKDir)

    #拷贝媒体SDK到工作目录
    if channelConfig['ad_sdk'].has_key(
            'media_flag') and channelConfig['ad_sdk']['media_flag'] > 0:
        madiaSdk = os.path.join(mediaSdkPath,
                                channelConfig['ad_sdk']['media_flag'],
                                channelConfig['game_info']['media_version'])
        file_utils.copy_files(madiaSdk, workDirCls.workSDKDir)

    #copy头条aar
    #logger.info("if has toutiao, copy toutiao plugin to workdir")
    #if channelConfig['ad_sdk'].has_key('tt_id') and len(channelConfig['ad_sdk']['tt_id']) > 0:
    #    toutiaoPluginDir = os.path.join(workDirCls.channelsDir, 'toutiao')
    #    file_utils.copy_files(toutiaoPluginDir, workDirCls.workSDKDir)
    #copy广点通aar
    #logger.info("if has gdt, copy gdt plugin to workdir")
    #if channelConfig['ad_sdk'].has_key('gdt_id') and channelConfig['ad_sdk'].has_key('gdt_secret_key') and len(channelConfig['ad_sdk']['gdt_id']) > 0 and len(channelConfig['ad_sdk']['gdt_secret_key']) > 0:
    #    gdtPluginDir = os.path.join(workDirCls.channelsDir, 'gdt')
    #    file_utils.copy_files(gdtPluginDir, workDirCls.workSDKDir)
    #copy快手aar
    #logger.info("if has kuaishou, copy kuaishou plugin to workdir")
    #if channelConfig['ad_sdk'].has_key('ks_id') and len(channelConfig['ad_sdk']['ks_id']) > 0 and channelConfig['ad_sdk'].has_key('ks_name') and len(channelConfig['ad_sdk']['ks_name']) > 0:
    #    kuaishouPluginDir = os.path.join(workDirCls.channelsDir, 'kuaishou')
    #    file_utils.copy_files(kuaishouPluginDir, workDirCls.workSDKDir)
    #copy独代aar
    #logger.info("if has dudai, copy dudai plugin to workdir")
    #if channelConfig['game_info'].has_key('is_dudai') and channelConfig['game_info']['is_dudai'] == 'true':
    #    dudaiPluginDir = os.path.join(workDirCls.channelsDir, 'dudai')
    #    file_utils.copy_files(dudaiPluginDir, workDirCls.workSDKDir)

    #aar模式需进行解压和资源合并
    logger.info("in workdir, unzip aar and zip, then merge")
    if apk_utils.isAarMode(workDirCls.workSDKDir):
        apk_utils.unzipAarFiles(workDirCls.workSDKDir)
        apk_utils.mergeAarFiles(workDirCls.workSDKDir)
    # copy libs(.jar除外)
    logger.info("copy sdk libs(except jar) to decompile dir")
    ret, result = apk_utils.copyLibs(
        os.path.join(workDirCls.workSDKDir, 'libs'),
        os.path.join(workDirCls.workDecompileDir, 'lib'))
    logger.info(str(ret) + "======" + result)
    # 处理lib文件夹,仅保留一个,防止不一致导致部分机型崩溃
    logger.info("handle lib dir(cpu type)")
    ret, result = apk_utils.deleteOtherLibDir(
        os.path.join(workDirCls.workDecompileDir, 'lib'),
        channelConfig['game_info']['partner_id'])
    logger.info(str(ret) + "======" + result)
    #copy 渠道res
    logger.info("copy sdk res to decompile res dir")
    ret, result = apk_utils.copyResToApk(
        os.path.join(workDirCls.workSDKDir, 'res'),
        os.path.join(workDirCls.workDecompileDir, 'res'))
    logger.info(str(ret) + "======" + result)
    #copy 渠道assets
    logger.info("copy sdk assets to decompile assets dir")
    ret, result = apk_utils.copyResToApk(
        os.path.join(workDirCls.workSDKDir, 'assets'),
        os.path.join(workDirCls.workDecompileDir, 'assets'))
    logger.info(str(ret) + "======" + result)
    #copy 其他资源
    logger.info("copy sdk other res to decompile dir")
    ret, result = apk_utils.copyOtherResToApk(workDirCls.workSDKDir,
                                              workDirCls.workDecompileDir)
    logger.info(str(ret) + "======" + result)
    #配置写入 独代配置暂时写死,没有更新
    logger.info("update conf file()")
    apk_utils.updateConfFile(channelConfig, workDirCls.workDecompileDir)
    #修改apktool.yml 版本号 targetSdkVersion
    logger.info(
        "update apktool.yml, include targetSdkVersion, version_code etc.")
    apk_utils.updateApktoolYmlFile(channelConfig, workDirCls.workDecompileDir)
    #修改包名,合并manifest 2019-08-01新增:应用宝渠道,在主activity里面添加url scheme 格式:scheme://host/path(path为分包名)
    logger.info("merge manifest")
    ret, result, oldPackageName = apk_utils.mergeManifest(
        os.path.join(workDirCls.workDecompileDir, 'AndroidManifest.xml'),
        os.path.join(workDirCls.workSDKDir, 'sdkmanifest.xml'), channelConfig)
    logger.info(str(ret) + "======" + result)
    #替换AndroidManifest里面的占位符
    logger.info("replace placeholder in manifest")
    apk_utils.replaceSpecialString(
        os.path.join(workDirCls.workDecompileDir, 'AndroidManifest.xml'),
        channelConfig, oldPackageName)
    #修改应用名称
    logger.info("update app display name")
    ret, result = apk_utils.updateAppDisplayName(
        workDirCls.workDecompileDir, channelConfig['game_info']['game_name'])
    logger.info(str(ret) + "======" + result)

    apk_utils.handle_drawable_v4(workDirCls.workDecompileDir)
    #修改icon
    if channelConfig['game_info'].has_key(
            'icon_file') and channelConfig['game_info'].has_key('icon_name'):
        logger.info("handle app icon")
        ret, result = apk_utils.handlePackageIcon(
            channelConfig['game_info']['icon_file'],
            workDirCls.workDecompileDir,
            channelConfig['game_info']['icon_name'])
        logger.info(str(ret) + "======" + result)

    #替换游戏素材(闪屏、loading、登录背景图)
    logger.info("replace app resource")
    if channelConfig['game_info'].has_key('game_resources') and len(
            channelConfig['game_info']['game_resources']
    ) > 0 and channelConfig['game_info'].has_key('resource_path') and len(
            channelConfig['game_info']['resource_path']) > 0:
        oldGameResourcePath = os.path.join(
            workDirCls.workDecompileDir,
            channelConfig['game_info']['resource_path'].replace('/', os.sep))
        for newGameResourcePath in channelConfig['game_info'][
                'game_resources']:
            file_utils.copy_file(
                newGameResourcePath,
                os.path.join(oldGameResourcePath,
                             os.path.basename(newGameResourcePath)))
    #重新生成R文件,编译,然后生成jar包搭配渠道的libs目录下
    logger.info("generate R file")
    ret, cmd, result = apk_utils.generateNewRFile(
        oldPackageName, channelConfig['game_info']['game_bundle_id'],
        workDirCls.workDecompileDir, toolsDir, channelConfig)
    logger.info(cmd)
    logger.info(str(ret) + "======" + result)
    #jar to dex
    logger.info("convert jar to dex")
    if not os.path.exists(
            os.path.join(workDirCls.currentChannelDir, "classes.dex")):
        ret, cmd, result = apk_utils.jar2dex(workDirCls.workSDKDir,
                                             workDirCls.workSDKDir,
                                             channelConfig)
        logger.info(cmd)
        logger.info(str(ret) + "======" + result)
    #dex to smali
    logger.info("convert dex to smali")
    sdkDexFile = os.path.join(workDirCls.workSDKDir, "classes.dex")
    ret, cmd, result = apk_utils.dex2smali(sdkDexFile,
                                           workDirCls.workDecompileSmaliDir,
                                           baksmaliJarPath)
    logger.info(cmd)
    logger.info(str(ret) + "======" + result)
    #应用宝/小米 多Dex处理
    if channelConfig['game_info']['partner_id'] == '3' or channelConfig[
            'game_info']['partner_id'] == '9':
        logger.info("handle multi dex")
        apk_utils.splitDex(workDirCls.workDecompileDir)

    # 处理需要特殊处理的smali文件
    apk_utils.handleSmali(channelConfig, workDirCls.workDecompileDir)

    #重新编译
    logger.info("compile new apk")
    targetApkFile = os.path.join(workDirCls.workTempDir, "output.apk")
    ret, cmd, result = apk_utils.recompileApk(workDirCls.workTempDir,
                                              workDirCls.workDecompileDir,
                                              targetApkFile, apktoolPath)
    logger.info(cmd)
    logger.info(str(ret) + "======" + result)
    #签名
    logger.info("sign apk")
    signInfo = {
        "keystore": os.path.join(commonConfigDir, '7yol_default.keystore'),
        "password": "******",
        "aliaskey": "7yol_default",
        "aliaspwd": "Aa314159"
    }
    ret, cmd, result = apk_utils.signApk(targetApkFile, signInfo)
    logger.info(cmd)
    logger.info(str(ret) + "======" + result)
    #对齐
    logger.info("align apk")
    targetZApk = os.path.join(workDirCls.workTempDir, "outputZ.apk")
    ret, cmd, result = apk_utils.alignApk(zipalignToolPath, targetApkFile,
                                          targetZApk)
    logger.info(cmd)
    logger.info(str(ret) + "======" + result)
    #copy到target目录
    logger.info("copy apk to target dir")
    targetApkFileName = os.path.splitext(os.path.basename(logfilepath))[0]
    targetApkFilePath = os.path.join(
        channelConfig['game_info']['target_apk'],
        channelConfig['game_info']['game_id'],
        channelConfig['game_info']['channel_flag'],
        channelConfig['game_info']['game_bundle_id'],
        targetApkFileName + '.apk')
    file_utils.copy_file(targetZApk, targetApkFilePath)
    if os.path.exists(targetApkFilePath):
        logger.info("pack success!!!===target apk is: %s" % targetApkFilePath)
        print '{"status":1, "apkPath":"%s", "logPath": "%s"}' % (
            targetApkFilePath, logfilepath)
    else:
        logger.info("pack fail")
        print '{"status":0, "logPath": "%s"}' % (logfilepath)
Пример #4
0
def execute(channel, decompileDir, packageName):

	sdkDir = decompileDir + '/../sdk/' + channel['sdk']
	if not os.path.exists(sdkDir):
		file_utils.printF("The sdk temp folder is not exists. path:"+sdkDir)
		return 1

	extraFilesPath = sdkDir + '/extraFiles'
	relatedJar = os.path.join(extraFilesPath, '360SDK.jar')
	WXPayEntryActivity = os.path.join(extraFilesPath, 'WXEntryActivity.java')
	file_utils.modifyFileContent(WXPayEntryActivity, 'com.u8.sdk.qh360.wxapi', packageName+".wxapi")


	splitdot = ';'
	if platform.system() == 'Darwin':
		splitdot = ':'

	cmd = '"%sjavac" -source 1.7 -target 1.7 "%s" -classpath "%s"%s"%s"' % (file_utils.getJavaBinDir(), WXPayEntryActivity, relatedJar, splitdot, file_utils.getFullToolPath('android.jar'))

	ret = file_utils.execFormatCmd(cmd)
	if ret:
		return 1

	packageDir = packageName.replace('.', '/')
	srcDir = sdkDir + '/tempDex'
	classDir = srcDir + '/' + packageDir + '/wxapi'

	if not os.path.exists(classDir):
		os.makedirs(classDir)

	sourceClassFilePath = os.path.join(extraFilesPath, 'WXEntryActivity.class')
	targetClassFilePath = classDir + '/WXEntryActivity.class'

	file_utils.copy_file(sourceClassFilePath, targetClassFilePath)

	targetDexPath = os.path.join(sdkDir, 'WXEntryActivity.dex')

	dxTool = file_utils.getFullToolPath("/lib/dx.jar")

	cmd = file_utils.getJavaCMD() + ' -jar -Xmx512m -Xms512m "%s" --dex --output="%s" "%s"' % (dxTool, targetDexPath, srcDir)



	ret = file_utils.execFormatCmd(cmd)

	if ret:
		return 1

	ret = apk_utils.dex2smali(targetDexPath, decompileDir+'/smali', "baksmali.jar")

	if ret:
		return 1

	manifest = decompileDir + '/AndroidManifest.xml'
	ET.register_namespace('android', androidNS)
	name = '{' + androidNS + '}name'
	hostKey = '{'+androidNS+'}host'
	configChanges = '{' + androidNS + '}configChanges'
	exported = '{' + androidNS + '}exported'
	screenOrientation = '{' + androidNS + '}screenOrientation'
	tree = ET.parse(manifest)
	root = tree.getroot()

	appNode = root.find('application')
	if appNode is None:
		return 1

	activityNode = SubElement(appNode, 'activity')
	activityNode.set(name, packageName + '.wxapi.WXEntryActivity')
	activityNode.set(configChanges, 'keyboardHidden|orientation')
	activityNode.set(exported, 'true')
	activityNode.set(screenOrientation, 'portrait')


	#append host
	activityNodeLst = appNode.findall('activity')
	if activityNodeLst is not None and len(activityNodeLst) > 0:
		for activityNode in activityNodeLst:
			activityName = activityNode.get(name)
			if activityName == 'com.qihoo.gamecenter.sdk.activity.ContainerActivity':
				intentNodeLst = activityNode.findall('intent-filter')
				find = False
				if intentNodeLst is not None:
					for itNode in intentNodeLst:
                                                dataNodeList = itNode.findall('data')
                                                for dataNode in dataNodeList :
                                                        if dataNode.get(hostKey) == 'com.qihoo.gamecenter.sdk.demosp':
                                                                dataNode.set(hostKey, packageName)
                                                                find = True
                                                                break
                                                if find:
                                                        break
                                                        


	tree.write(manifest, 'UTF-8')

	return 0
Пример #5
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

    #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")):
        apk_utils.jar2dex(sdkSourceDir, sdkDestDir)

    sdkDexFile = sdkDestDir + "/classes.dex"
    ret = apk_utils.dex2smali(sdkDexFile, smaliDir, "baksmali.jar")
    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 main sdk resources.
    ret = apk_utils.copyResource(game, channel, newPackageName, sdkDestDir,
                                 decompileDir, channel['operations'],
                                 channelName)
    if ret:
        return 1

    #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)
    apk_utils.appendChannelIconMark(game, channel, decompileDir)

    #generate config files for apk to run.
    apk_utils.writeDevelopInfo(appID, appKey, channel, decompileDir)
    apk_utils.writePluginInfo(channel, decompileDir)
    apk_utils.writeManifestMetaInfo(channel, 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)

    #generate new R.java
    ret = apk_utils.generateNewRFile(newPackageName, decompileDir)
    if ret:
        return 1

    targetApk = workDir + "/output.apk"
    ret = apk_utils.recompileApk(decompileDir, targetApk)
    if ret:
        return 1

    apk_utils.copyRootResFiles(targetApk, decompileDir)

    ret = apk_utils.signApk(appName, channelId, targetApk)
    if ret:
        return 1

    #destApkName = channelName + '.apk'
    channelNameStr = channelName.replace(' ', '')

    if isPublic:
        destApkName = channelNameStr + '-' + time.strftime('%Y%m%d%H') + '.apk'
    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
Пример #6
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

    # 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"):
        apk_utils.jar2dex(sdkSourceDir, sdkDestDir)

    sdkDexFile = sdkDestDir + "/classes.dex"
    ret = apk_utils.dex2smali(sdkDexFile, smaliDir, "baksmali.jar")
    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 main sdk resources.
    ret = apk_utils.copyResource(
        game, channel, newPackageName, sdkDestDir, decompileDir, channel["operations"], channelName
    )
    if ret:
        return 1

    # 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)
    apk_utils.appendChannelIconMark(game, channel, decompileDir)

    # generate config files for apk to run.
    apk_utils.writeDevelopInfo(appID, appKey, channel, decompileDir)
    apk_utils.writePluginInfo(channel, decompileDir)
    apk_utils.writeManifestMetaInfo(channel, 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)

    # generate new R.java
    ret = apk_utils.generateNewRFile(newPackageName, decompileDir)
    if ret:
        return 1

    targetApk = workDir + "/output.apk"
    ret = apk_utils.recompileApk(decompileDir, targetApk)
    if ret:
        return 1

    apk_utils.copyRootResFiles(targetApk, decompileDir)

    ret = apk_utils.signApk(appName, channelId, targetApk)
    if ret:
        return 1

    # destApkName = channelName + '.apk'
    channelNameStr = channelName.replace(" ", "")

    if isPublic:
        destApkName = channelNameStr + "-" + time.strftime("%Y%m%d%H") + ".apk"
    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
Пример #7
0
def execute(channel, decompileDir, packageName):

    sdkDir = decompileDir + '/../sdk/' + channel['sdk']
    if not os.path.exists(sdkDir):
        file_utils.printF("The sdk temp folder is not exists. path:" + sdkDir)
        return 1

    extraFilesPath = sdkDir + '/extraFiles'
    relatedJar = os.path.join(extraFilesPath, '360SDK.jar')
    WXPayEntryActivity = os.path.join(extraFilesPath, 'WXEntryActivity.java')
    file_utils.modifyFileContent(WXPayEntryActivity, 'com.u8.sdk.qh360.wxapi',
                                 packageName + ".wxapi")

    splitdot = ';'
    if platform.system() == 'Darwin':
        splitdot = ':'

    cmd = '"%sjavac" -source 1.7 -target 1.7 "%s" -classpath "%s"%s"%s"' % (
        file_utils.getJavaBinDir(), WXPayEntryActivity, relatedJar, splitdot,
        file_utils.getFullToolPath('android.jar'))

    ret = file_utils.execFormatCmd(cmd)
    if ret:
        return 1

    packageDir = packageName.replace('.', '/')
    srcDir = sdkDir + '/tempDex'
    classDir = srcDir + '/' + packageDir + '/wxapi'

    if not os.path.exists(classDir):
        os.makedirs(classDir)

    sourceClassFilePath = os.path.join(extraFilesPath, 'WXEntryActivity.class')
    targetClassFilePath = classDir + '/WXEntryActivity.class'

    file_utils.copy_file(sourceClassFilePath, targetClassFilePath)

    targetDexPath = os.path.join(sdkDir, 'WXEntryActivity.dex')

    dxTool = file_utils.getFullToolPath("/lib/dx.jar")

    cmd = file_utils.getJavaCMD(
    ) + ' -jar -Xmx512m -Xms512m "%s" --dex --output="%s" "%s"' % (
        dxTool, targetDexPath, srcDir)

    ret = file_utils.execFormatCmd(cmd)

    if ret:
        return 1

    ret = apk_utils.dex2smali(targetDexPath, decompileDir + '/smali')

    if ret:
        return 1

    manifest = decompileDir + '/AndroidManifest.xml'
    ET.register_namespace('android', androidNS)
    name = '{' + androidNS + '}name'
    hostKey = '{' + androidNS + '}host'
    configChanges = '{' + androidNS + '}configChanges'
    exported = '{' + androidNS + '}exported'
    screenOrientation = '{' + androidNS + '}screenOrientation'
    authoritiesKey = '{' + androidNS + '}authorities'
    tree = ET.parse(manifest)
    root = tree.getroot()

    appNode = root.find('application')
    if appNode is None:
        return 1

    activityNode = SubElement(appNode, 'activity')
    activityNode.set(name, packageName + '.wxapi.WXEntryActivity')
    activityNode.set(configChanges, 'keyboardHidden|orientation')
    activityNode.set(exported, 'true')
    activityNode.set(screenOrientation, 'portrait')

    # appkey = ""

    # if 'params' in channel:
    # 	params = channel['params']
    # 	for param in params:
    # 		if param['name'] == 'QHOPENSDK_APPKEY':
    # 			appkey = param['value']
    # 			break

    #append host
    activityNodeLst = appNode.findall('activity')
    if activityNodeLst is not None and len(activityNodeLst) > 0:
        for activityNode in activityNodeLst:
            activityName = activityNode.get(name)
            if activityName == 'com.qihoo.gamecenter.sdk.activity.ContainerActivity':
                intentNodeLst = activityNode.findall('intent-filter')
                if intentNodeLst is not None:
                    for itNode in intentNodeLst:
                        dataNode = SubElement(itNode, 'data')
                        dataNode.set(hostKey, packageName)

            # elif activityName == 'com.qihoo.gamecenter.sdk.activity.QhDeepLinkActivity':
            # 	intentNodeLst = activityNode.findall('intent-filter')
            # 	if intentNodeLst is not None:
            # 		for itNode in intentNodeLst:
            # 			dataNodeLst = itNode.findall('data')
            # 			if dataNodeLst is not None:
            # 				for dNode in dataNodeLst:
            # 					dNode.set(hostKey, appkey)
            # 					break

    providerNodeLst = appNode.findall("provider")
    if providerNodeLst is not None and len(providerNodeLst) > 0:
        for pNode in providerNodeLst:
            pName = pNode.get(name)
            if pName == 'com.qihoo.pushsdk.keepalive.account.SyncProvider':
                pNode.set(authoritiesKey,
                          packageName + ".cx.accounts.syncprovider")

    tree.write(manifest, 'UTF-8')

    #modify res/xml/qihoo_game_sdk_sync_adapter.xml
    resXml = decompileDir + '/res/xml/qihoo_game_sdk_sync_adapter.xml'
    if os.path.exists(resXml):
        file_utils.modifyFileContent(
            resXml, 'com.qihoo.gamecenter.sdk.demosp.cx.accounts.syncprovider',
            packageName + ".cx.accounts.syncprovider")

    return 0
Пример #8
0
def generateWXEntryActivity(channel, pluginInfo, decompileDir, packageName):

    sdkDir = decompileDir + '/../plugins/' + pluginInfo['name']
    if not os.path.exists(sdkDir):
        file_utils.printF("The plugin temp folder is not exists. path:" +
                          sdkDir)
        return 1

    extraFilesPath = sdkDir + '/extraFiles'
    relatedJar = os.path.join(extraFilesPath, 'ShareSDK-Wechat-Core.jar')
    WXPayEntryActivity = os.path.join(extraFilesPath, 'WXEntryActivity.java')
    file_utils.modifyFileContent(WXPayEntryActivity,
                                 'cn.sharesdk.socialization.sample.wxapi',
                                 packageName + ".wxapi")

    splitdot = ';'
    if platform.system() == 'Darwin':
        splitdot = ':'

    cmd = '"%sjavac" -source 1.7 -target 1.7 "%s" -classpath "%s"%s"%s"' % (
        file_utils.getJavaBinDir(), WXPayEntryActivity, relatedJar, splitdot,
        file_utils.getFullToolPath('android.jar'))

    ret = file_utils.execFormatCmd(cmd)
    if ret:
        return 1

    packageDir = packageName.replace('.', '/')
    srcDir = sdkDir + '/tempDex'
    classDir = srcDir + '/' + packageDir + '/wxapi'

    if not os.path.exists(classDir):
        os.makedirs(classDir)

    sourceClassFilePath = os.path.join(extraFilesPath, 'WXEntryActivity.class')
    targetClassFilePath = classDir + '/WXEntryActivity.class'

    file_utils.copy_file(sourceClassFilePath, targetClassFilePath)

    targetDexPath = os.path.join(sdkDir, 'WXEntryActivity.dex')

    dxTool = file_utils.getFullToolPath("/lib/dx.jar")

    cmd = file_utils.getJavaCMD(
    ) + ' -jar -Xmx512m -Xms512m "%s" --dex --output="%s" "%s"' % (
        dxTool, targetDexPath, srcDir)

    ret = file_utils.execFormatCmd(cmd)

    if ret:
        return 1

    ret = apk_utils.dex2smali(targetDexPath, decompileDir + '/smali')

    if ret:
        return 1

    manifest = decompileDir + '/AndroidManifest.xml'
    ET.register_namespace('android', androidNS)
    name = '{' + androidNS + '}name'
    theme = '{' + androidNS + '}theme'
    configChanges = '{' + androidNS + '}configChanges'
    exported = '{' + androidNS + '}exported'
    screenOrientation = '{' + androidNS + '}screenOrientation'
    tree = ET.parse(manifest)
    root = tree.getroot()

    appNode = root.find('application')
    if appNode is None:
        return 1

    activityNode = SubElement(appNode, 'activity')
    activityNode.set(name, packageName + '.wxapi.WXEntryActivity')
    activityNode.set(theme, '@android:style/Theme.Translucent.NoTitleBar')
    activityNode.set(configChanges, 'keyboardHidden|orientation')
    activityNode.set(exported, 'true')
    activityNode.set(screenOrientation, 'portrait')

    tree.write(manifest, 'UTF-8')

    return 0