Example #1
0
def processAdvertising(channel, checkBox_2_isChecked, comboBox_6_currentText):
    if not checkBox_2_isChecked:
        return
    
    advertisingPath = file_operate.getAdvertisingPath()
    thirdAdvertisingName = comboBox_6_currentText
    thirdAdvertisingPath = advertisingPath + '/' + str(thirdAdvertisingName)
    print "..........", thirdAdvertisingPath
    file_operate.copyFiles(thirdAdvertisingPath + "/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
    
    if (os.path.exists(thirdAdvertisingPath + "/advertisingScript.pyc")):
        file_operate.copyFile(thirdAdvertisingPath + "/advertisingScript.pyc", file_operate.getFullPath(constant.tmpPath + '/' + channel) + "/advertisingScript.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, thirdAdvertisingPath + "/ForManifest.xml", targetRoot)
    if haveChanged:
        targetTree.write(manifestFile, 'UTF-8')
Example #2
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-------------"    
Example #3
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')
Example #4
0
def split_apk(db_name, game_id, id_channel, parent_apk_path, sub_apk_path,
              sub_channel_id):
    reload(sys)
    sys.setdefaultencoding('utf8')
    log_dir = '%s/%s/%s' % (db_name, game_id, id_channel)
    ConfigParse.shareInstance().set_log_dir(log_dir)
    if not os.path.exists(parent_apk_path):
        logError('parent apk not exist', log_dir)
        print '{"ret":"fail","msg":"parent apk not exist"}'
        return
    middle_dir = '%s/%s' % (db_name, sub_channel_id)
    split_work_dir = file_operate.get_server_dir(
    ) + '/split_workspace/%s' % middle_dir
    print 'split_work_dir:' + split_work_dir
    if os.path.exists(split_work_dir):
        file_operate.delete_file_folder(split_work_dir)

    os.makedirs(split_work_dir)
    split_decompile_dir = split_work_dir + '/decompile'
    os.mkdir(split_decompile_dir)

    channel_temp_apk_dir = split_work_dir + '/temp'
    os.mkdir(channel_temp_apk_dir)

    channel_temp_apk = channel_temp_apk_dir + '/temp.apk'
    file_operate.copyFile(parent_apk_path, channel_temp_apk)

    ret = apk_operate.decompileApk(channel_temp_apk, split_decompile_dir, None)
    if ret:
        logError('decompileApk parent apk fail', log_dir)
        print '{"ret":"fail","msg":"decompileApk parent apk fail"}'
        return
    ConfigParse.shareInstance().readUserConfig(0)
    sub_channel_config = ConfigParse.shareInstance().get_sub_channel_config()

    sub_channel_icon_url = None
    display_name = None
    sub_app_id = ''
    sub_num = ''

    if len(sub_channel_config) > 0:
        for r in sub_channel_config:
            if int(id_channel) != int(r['p_channel_id']):
                logError('param channel id is not right', log_dir)
                print '{"ret":"fail","msg":"param channel id is not right"}'
                return

            if int(game_id) != int(r['game_id']):
                logError('param game id is not right', log_dir)
                print '{"ret":"fail","msg":"param game id is not right"}'
                return

            if r['r_channel_game_icon'] is None:
                sub_channel_icon_url = ''
            else:
                sub_channel_icon_url = r['r_channel_game_icon']

            if r['display_name'] is None:
                display_name = ''
            else:
                display_name = r['display_name'].encode('utf-8')

            sub_app_id = str(r['sub_app_id'])
            print 'sub_app_id: %s' % sub_app_id
            sub_num = str(r['sub_num'])

    else:
        logError('sub channel config is empty', log_dir)
        print '{"ret":"fail","msg":"sub channel config is empty"}'
        return

    if sub_app_id == 0 or sub_num == 0:
        log_info = 'ret:fail,msg:sub_app_id and sub_num == 0'
        logError(log_info, log_dir)
        return

    if display_name != '' and display_name is not None:
        apk_operate.doModifyAppName(split_decompile_dir, display_name)

    if sub_channel_icon_url != '' and sub_channel_icon_url is not None:
        channel_icon_dir = split_work_dir + '/icon/'
        os.mkdir(channel_icon_dir)
        urllib.urlretrieve(sub_channel_icon_url, channel_icon_dir + 'icon.png')
        ret = apk_operate.pushIconIntoApk(channel_icon_dir,
                                          split_decompile_dir)
        if ret:
            logError('pushIconIntoApk error', log_dir)
            return
    ret = encode_operate.decodeXmlFiles(split_decompile_dir)
    if ret:
        logError('decodeXmlFiles error', log_dir)
        return

    channel = ConfigParse.shareInstance().findChannel(int(id_channel))
    sdk_dir = split_work_dir + '/sdk/'
    for channel_sdk in channel['sdkLs']:
        id_sdk = channel_sdk['idSDK']
        SDK = ConfigParse.shareInstance().findSDK(id_sdk)
        if SDK is None:
            continue
        split_script_src_dir = file_operate.get_server_dir(
        ) + '/config/sdk/' + SDK['SDKName'] + '/specialsplit_script.pyc'
        split_script_src_dir = file_operate.getFullPath(split_script_src_dir)
        if not os.path.exists(split_script_src_dir):
            continue

        split_script_dest_dir = sdk_dir + SDK[
            'SDKName'] + '/specialsplit_script.pyc'

        file_operate.copyFiles(split_script_src_dir, split_script_dest_dir)
        SDKDir = sdk_dir + SDK['SDKName']
        sys.path.append(SDKDir)
        import specialsplit_script
        print 'sub_app_id:' + sub_app_id
        ret = specialsplit_script.script(split_decompile_dir, sub_app_id,
                                         sub_num)
        del sys.modules['specialsplit_script']
        sys.path.remove(SDKDir)
        if ret:
            logError("error do Special Operate", log_dir)
            print "error do Special Operate"
            return

    ret = change_develop_id(split_decompile_dir, sub_app_id, sub_num)
    print 'change_develop_id ret:%s' % ret
    if ret:
        logError('change develop id error', log_dir)
        return

    encode_operate.encodeXmlFiles(split_decompile_dir)

    channel_unsign_apk = channel_temp_apk_dir + '/channel_temp_apk.apk'
    ret = apk_operate.recompileApk(split_decompile_dir, channel_unsign_apk)
    if ret:
        logError("recompileApk fail", log_dir)
        print "recompileApk fail"
        return
    game = ConfigParse.shareInstance().getCurrentGame()
    if game is None:
        print 'game is none'
        logError('game is none', log_dir)
        return
    ret = apk_operate.signApkAuto(channel_unsign_apk, game, channel,
                                  middle_dir)

    if ret:
        print 'signApkAuto fail'
        logError('signApkAuto fail', log_dir)
        return

    out_put_dir = os.path.dirname(sub_apk_path)
    ret = apk_operate.alignAPK(channel_unsign_apk, sub_apk_path, out_put_dir)
    if ret:
        print 'alignAPK fail'
        logError('alignAPK fail', log_dir)
        return
    print '{"ret":"success","msg":"run pack success"}'
    file_operate.delete_file_folder(split_work_dir)
def produceNewRFile(packName,
                    decompileFullDir,
                    androidManiFest='AndroidManifest.xml'):
    """
        According to the merger of resources to create new R file
    """
    fullPath = decompileFullDir
    tempPath = os.path.dirname(decompileFullDir)
    tempPath = tempPath + '/tempRFile'
    if os.path.exists(tempPath):
        file_operate.delete_file_folder(tempPath)
    if not os.path.exists(tempPath):
        os.makedirs(tempPath)
    resPath = os.path.join(decompileFullDir, 'res')
    targetResPath = os.path.join(tempPath, 'res')
    file_operate.copyFiles(resPath, targetResPath)
    genPath = os.path.join(tempPath, 'gen')
    if not os.path.exists(genPath):
        os.mkdir(genPath)
    androidPath = file_operate.getToolPath('android.jar')
    srcManifest = os.path.join(fullPath, androidManiFest)
    aaptPath = file_operate.getToolPath('aapt')
    cmd = '"%s" p -f -m -J "%s" -S "%s" -I "%s" -M "%s"' % (
        aaptPath, genPath, targetResPath, androidPath, srcManifest)
    ret = file_operate.execFormatCmd(cmd)
    if ret:
        error_operate.error(102)
        return 1
    RPath = packName.replace('.', '/')
    RPath = os.path.join(genPath, RPath)
    RFile = os.path.join(RPath, 'R.java')
    cmd = '"%sjavac" -source 1.7 -target 1.7 -encoding UTF-8 "%s"' % (
        file_operate.getJavaBinDir(), RFile)
    ret = file_operate.execFormatCmd(cmd)
    if ret:
        error_operate.error(103)
        return 1

    #针对某系渠道通过R。xx来获取资源,在指定包名下添加R文件
    try:
        config = ET.parse(file_operate.getConfigXmlPath())
        root = config.getroot()
        Manifest = root.find("Manifest")
        num = int(Manifest.get('num'))
        for i in range(0, num):
            srcManifest_i = os.path.join(
                file_operate.getFullPath(constant.tmpPath),
                'Manifest/' + str(i) + '/AndroidManifest.xml')
            cmd = '"%s" p -f -m -J "%s" -S "%s" -I "%s" -M "%s"' % (
                aaptPath, genPath, targetResPath, androidPath, srcManifest_i)
            ret = file_operate.execFormatCmd(cmd)
            if ret:
                error_operate.error(102)
                return 1
            packageNameArray = Manifest.get('packageNameArray')
            packageNameNode = packageNameArray.split(',')[i]
            RPath = packageNameNode.replace('.', '/')
            RPath = os.path.join(genPath, RPath)
            RFile = os.path.join(RPath, 'R.java')
            cmd = '"%sjavac" -source 1.7 -target 1.7 -encoding UTF-8 "%s"' % (
                file_operate.getJavaBinDir(), RFile)
            ret = file_operate.execFormatCmd(cmd)
            if ret:
                error_operate.error(103)
                return 1
    except Exception, e:
        print e
        print "Error: cannot parse file: funcellconfig.xml."
 codeDir = decompileDir + '/oldApkDir/' + '/smali/com/haowan/funcell/sdk/api/splash'
 newSplashCodePath = codeDir + '/SplashActivity.smali'
 print "newSplashCodePath : " + newSplashCodePath
 file_operate.copyFile(SplashCodePath, newSplashCodePath)
 newSplashCode2Path = codeDir + '/SplashActivity$1.smali'
 file_operate.copyFile(SplashCode2Path, newSplashCode2Path)
 activityName = removeStartActivity(channelHasSplash,
                                    decompileDir + '/oldApkDir/')
 modifyManifestForSplash(channelHasSplash, decompileDir + '/oldApkDir/')
 xmlSplashTarget = decompileDir + '/oldApkDir/' + '/res/layout'
 if not os.path.exists(xmlSplashTarget):
     os.mkdir(xmlSplashTarget)
 xmlSplashTarget = xmlSplashTarget + '/funcell_plugin_splash.xml'
 file_operate.copyFile(xmlSplashSrc, xmlSplashTarget)
 resDir = decompileDir + '/oldApkDir/' + '/res'
 file_operate.copyFiles(SplashPath, resDir)
 #     assetsDir = decompileDir + '/assets'
 #     developerFile = assetsDir + '/developerInfo.xml'
 #     if not os.path.exists(assetsDir):
 #         os.makedirs(assetsDir)
 #     targetTree = None
 #     targetRoot = None
 #     if not os.path.exists(developerFile):
 #         targetTree = ElementTree()
 #         targetRoot = Element('developer')
 #         targetTree._setroot(targetRoot)
 #     else:
 #         targetTree = ET.parse(developerFile)
 #         targetRoot = targetTree.getroot()
 #     infoNode = targetRoot.find('channel')
 #     if infoNode is None:
Example #7
0
 def custom_package_r_file(self, packageName, androidManiFest = 'AndroidManifest.xml'):
     '''
     create custom packageName R file
     :param packageName:
     :param androidManiFest:
     :return:
     '''
     # bMerge = mergeValueXml(decompileFullDir)
     # if bMerge:
     #     error_operate.error(102)
     #     return 1
     fullPath = self.__decompileDir
     tempPath = os.path.dirname(self.__decompileDir)
     tempPath = tempPath + '/tempRFile'
     if os.path.exists(tempPath):
         file_operate.delete_file_folder(tempPath)
     if not os.path.exists(tempPath):
         os.makedirs(tempPath)
     resPath = os.path.join(self.__decompileDir, 'res')
     targetResPath = os.path.join(tempPath, 'res')
     file_operate.copyFiles(resPath, targetResPath)
     genPath = os.path.join(tempPath, 'gen')
     if not os.path.exists(genPath):
         os.mkdir(genPath)
     androidPath = file_operate.getToolPath('android.jar')
     srcManifest = os.path.join(fullPath, androidManiFest)
     aaptPath = file_operate.getToolPath('aapt')
     cmd = '"%s" p -f -m -J "%s" --custom-package "%s" -S "%s" -I "%s" -M "%s"' % (aaptPath,
      genPath,
      packageName,
      targetResPath,
      androidPath,
      srcManifest)
     ret = file_operate.execFormatCmd(cmd)
     if ret:
         error_operate.error(102)
         return 1
     RPath = packageName.replace('.', '/')
     RPath = os.path.join(genPath, RPath)
     RFile = os.path.join(RPath, 'R.java')
     cmd = '"%sjavac" -source 1.7 -target 1.7 -encoding UTF-8 "%s"' % (file_operate.getJavaBinDir(), RFile)
     ret = file_operate.execFormatCmd(cmd)
     if ret:
         error_operate.error(103)
         return 1
     dexPath = os.path.join(tempPath, 'class.dex')
     if platform.system() == 'Windows':
         dxTool = file_operate.getToolPath('dx.bat')
         cmd = '"%s" --dex --output="%s" "%s"' % (dxTool, dexPath, genPath)
     else:
         dxTool = file_operate.getToolPath('/lib/dx.jar')
         cmd = 'java -jar -Xms512m -Xmx512m "%s" --dex --output="%s" "%s"' % (dxTool, dexPath, genPath)
     ret = file_operate.execFormatCmd(cmd)
     if ret:
         error_operate.error(104)
         return 1
     smaliPath = os.path.join(fullPath, 'smali')
     ret = apk_operate.dexTrans2Smali(dexPath, smaliPath, 10, 'baksmali.jar')
     if ret:
         return 1
     else:
         return 0
     pass
Example #8
0
def main(channel):
    # 调用函数 8.4
    inspectJDK()
    source = ConfigParse.shareInstance().getSource()
    if os.path.isdir(source):
        error_operate.error(3000)
        return
        # buildGradle(channel)
    else:
        idChannel = channel.get('idChannel')
        channelName = channel.get('name')
        channelNum = channel.get('channelNum')
        ConfigParse.shareInstance().set_channel_num(channelNum)

        extChannel = channel.get('extChannel')
        threading.currentThread().setName(idChannel)
        taskManager.shareInstance().notify(idChannel, 5)
        # source = ConfigParse.shareInstance().getSource()
        basename = os.path.basename(source)
        exttuple = os.path.splitext(basename)
        taskLock = taskManager.shareInstance().getLock()
        basename = exttuple[0]
        extname = exttuple[1]
        game = ConfigParse.shareInstance().getCurrentGame()
        if game is None:
            error_operate.error(3)
            return
        versionName = ConfigParse.shareInstance().getVersionName()
        print '<---Parent apk versionName-->%s' % (versionName)
        keystore = ConfigParse.shareInstance().getKeyStore()
        print '<---Game keystore info-->%s' % (keystore)
        if channelName is None:
            error_operate.error(5)
            return
        taskManager.shareInstance().notify(idChannel, 10)
        # file_operate.execFormatCmd('chmod -R 777 %s' % (file_operate.get_server_dir()+'/workspace/'))
        workDir = file_operate.get_server_dir() + '/workspace/%s/%s' % (
            ConfigParse.shareInstance().getDBName(), idChannel)
        workDir = file_operate.getFullPath(workDir)
        file_operate.delete_file_folder(workDir)
        if not os.path.exists(source):
            error_operate.error(60)
            return
        tmpApkSource = workDir + '/temp.apk'
        file_operate.copyFile(source, tmpApkSource)
        print 'tmpApkSource-->' + tmpApkSource
        decompileDir = workDir + '/decompile'
        ret = apk_operate.decompileApk(tmpApkSource, decompileDir, taskLock)
        print 'step--decompileAPK--RET-->%d' % (ret)
        if ret:
            return
        unknownFile = decompileDir + '/AddForRoot'
        if os.path.exists(decompileDir + '/unknown'):
            os.rename(decompileDir + '/unknown', unknownFile)
        # oldPackageName = apk_operate.getPackageName(decompileDir)
        # isCocosPlay = apk_operate.checkForCocosPlay(decompileDir, channel, oldPackageName)
        # if isCocosPlay:
        #     ret = apk_operate.renameApkForCocosPlay(decompileDir, oldPackageName, channel['packNameSuffix'], game,
        #                                             channel, taskLock)
        #     if ret:
        #         return
        # ConfigParse.shareInstance().setCocosPlayMode(isCocosPlay)

        apk_operate.replace_custom_res(decompileDir)

        taskManager.shareInstance().notify(idChannel, 20)
        SmaliDir = decompileDir + '/smali'
        SDKWorkDir = workDir + '/sdk/'
        for Channel_SDK in channel['sdkLs']:
            idSDK = Channel_SDK['idSDK']
            SDK = ConfigParse.shareInstance().findSDK(idSDK)
            if SDK == None:
                continue
            SDKSrcDir = file_operate.get_server_dir(
            ) + '/config/sdk/' + SDK['SDKName']
            SDKSrcDir = file_operate.getFullPath(SDKSrcDir)
            SDKDestDir = SDKWorkDir + SDK['SDKName']
            file_operate.copyFiles(SDKSrcDir, SDKDestDir)
            if os.path.exists(SDKDestDir + '/ForRes/drawable-xxxhdpi'):
                if file_operate.getTargetSdkVersion(tmpApkSource) < 18:
                    file_operate.delete_file_folder(SDKDestDir +
                                                    '/ForRes/drawable-xxxhdpi')

        taskManager.shareInstance().notify(idChannel, 30)
        for Channel_SDK in channel['sdkLs']:
            idSDK = Channel_SDK['idSDK']
            SDK = ConfigParse.shareInstance().findSDK(idSDK)
            if SDK == None:
                continue
            SDKDir = SDKWorkDir + SDK['SDKName']
            SDKDex = os.path.join(SDKDir, 'classes.dex')
            SDKDex = file_operate.getFullPath(SDKDex)
            ret = apk_operate.dexTrans2Smali(SDKDex, SmaliDir, 4,
                                             'baksmali.jar')
            if ret:
                return

        taskManager.shareInstance().notify(idChannel, 35)
        decompileSmaliDir = decompileDir + '/smali'
        maniFestFile = decompileDir + '/AndroidManifest.xml'
        newPackagename = apk_operate.renameApkPackage(
            decompileSmaliDir, maniFestFile, channel['packNameSuffix'],
            channel['r_bundle_id'])

        #reset apk version
        if channel['r_gameversion_build'] != '' and channel[
                'r_gameversion'] != '':
            apk_operate.resetApkVersion(maniFestFile,
                                        channel['r_gameversion_build'],
                                        channel['r_gameversion'])
            file_operate.printf("Reset ApkVersion success")

        taskManager.shareInstance().notify(idChannel, 45)
        print '<---- decompileDir:%s ---->' % (decompileDir)
        print '<---- channel:%s ---->' % (channel)
        print '<---- game:%s ---->' % (game)
        apk_operate.writeChannelInfoIntoDevelopInfo(decompileDir, channel,
                                                    game)
        apk_operate.writeSupportInfo(decompileDir)
        taskManager.shareInstance().notify(idChannel, 50)
        bExecuteSpecialScipt = False
        for Channel_SDK in channel['sdkLs']:
            idSDK = Channel_SDK['idSDK']
            UsrSDKConfig = ConfigParse.shareInstance().findUserSDKConfigBySDK(
                idSDK, channel['idChannel'])
            SDK = ConfigParse.shareInstance().findSDK(idSDK)
            if SDK == None:
                continue
            ret = apk_operate.packResIntoApk(SDKWorkDir, SDK, decompileDir,
                                             newPackagename, UsrSDKConfig)
            if ret:
                return
            SDKVersionInfo = ConfigParse.shareInstance().findSDKVersion(
                SDK['SDKName'])
            if SDKVersionInfo is not None:
                SDK['showVersion'] = SDKVersionInfo['showVersion']
            print '<---- SDK:%s ---->' % (SDK)
            print '<---- UsrSDKConfig:%s ---->' % (UsrSDKConfig)
            ret = apk_operate.configDeveloperInfo(channel, SDK, UsrSDKConfig,
                                                  decompileDir)
            if ret:
                return
            # apk_operate.downloadUserConfigFile(channel,game,UsrSDKConfig)
            for child in SDK['operateLs']:
                if child['name'] == 'script' or child['name'] == 'Script':
                    bExecuteSpecialScipt = True
                    break

        taskManager.shareInstance().notify(idChannel, 65)
        # bMergeR = False
        ret, bMergeR = apk_operate.addSplashScreen(channel, decompileDir)
        if ret:
            return
        ret = encode_operate.encodeXmlFiles(workDir + '/decompile')
        if ret:
            return

        taskManager.shareInstance().notify(idChannel, 60)
        if bExecuteSpecialScipt:
            ret = special_script.doSpecialOperate(channel, decompileDir,
                                                  newPackagename, SDKWorkDir)
            if ret:
                return

        taskManager.shareInstance().notify(idChannel, 70)

        if extChannel.find("androidsupportv4") != -1:
            print 'handle androidsupportv4 resource'
            androidsupportv4dex = decompileDir + '/../../../../config/channel/android-support-v4.dex'
            if os.path.exists(androidsupportv4dex):
                samilDir = decompileDir + '/smali'
                ret = apk_operate.dexTrans2Smali(androidsupportv4dex, samilDir,
                                                 10)
                if ret:
                    print('copy androidsupportv4 dex to smali fail')
                    return
            else:
                print('androidsupportv4.dex is not exists')
                return

        if (ConfigParse.shareInstance().getChannelIcon(idChannel) != ''):
            iconDir = file_operate.get_server_dir(
            ) + '/workspace/' + ConfigParse.shareInstance().getOutputDir(
            ) + '/icon/'
            if not os.path.exists(iconDir):
                os.makedirs(iconDir)
            urllib.urlretrieve(
                ConfigParse.shareInstance().getChannelIcon(idChannel),
                iconDir + 'icon.png')

            ret = apk_operate.pushIconIntoApk(iconDir, decompileDir)
            if ret:
                return
        # newAppName = ConfigParse.shareInstance().getAppName()
        #modify app display name by game setting
        # apk_operate.modifyAppName(game, decompileDir, newAppName)
        # modify app display name by channel setting
        #if channel display_name is not null,the app displayname will be set by channel
        apk_operate.modifyAppNameByChannel(channel, decompileDir)

        apk_operate.writeDataIntoAndroidManifest(decompileDir, channel)
        taskManager.shareInstance().notify(idChannel, 75)

        ret = apk_operate.produceNewRFile(newPackagename, decompileDir)
        if ret:
            return
        ret = apk_operate.splitDex(workDir, channel)
        if ret:
            return
        taskManager.shareInstance().notify(idChannel, 80)
        tempApkDir = workDir + '/tempApk'
        tempApkDir = file_operate.getFullPath(tempApkDir)
        tempApkName = '%s/game_%s_%s%s' % (tempApkDir, channel['idChannel'],
                                           versionName, extname)
        apk_operate.encryptApkByDeveloper(decompileDir)
        ret = apk_operate.recompileApk(decompileDir, tempApkName)
        if ret:
            return
        print '<---recompileApk success--->'
        taskManager.shareInstance().notify(idChannel, 90)
        for Channel_SDK in channel['sdkLs']:
            idSDK = Channel_SDK['idSDK']
            SDK = ConfigParse.shareInstance().findSDK(idSDK)
            if SDK == None:
                continue
            SDKSrcDir = file_operate.get_server_dir(
            ) + '/config/sdk/' + SDK['SDKName']
            SDKSrcDir = file_operate.getFullPath(SDKSrcDir)
            ForRootDir = SDKSrcDir + '/ForRootDir'
            if os.path.exists(ForRootDir):
                apk_operate.addForRootDir(tempApkName, ForRootDir)

        if os.path.exists(unknownFile):
            apk_operate.addForRootDir(tempApkName, unknownFile)
        ret = apk_operate.signApkAuto(tempApkName, game, channel)
        if ret:
            return
        #outputDir = ConfigParse.shareInstance().getOutputDir()
        #print '<---outputDir--->'+outputDir

#if outputDir == '':
#   outputDir = '../'

#get date for apk file name
        import time

        # dateStr = time.strftime("%Y%m%d%H%M%S")

        #get final apk name
        finalAppName = ''
        print '<---start rename apk--->'
        # if game.get('isModifyAppName') is not None and game['isModifyAppName'] != False:
        #     finalAppName = game.get('gameName').encode('utf-8')
        # display_name = channel['display_name'].encode('utf-8')
        # if display_name is not None and display_name != '':
        #     finalAppName = display_name
        #
        # if finalAppName == '':
        #     finalAppName = game.get('gameName')
        # channel_name = channel['name'].encode('utf-8')
        #outputDir += '/' + game['gameName'] + '/' + versionName + '/' + channel_name
        #outputDir = file_operate.getFullPath(outputDir)
        #apkName = ('%s/%s_%s_%s_%s%s' % (outputDir,
        #                               finalAppName,
        #                              channel_name,
        #                             versionName,
        #                            dateStr,
        #                           extname)).encode('utf-8')
        apkName = ConfigParse.shareInstance().getOutPutApkName()
        print '<---Apk PATH--->' + apkName
        #if platform.system() == 'Windows':
        #   apkName = '%s/game_%s%s' % (outputDir, versionName, extname)
        #  print '<---apk path:'+apkName+'--->'
        strlist = apkName.split('/')
        outputDir = apkName.replace('/' + strlist[len(strlist) - 1], '')
        print '<---outputDir--->' + outputDir
        ret = apk_operate.alignAPK(tempApkName, apkName, outputDir)
        if ret:
            print '{"ret":"fail","msg":"run pack fail"}'
            return
        print '{"ret":"success","msg":"run pack success"}'
        taskManager.shareInstance().notify(idChannel, 100)
Example #9
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
Example #10
0
def main(channel):
    idChannel = channel.get('idChannel')
    channelName = channel.get('name')
    channelNum = channel.get('channelNum')
    threading.currentThread().setName(idChannel)
    taskManager.shareInstance().notify(idChannel, 20)
    source = ConfigParse.shareInstance().getSource()
    basename = os.path.basename(source)
    exttuple = os.path.splitext(basename)
    basename = exttuple[0]
    extname = exttuple[1]
    originDir = ConfigParse.shareInstance().getProjFolder()
    useSDK = ConfigParse.shareInstance().getProjSDKVersion()
    systemSDKPath = ConfigParse.shareInstance().getProjSDKPath()
    ipaPackage = ConfigParse.shareInstance().getProjIpaPackage()
    game = ConfigParse.shareInstance().getCurrentGame()
    if channelName is None:
        error_operate.error(5)
        return
    versionName = ConfigParse.shareInstance().getVersionName()
    outputDir = ConfigParse.shareInstance().getOutputDir()
    if outputDir == '':
        outputDir = '../'
    #cocos2dx need cocos2dx framework,so we must put release pdroject to cocos2dx dictionary
    #outputDir += '/' + game['gameName'] + '/' + versionName + '/' + channel['name']
    outputDir += '/' + channel['name'] + '_' + versionName

    outputDir = file_operate.getFullPath(outputDir)
    outputDir = os.path.realpath(outputDir)
    file_operate.delete_file_folder(outputDir)
    #workDir = outputDir + '/Project_iOS'
    workDir = outputDir
    workDir = file_operate.getFullPath(workDir)
    workDir = os.path.realpath(workDir)
    file_operate.delete_file_folder(workDir)
    iconDir = '../workspace/icon/' + channelNum
    iconDir = file_operate.getFullPath(iconDir)
    iconDir = os.path.realpath(iconDir)
    if not os.path.exists(outputDir):
        os.makedirs(outputDir)
    if not os.path.exists(workDir):
        os.makedirs(workDir)
    file_operate.copyFiles(originDir, workDir)
    pbxFile = workDir + '/' + ConfigParse.shareInstance().getProjXcode(
    ) + '/project.pbxproj'
    target_name = None
    project = XcodeProject.Load(pbxFile)
    #从congfig.py里的getTargetName取到要编译打包的target,没有的话用默认的最后一个target
    if ConfigParse.shareInstance().getTargetName():
        target_name = project_name = ConfigParse.shareInstance().getTargetName(
        )
        print '----config ---- target name ----' + target_name
#        print 'ERROR_>'+target_name+'<_ERROR'
#        print 'WARNING_>'+target_name+'<_WARNING'
    else:
        target_name = project_name = project.get_target_name()

    project_config = project.get_configurations()
    #use release archieve ipa
    project_config = 'Release'
    project.add_other_ldflags('-ObjC')
    project.showSearchPathInfo()
    """add other flag param"""
    #project.add_other_ldflags('-lz')

    if project.modified:
        project.save()
    taskManager.shareInstance().notify(idChannel, 40)
    parentDir = ''
    for parent, dirnames, filenames in os.walk(workDir):
        for filename in filenames:
            if filename == 'Contents.json':
                if parent.find('Images.xcassets/AppIcon.appiconset') != -1:
                    parentDir = parent

    if parentDir != '':
        for parent, dirnames, filenames in os.walk(parentDir):
            for filename in filenames:
                if filename != 'Contents.json':
                    os.remove(parentDir + '/' + filename)

        jsonFile = open(parentDir + '/Contents.json')
        jsonContent = json.load(jsonFile)
        for child in jsonContent['images']:
            imgSize = int(child['size'][0:child['size'].find('x')]) * int(
                child['scale'][0:child['scale'].find('x')])
            imgName = 'Icon-' + str(imgSize) + '.png'
            if os.path.exists(iconDir + '/' +
                              imgName) and not os.path.exists(parentDir + '/' +
                                                              imgName):
                file_operate.copyFile(iconDir + '/' + imgName,
                                      parentDir + '/' + imgName)
            child['filename'] = imgName

        jsonContent = json.dumps(jsonContent)
        jsonFile.close()
        jsonFile = open(parentDir + '/Contents.json', 'w')
        try:
            jsonFile.write(jsonContent)
        finally:
            jsonFile.close()

    project_infoplist = workDir + '/' + ConfigParse.shareInstance(
    ).getProjXcode() + '/../' + project.get_infoplistfile()
    newAppName = ''
    if game.get(
            'isModifyiOSName') is not None and game['isModifyiOSName'] == True:
        newAppName = ConfigParse.shareInstance().getIosName()
        if newAppName is None or newAppName == '':
            newAppName = game.get('gameName')
    #set display name by channel
    if channel['display_name'] != '':
        newAppName = channel['display_name']

    customBundleId = channel['r_bundle_id']
    if os.path.exists(project_infoplist) and (
            newAppName != '' or channel['packNameSuffix'] != ''
            or channel['r_gameversion'] != ''
            or channel['r_gameversion_build'] != '' or customBundleId != ''):
        plistModify = False
        try:
            plist = readPlist(project_infoplist)
            for key in plist:
                if key == 'CFBundleName' and newAppName != '':
                    plist['CFBundleName'] = newAppName
                    plistModify = True
                elif key == 'CFBundleIdentifier':
                    if customBundleId == '':
                        plist['CFBundleIdentifier'] = plist[
                            'CFBundleIdentifier'] + channel['packNameSuffix']
                    else:
                        plist['CFBundleIdentifier'] = customBundleId
                    plistModify = True
                elif key == 'CFBundleShortVersionString' and channel[
                        'r_gameversion'] != '':
                    plist['CFBundleShortVersionString'] = channel[
                        'r_gameversion']
                    plistModify = True
                elif key == 'CFBundleVersion' and channel[
                        'r_gameversion_build'] != '':
                    plist['CFBundleVersion'] = channel['r_gameversion_build']
                    plistModify = True

            if plistModify == True:
                try:
                    writePlist(plist, project_infoplist)
                    project.modify_bundle_identifier(
                        plist['CFBundleIdentifier'])
                    project.save()
                except Exception as e:
                    print 'modify bundle Id/bundle Name Error:' + e

        except:
            print 'No Plist found'

    writeChannelInfoIntoDevelopInfo(workDir, channel, game)
    writeSupportInfo(workDir)
    SDKWorkDir = workDir + '/sdk/'
    list = [0, 2, 1, 3, 4, 5, 6]
    for count in range(len(list)):
        for Channel_SDK in channel['sdkLs']:
            idSDK = Channel_SDK['idSDK']
            usrSDKConfig = ConfigParse.shareInstance().findUserSDKConfigBySDK(
                idSDK, channel['idChannel'])
            SDK = ConfigParse.shareInstance().findSDK(idSDK)
            if SDK == None:
                continue
            for plugin in SDK['pluginLs']:
                type = plugin['typePlugin']
                if type == list[count]:
                    SDKSrcDir = '../config/sdk/' + SDK['SDKName']
                    SDKSrcDir = file_operate.getFullPath(SDKSrcDir)
                    SDKDestDir = SDKWorkDir + SDK['SDKName']
                    SDKDestDir = os.path.realpath(SDKDestDir)
                    if os.path.exists(SDKDestDir):
                        continue
                    file_operate.copyFiles(SDKSrcDir, SDKDestDir)
                    lib_path = 'sdk/' + SDK['SDKName'] + '/'
                    project = XcodeProject.Load(pbxFile)
                    scriptPath = SDKDestDir + '/script.pyc'
                    if os.path.exists(scriptPath):
                        sys.path.append(SDKDestDir)
                        import script
                        script.script(SDK, workDir, target_name, usrSDKConfig,
                                      SDKDestDir, project)
                        del sys.modules['script']
                        sys.path.remove(SDKDestDir)
                    if os.path.exists(SDKDestDir + '/Frameworks'):
                        addFrameworkGroupPath(SDKDestDir + '/Frameworks',
                                              target_name, project)

                    if os.path.exists(SDKDestDir + '/Resources'):
                        for res in os.listdir(SDKDestDir + '/Resources'):
                            project.add_file(SDKDestDir + '/Resources/' + res,
                                             None, 'SOURCE_ROOT', True, False,
                                             False, target_name)

                    if os.path.exists(SDKDestDir + '/Codes'):
                        for codes in os.listdir(SDKDestDir + '/Codes'):
                            project.add_file(SDKDestDir + '/Codes/' + codes,
                                             None, 'SOURCE_ROOT', True, False,
                                             False, target_name)

                    if project.modified:
                        project.save()
                    xmlFile = SDKDestDir + '/config.xml'
                    doc = minidom.parse(xmlFile)
                    rootNode = doc.documentElement
                    sysFrameworksList = rootNode.getElementsByTagName(
                        'sysFrameworks')
                    for sysFrameworksNode in sysFrameworksList:
                        path = ''
                        required = False
                        if sysFrameworksNode.getAttribute('required') == '0':
                            required = True
                        if sysFrameworksNode.getAttribute(
                                'path') == 'xcodeFrameworks':
                            path = systemSDKPath + '/System/Library/Frameworks/' + sysFrameworksNode.getAttribute(
                                'name')
                        elif sysFrameworksNode.getAttribute(
                                'path') == 'xcodeUsrlib':
                            path = systemSDKPath + '/usr/lib/'
                            frameworkName = sysFrameworksNode.getAttribute(
                                'name')
                            #if ios 9 and above,replace .dylib to .tbd
                            if isIOS9(systemSDKPath):
                                print 'use ios 9 sdk for' + sysFrameworksNode.getAttribute(
                                    'name')
                                path = path + frameworkName.replace(
                                    '.dylib', '.tbd')
                            else:
                                path = path + frameworkName
                                print 'donot use ios 9 sdk'
                        else:
                            path = sysFrameworksNode.getAttribute(
                                'path') + sysFrameworksNode.getAttribute(
                                    'name')
                        ret = project.add_file_if_doesnt_exist(
                            path, None, 'SOURCE_ROOT', True, required, False,
                            target_name)

                        if project.modified:
                            project.save()

                    for child in SDK['operateLs']:
                        if child['name'] == 'RemoveValidArchs_arm64':
                            project.modify_validarchs()
                            if project.modified:
                                project.save()

                    generateDeveloperInfo(channel, SDK, usrSDKConfig, workDir,
                                          game)
                    generatePluginInfo(SDK, usrSDKConfig, workDir)

    if os.path.exists(workDir + '/supportPlugin.xml'):
        encode_operate.xmlEncode(workDir + '/supportPlugin.xml')
        project.add_file(workDir + '/supportPlugin.xml', None, 'SOURCE_ROOT',
                         True, False, False, target_name)
        if project.modified:
            project.save()
    if os.path.exists(workDir + '/developerInfo.xml'):
        encode_operate.xmlEncode(workDir + '/developerInfo.xml')
        project.add_file(workDir + '/developerInfo.xml', None, 'SOURCE_ROOT',
                         True, False, False, target_name)
        if project.modified:
            project.save()
        taskManager.shareInstance().notify(idChannel, 70)
    if ipaPackage != 'True':
        taskManager.shareInstance().notify(idChannel, 100)
        return
    xcodeDir = workDir + '/' + ConfigParse.shareInstance().getProjXcode(
    ) + '/../'
    xcodeDir = os.path.realpath(xcodeDir)
    print 'XcodeDir ' + xcodeDir
    #change dictionary first,then run build command
    os.chdir(xcodeDir)
    mode = 0
    if useSDK.find('simulator') == -1:
        mode = 1
    cmd = None
    projectFileName = ConfigParse.shareInstance().getProjXcode().replace(
        '/', '')
    if mode == 0:
        cmd = 'xcodebuild ' + useSDK + ' -target ' + target_name + ' -arch i386 >xcodebuild.txt'
    else:
        #clean project and target
        cmd = 'xcodebuild clean ' + useSDK + ' -project ' + projectFileName + ' -target ' + target_name
        ret = file_operate.execFormatCmd(cmd)
        #don't build. use archieve
        cmd = 'xcodebuild ' + useSDK + ' -target ' + target_name + '>xcodebuild.txt'
        #cmd = 'xcodebuild archive -scheme ' + target_name + '  -target ' + target_name + ' -archivePath ' + target_name + '.xcarchive >xcodearchive.txt'

    ret = file_operate.execFormatCmd(cmd)
    buildFile = workDir + '/xcodebuild.txt'
    if not os.path.exists(buildFile):
        print 'file not exists'
    else:
        file_object = open(buildFile)
        try:
            buildText = file_object.read()
            print buildText.find('BUILD SUCCEEDED')
            if buildText.find('BUILD SUCCEEDED') < 0:
                print 'BUILD FAILED!'
                error_operate.error(200)
                return
        finally:
            file_object.close()

    # ret = file_operate.execFormatCmd(cmd)
    # buildFile = workDir + '/xcodearchive.txt'
    # if not os.path.exists(buildFile):
    #     print 'file not exists'
    # else:
    #     file_object = open(buildFile)
    #     try:
    #         buildText = file_object.read()
    #         print buildText.find('** ARCHIVE SUCCEEDED **')
    #         if buildText.find('** ARCHIVE SUCCEEDED **') < 0:
    #             print 'ARCHIVE FAILED!'
    #             error_operate.error(200)
    #             return
    #     finally:
    #         file_object.close()

    appDir = None
    if mode == 0:
        appDir = project_config + '-iphonesimulator/'
    else:
        appDir = project_config + '-iphoneos/'
    ipaName = target_name + '_' + channelName + '_' + versionName + '.ipa'
    #use xcodebuild exportArchieve export ipa.this code don't contain Symbols.
    cmd = 'xcrun -sdk iphoneos PackageApplication -v ' + '"' + xcodeDir + '/build/' + appDir + project_name + '.app" -o "' + outputDir + '/' + ipaName + '"'
    #cmd = 'xcodebuild -exportArchive -archivePath ' + target_name + '.xcarchive -exportPath "' + xcodeDir + '" -exportFormat ipa >exportarchieve.txt'
    ret = file_operate.execFormatCmd(cmd)
    taskManager.shareInstance().notify(idChannel, 100)