Exemplo n.º 1
0
    def decompile(self):
        log_utils.getLogger().info('start decompiling...')

        taskLogDir = os.path.join(self.taskWorkDir, 'log')
        if not os.path.exists(taskLogDir):
            os.makedirs(taskLogDir)

        logFileName = os.path.join(taskLogDir, 'repack.log')
        log_utils.changeLoggerFileHandler(logFileName)

        if not os.path.exists(self.apkFile):
            raise PackException(
                pack_exception.SOURCE_APK_NOT_EXIST,
                'source apk file %s does not exist' % self.apkFile)

        tmpApkSource = self.taskWorkDir + '/temp.apk'
        my_utils.copyFile(self.apkFile, tmpApkSource)

        log_utils.getLogger().info('decompiling apk ... ')
        #apk反编译
        ret = cmd_tools.decompileApk(tmpApkSource, self.decompileDir,
                                     self.tmpApkToolPath)
        if ret:
            raise PackException(pack_exception.DECOMPLE_APK_FAILED,
                                'decompile apk %s failed' % tmpApkSource)
Exemplo n.º 2
0
    def pack(self):
        try:
            log_utils.getLogger().info('generating new r file ... ')
            #重新生成R文件

            ret = cmd_tools.produceNewRFile(self._packageName,
                                            self.decompileDir)
            if ret:
                raise PackException(pack_exception.PRODUCE_NEW_R_FILE_FAILED,
                                    'produce new r file failed')

            #重新编译成apk
            tempRecompileApkDir = self.taskWorkDir + '/tempRecompileApk'
            tempRecompileApk = '%s/nosig.apk' % (tempRecompileApkDir)
            tempSignedApkName = '%s/_sig.apk' % (tempRecompileApkDir)

            log_utils.getLogger().info(
                'recompiling apk ... tempRecompileApk = ' + tempRecompileApk)
            ret = cmd_tools.recompileApk(self.decompileDir, tempRecompileApk,
                                         self.tmpApkToolPath)
            if ret:
                raise PackException(pack_exception.RECOMPILE_APK_FAILED,
                                    'recompile apk failed')

            # self.outputName是 autotest_xxx.apk
            self.doPackWithoutChannelSymbol(tempRecompileApk,
                                            tempSignedApkName, self.outputDir,
                                            self.outputName)

            #测试桩重打包
            import env
            testbundle_apkFile = os.path.join(env.SUPPORT_DIR,
                                              self._projectShorName,
                                              'testbundle', 'TestBundle.apk')
            #testbundle_apkFile = os.path.join(env.GOD_TOOL_DIR, 'TestBundle_base.apk')
            if not os.path.exists(testbundle_apkFile):
                raise PackException(
                    pack_exception.SOURCE_APK_NOT_EXIST,
                    'testbundle_base apk file %s does not exist' %
                    testbundle_apkFile)

            # 拷贝TestBundle.apk 到  工作目录下/testbundle_temp.apk
            tmpTestBundleApk = self.taskWorkDir + '/testbundle_temp.apk'
            my_utils.copyFile(testbundle_apkFile, tmpTestBundleApk)

            testbundle_decompileDir = self.taskWorkDir + '/testbundle_decompile'
            testbundle_tmpApkToolPath = os.path.join(self.taskWorkDir,
                                                     'testbundle_apktooltmp')
            log_utils.getLogger().info('decompiling testbundle apk ... ')

            #测试桩反编译 到   工作目录下/testbundle_decompile
            ret = cmd_tools.decompileApk(tmpTestBundleApk,
                                         testbundle_decompileDir,
                                         testbundle_tmpApkToolPath)
            if ret:
                raise PackException(
                    pack_exception.DECOMPLE_APK_FAILED,
                    'decompile testbundle apk %s failed' % tmpTestBundleApk)

            testbundle_packageName = "com.boyaa.application.testbundle"
            # 修改manifest.xml
            self.repackTestBundleForMatch(self.sdksRootDir,
                                          testbundle_decompileDir,
                                          self._packageName)

            log_utils.getLogger().info(
                'generating new r file for testbundle... ')
            #重新生成测试桩的R文件
            ret = cmd_tools.produceNewRFile(testbundle_packageName,
                                            testbundle_decompileDir)
            if ret:
                raise PackException(
                    pack_exception.PRODUCE_NEW_R_FILE_FAILED,
                    'produce new r file for testbundle failed')

            #重新编译测试桩apk
            testbundle_tempRecompileApkDir = self.taskWorkDir + '/testbundle_tempRecompileApk'
            testbundle_tempRecompileApk = '%s/testbundle_nosig.apk' % (
                testbundle_tempRecompileApkDir)
            testbundle_tempSignedApkName = '%s/testbundle_sig.apk' % (
                testbundle_tempRecompileApkDir)

            log_utils.getLogger().info(
                'recompiling apk ... tempRecompileApk = ' +
                testbundle_tempRecompileApk)
            ret = cmd_tools.recompileApk(testbundle_decompileDir,
                                         testbundle_tempRecompileApk,
                                         testbundle_tmpApkToolPath)
            if ret:
                raise PackException(pack_exception.RECOMPILE_APK_FAILED,
                                    'recompile test bundle apk failed')

            self.doPackWithoutChannelSymbol(
                testbundle_tempRecompileApk, testbundle_tempSignedApkName,
                os.path.join(self.outputDir, 'testbundle'), "testbundle.apk")

            #log_utils.getLogger().info('doPack: =============================================success=============================================' + StreamHandler.terminator)

        except PackException as pe:
            log_utils.getLogger().error(pe)
            #log_utils.getLogger().info('doPack: =============================================Failed=============================================' + StreamHandler.terminator)
            return