예제 #1
0
def processMedia(channel, checkBox_voice_isChecked, comboBox_voice_currentText):
    print"----------begin processMedia--------------"
    if not checkBox_voice_isChecked:
        return
    print"----------select path--------------"
    mediaPath = file_operate.getMediaPath()
    print "path= "+comboBox_voice_currentText
    thirdMediaName = unicode(comboBox_voice_currentText)
    thirdMediaPath = mediaPath + '/' + thirdMediaName
    print "thirdMediaPath= "+thirdMediaPath
    file_operate.copyFiles(thirdMediaPath + "/jar", constant.tmpPath + '/' + channel + "/jar")
    print"----------select windows--------------"
    if platform.system() == 'Windows':
        dxTool = file_operate.getToolPath('dx.bat')
    else:
        dxTool = file_operate.getToolPath('dx')
#     cmd = '"%s" --dex --output="%s" "%s"' % (dxTool, file_operate.getFullPath(constant.tmpPath+'/'+channel+"/classes.dex"), file_operate.getFullPath(constant.tmpPath+'/'+channel+"/jar")) #合并jar
    cmd = '"%s" --multi-dex --dex --output="%s" "%s"' % (dxTool, file_operate.getFullPath(constant.tmpPath + '/' + channel), file_operate.getFullPath(constant.tmpPath + '/' + channel + "/jar"))  # 合并jar
    ret = file_operate.execFormatCmd(cmd)
    if ret:
        error_operate.error(104)
        return
    print"-----------copy libs-------------"
    # copy libs
    targetDir = file_operate.getFullPath(constant.tmpPath + '/' + channel)
    oldApkDir = targetDir + "/oldApkDir"
    if os.path.exists(thirdMediaPath + "/ForLibs"):
        if os.path.exists(oldApkDir + "/lib/armeabi") and os.path.exists(thirdMediaPath + "/ForLibs/armeabi"):
            operate.copyResToApk(thirdMediaPath + "/ForLibs/armeabi", oldApkDir + "/lib/armeabi")
        if os.path.exists(oldApkDir + "/lib/armeabi-v7a") and os.path.exists(thirdMediaPath + "/ForLibs/armeabi-v7a"):
            operate.copyResToApk(thirdMediaPath + "/ForLibs/armeabi-v7a", oldApkDir + "/lib/armeabi-v7a")
        if os.path.exists(oldApkDir + "/lib/x86") and os.path.exists(thirdMediaPath + "/ForLibs/x86"):
            operate.copyResToApk(thirdMediaPath + "/ForLibs/x86", oldApkDir + "/lib/x86")
    print"-----------copy res-------------"
     # copy res
    if os.path.exists(thirdMediaPath + "/ForRes"):
        operate.copyResToApk(thirdMediaPath + "/ForRes", oldApkDir + "/res")
        
    print"-----------copy pushScript-------------"    
    # copy pushScript
    file_operate.copyFile(thirdMediaPath + "/pushScript.pyc", targetDir + "/pushScript.pyc")
    print"----------- ForManifest-------------" 
    # 合并ForManifest.xml
    manifestFile = file_operate.getFullPath(constant.tmpPath + '/' + channel + "/ForManifest.xml")
    ET.register_namespace('android', constant.androidNS)
    targetTree = ET.parse(manifestFile)
    targetRoot = targetTree.getroot()
    print"-----------write-------------" 
    haveChanged = modifyManifest.doModifyForManifest(manifestFile, thirdMediaPath + "/ForManifest.xml", targetRoot)
    if haveChanged:
        targetTree.write(manifestFile, 'UTF-8')
    print"-----------comeplete-------------"    
예제 #2
0
def processStatistics(channel, checkBox_isChecked, comboBox_4_currentText):
    if not checkBox_isChecked:
        return
    
    statisticsPath = file_operate.getStatisticsPath()
    thirdStatisticsName = comboBox_4_currentText
    thirdStatisticsPath = statisticsPath + '/' + str(thirdStatisticsName)
    print "..........", thirdStatisticsPath
    file_operate.copyFiles(thirdStatisticsPath + "/jar", constant.tmpPath + '/' + channel + "/jar")
    if platform.system() == 'Windows':
        dxTool = file_operate.getToolPath('dx.bat')
    else:
        dxTool = file_operate.getToolPath('dx')
#     cmd = '"%s" --dex --output="%s" "%s"' % (dxTool, file_operate.getFullPath(constant.tmpPath+'/'+channel+"/classes.dex"), file_operate.getFullPath(constant.tmpPath+'/'+channel+"/jar")) #合并jar
    cmd = '"%s" --multi-dex --dex --output="%s" "%s"' % (dxTool, file_operate.getFullPath(constant.tmpPath + '/' + channel), file_operate.getFullPath(constant.tmpPath + '/' + channel + "/jar"))  # 合并jar
    print "cmd" + cmd
    ret = file_operate.execFormatCmd(cmd)
    if ret:
        error_operate.error(104)
        return
    
    # copy libs
    targetDir = file_operate.getFullPath(constant.tmpPath + '/' + channel)
    oldApkDir = targetDir + "/oldApkDir"
    if os.path.exists(statisticsPath + "/ForLibs"):
        if os.path.exists(oldApkDir + "/lib/armeabi") and os.path.exists(statisticsPath + "/ForLibs/armeabi"):
            operate.copyResToApk(statisticsPath + "/ForLibs/armeabi", oldApkDir + "/lib/armeabi")
        if os.path.exists(oldApkDir + "/lib/armeabi-v7a") and os.path.exists(statisticsPath + "/ForLibs/armeabi-v7a"):
            operate.copyResToApk(statisticsPath + "/ForLibs/armeabi-v7a", oldApkDir + "/lib/armeabi-v7a")
        if os.path.exists(oldApkDir + "/lib/x86") and os.path.exists(statisticsPath + "/ForLibs/x86"):
            operate.copyResToApk(statisticsPath + "/ForLibs/x86", oldApkDir + "/lib/x86")
    
    # copy res
    if os.path.exists(statisticsPath + "/ForRes"):
        operate.copyResToApk(statisticsPath + "/ForRes", oldApkDir + "/res")
    
    if (os.path.exists(thirdStatisticsPath + "/statisticsScript.pyc")):
        file_operate.copyFile(thirdStatisticsPath + "/statisticsScript.pyc", file_operate.getFullPath(constant.tmpPath + '/' + channel) + "/statisticsScript.pyc")
    
    # 合并ForManifest.xml
    manifestFile = file_operate.getFullPath(constant.tmpPath + '/' + channel + "/ForManifest.xml")
    ET.register_namespace('android', constant.androidNS)
    targetTree = ET.parse(manifestFile)
    targetRoot = targetTree.getroot()
    
    haveChanged = modifyManifest.doModifyForManifest(manifestFile, thirdStatisticsPath + "/ForManifest.xml", targetRoot)
    if haveChanged:
        targetTree.write(manifestFile, 'UTF-8')
예제 #3
0
def main(channel, dict):
    threading.currentThread().setName(channel)
    
    writeConfigToSdkConfigFile(channel, dict)
    
    dictTemp = ConfigParse.shareInstance().ConfigRead(channel)
    platformId = dictTemp.get('platformId')
    appVersion = dictTemp.get('appVersion')
    resVersion = dictTemp.get('resVersion')
    platformType = dictTemp.get('platformType')
    packageName = dictTemp.get('packageName')
    checkBox_isChecked = dict.get('checkBox_isChecked')
    checkBox_2_isChecked = dict.get('checkBox_2_isChecked')
    checkBox_4_isChecked = dict.get('checkBox_4_isChecked')
    checkBox_5_isChecked = dict.get('checkBox_5_isChecked')
    checkBox_voice_isChecked=dict.get('checkBox_voice_isChecked')
    
    comboBox_currentText = dict.get('comboBox_currentText')
    comboBox_3_currentText = dict.get('comboBox_3_currentText')
    comboBox_4_currentText = dict.get('comboBox_4_currentText')
    comboBox_6_currentText = dict.get('comboBox_6_currentText')
    comboBox_voice_currentText= dict.get('comboBox_voice_currentText')
    taskManager.shareInstance().notify(channel, 5)
    
    taskLock = taskManager.shareInstance().getLock()
    
    ret = execGameCommonInitializeScript(channel, platformId, appVersion, resVersion, platformType)
    if ret:
        return
    CreateTmpFolder(channel)
    source = ConfigParse.shareInstance().getApkPath()
#     source = dict.get('ApkPath')
    backupApk(source, channel)
    sourceDir = file_operate.getFullPath(constant.sdkRelatePath + channel)
    targetDir = file_operate.getFullPath(constant.tmpPath + '/' + channel)
    file_operate.copyFiles(sourceDir, targetDir)

    apkFile = targetDir + "/common.apk"
    deDir = targetDir + "/oldApkDir"
    operate.decompileApk_android(apkFile, deDir, taskLock)
    
    processStatistics(channel, checkBox_isChecked, comboBox_4_currentText)
    
    processAdvertising(channel, checkBox_2_isChecked, comboBox_6_currentText)
    
    processCrash(channel, checkBox_4_isChecked, comboBox_currentText) 

    processPush(channel, checkBox_5_isChecked, comboBox_3_currentText) 
    
    processMedia(channel,checkBox_voice_isChecked,comboBox_voice_currentText)

    oldApkDir = targetDir + "/oldApkDir"
    SmaliDir = oldApkDir + "/smali"
    dexFile1 = targetDir + "/classes.dex"
    ret = operate.dexTrans2Smali(dexFile1, SmaliDir, 3)
    
    dexFile2 = targetDir + "/classes2.dex"
    if os.path.exists(dexFile2):
        global splitDexFlag
        splitDexFlag = True
        ret = operate.dexTrans2Smali(dexFile2, SmaliDir, 3)
    if ret:
        return
#     dexFileApk = oldApkDir + "/classes.dex"
#     ret = operate.dexTrans2Smali(dexFileApk, SmaliDir, 3)
#     if ret:
#         return
    # copy res
    if os.path.exists(targetDir + "/ForRes"):
        operate.copyResToApk(targetDir + "/ForRes", oldApkDir + "/res")
    # copy funcellconfig.xml
    file_operate.copyFile(file_operate.getchannelFuncellConfigXmlPath(channel), oldApkDir + "/assets/funcellconfig.xml")
    # copy Assets
    armPath = targetDir + "/ForAssets/so/armeabi"
    armv7Path = targetDir + "/ForAssets/so/armeabi-v7a"
    if os.path.exists(armPath) and os.path.exists(armv7Path):
        operate.copyResToApk(armPath, armv7Path)
        
    if os.path.exists(targetDir + "/ForAssets"):
        operate.copyResToApk(targetDir + "/ForAssets", oldApkDir + "/assets")
    # copy extra
    
    if os.path.exists(targetDir + "/extra"):
        #-----------------六扇门配置-----------------------
        if os.path.exists(targetDir + "/extra/Assets/GameAssets/Resources/Config"):
            execOtherScript(targetDir)
        #----------------------------------------
#         operate.copyResToApk(targetDir+"/extra", oldApkDir+"/assets")
        file_operate.copyFiles(targetDir + "/extra", oldApkDir + "/assets")
    
    # copy libs
    if os.path.exists(targetDir + "/ForLibs"):
        if os.path.exists(oldApkDir + "/lib/armeabi") and os.path.exists(targetDir + "/ForLibs/armeabi"):
            operate.copyResToApk(targetDir + "/ForLibs/armeabi", oldApkDir + "/lib/armeabi")
        if os.path.exists(oldApkDir + "/lib/armeabi-v7a") and os.path.exists(targetDir + "/ForLibs/armeabi-v7a"):
            operate.copyResToApk(targetDir + "/ForLibs/armeabi-v7a", oldApkDir + "/lib/armeabi-v7a")
        if os.path.exists(oldApkDir + "/lib/x86") and os.path.exists(targetDir + "/ForLibs/x86"):
            operate.copyResToApk(targetDir + "/ForLibs/x86", oldApkDir + "/lib/x86")
        if os.path.exists(oldApkDir + "/lib/mips") and os.path.exists(targetDir + "/ForLibs/mips"):
            operate.copyResToApk(targetDir + "/ForLibs/mips", oldApkDir + "/lib/mips")
    
    # �ϲ�AndroidManifest.xml
    manifestFile = oldApkDir + "/AndroidManifest.xml"
    ET.register_namespace('android', constant.androidNS)
    targetTree = ET.parse(manifestFile)
    targetRoot = targetTree.getroot()
    
    haveChanged = modifyManifest.doModify(manifestFile, targetDir + "/ForManifest.xml", targetRoot)
    if haveChanged:
        targetTree.write(manifestFile, 'UTF-8')
    
    
    newPackagename = operate.renameApkPackage(SmaliDir, manifestFile, packageName)
    
    print channel , oldApkDir
    operate.addSplashScreen(channel, targetDir);
    
    ret = execGameCommongameSdkScript(channel, oldApkDir)
    if ret:
        return
    
    # statisticsScript
    statisticsScriptPath = targetDir + "/statisticsScript.pyc"
    if os.path.exists(statisticsScriptPath):
        sys.path.append(targetDir)
        import statisticsScript
        statisticsScript.Script(oldApkDir, newPackagename)
        del sys.modules['statisticsScript']
        sys.path.remove(targetDir)
    
    # advertisingScript
    advertisingScriptPath = targetDir + "/advertisingScript.pyc"
    if os.path.exists(advertisingScriptPath):
        sys.path.append(targetDir)
        import advertisingScript
        advertisingScript.Script(oldApkDir, newPackagename)
        del sys.modules['advertisingScript']
        sys.path.remove(targetDir)
    
    # pushScript
    pushScriptPath = targetDir + "/pushScript.pyc"
    if os.path.exists(pushScriptPath):
        sys.path.append(targetDir)
        import pushScript
        ret = pushScript.script(oldApkDir, newPackagename)
        del sys.modules['pushScript']
        lsPath = []
        for item in sys.path:
            if str(item) == str(targetDir):
                continue
            lsPath.append(item)
        sys.path = lsPath
    
    # sdk����ű�
    scriptPath = targetDir + "/script.pyc"
    if os.path.exists(scriptPath):
        sys.path.append(targetDir)
        import script
        ret = script.script(oldApkDir, newPackagename)
        del sys.modules['script']
        lsPath = []
        for item in sys.path:
            if str(item) == str(targetDir):
                continue
            lsPath.append(item)
        sys.path = lsPath
    
    ret = operate.pushIconIntoApk('', oldApkDir, channel)
    
    operate.modifyGameName(channel, oldApkDir)
    
    ret = operate.produceNewRFile(channel, newPackagename, oldApkDir)
    if ret:
        return
    
    # smali to dex
#     classesDexFile = oldApkDir + "/classes.dex"
#     ret = operate.smaliTrans2dex(SmaliDir, classesDexFile)
#     if ret:
#         return 
    #         if os.path.exists(SmaliDir):
    #             file_operate.delete_file_folder(SmaliDir)
    
    if splitDexFlag == True:
        print '+++++++++++++++++++++++++++++++++++++'
#         operate.splitDex(targetDir, oldApkDir)
        operate.splitDex_old(targetDir, oldApkDir)
        print '+++++++++++++++++++++++++++++++++++++'
        

    operate.rewriteYml(oldApkDir)    
    tempApkName = file_operate.getFullPath(constant.outDir) + "/apk_"+channel+"_unsigned.apk"
    ret = operate.recompileApk(oldApkDir, tempApkName)
    if ret:
        return
    keystoreFile = ConfigParse.shareInstance().getKeystoreFile()
    storepassword = ConfigParse.shareInstance().getKeystorePassword()
    alias = ConfigParse.shareInstance().getKeystoreAlias()
    aliasPasswd = ConfigParse.shareInstance().getKeystoreAliasPassword()
    # def signApk(apkFile, keyStore, storepassword, keyalias, aliaspassword):
    ret = operate.signApk(tempApkName, keystoreFile, storepassword, alias, aliasPasswd)
    print "sign"
    print ret
    if ret:
        return
    
    apkName = file_operate.getFullPath(constant.outDir) + "/apk_" + channel + ".apk" 
    ret = operate.alignAPK(tempApkName, apkName, file_operate.getFullPath(constant.outDir))
    
    ret = execGameCommonFinalizeScript(channel, platformId, appVersion, resVersion, checkBox_isChecked, checkBox_4_isChecked, checkBox_5_isChecked)
    if ret:
        print 'execGameCommonFinalizeScript error:'
        return
    taskManager.shareInstance().notify(channel, 100)
    print "----------------------------%s pack complete!------------------------" % channel