def test_ApkConfigUpdater(): apk_path = r'D:\version_build\pytxxy\output\pytxxy-debug-pytxxyV1.2.0.Build150304-20150415.apk' apk_items = apk_util.get_apk_info(apk_path) dst_path = r'D:\version_build\pytxxy\config\template\upgrade.json' updater = ApkConfigUpdater(dst_path) updater._update_json_file(apk_path, apk_items)
def main(args): apk_path = os.path.abspath(args.src) apk_items = apk_util.get_apk_info(apk_path) # print(apk_items) str_format = 'package: {0}, name: {1}, version: {2}, verCode: {3}' str_info = str_format.format(apk_items['name'], apk_items['label'], apk_items['versionName'], apk_items['versionCode']) print(str_info)
def build(self): print('building apk begin ...') # 获取apk名称 apk_name = os.path.basename(self.main_prj_path) apk_out_path = self.main_prj_path + '/build/outputs/apk/' # build_type = self.info[BuilderLabel.TYPE_FLAG] # 默认名称形式 # apk_path = '{}{}-{}.apk'.format(apk_out_path, apk_name, build_type) # 自定义名称形式 apk_path = os.path.join(apk_out_path, self._get_output_relative_path(), self.info[BuilderLabel.OUTPUT_NAME_FLAG]) apk_path = os.path.normpath(apk_path) # 先把现有的apk文件直接删除 if os.path.exists(apk_path) and os.path.isfile(apk_path): os.remove(apk_path) cmd_str = self.get_build_cmd() make_apk_with_gradle(self.main_prj_path, cmd_str) src_file = apk_path print('source apk path: {}'.format(src_file)) if os.path.exists(src_file): apk_items = apk_util.get_apk_info(src_file) actual_ver_name = self.get_main_ver_name(apk_items['versionName']) if actual_ver_name != self.info[BuilderLabel.VER_NAME_FLAG]: info = 'set version name is {}, but actual is {}!'.format(self.info[BuilderLabel.VER_NAME_FLAG], actual_ver_name) raise Exception(info) if apk_items['versionCode'] != str(self.info[BuilderLabel.VER_CODE_FLAG]): info = 'set version code is {}, but actual is {}!'.format(self.info[BuilderLabel.VER_CODE_FLAG], apk_items['versionCode']) raise Exception(info) dst_file = self.info[BuilderLabel.OUTPUT_DIRECTORY_FLAG] + os.sep + self.info[ BuilderLabel.OUTPUT_NAME_FLAG] file_util.replace_file(src_file, dst_file) print('built the apk {}.'.format(dst_file)) else: print('build {} failed!'.format(apk_name))
def build(self, chan_id, mode=apk_builder.RELEASE_MODE): self._update_chan_info(chan_id) # update_str = 'updated version info with chan_id "{0}".'.format(chan_id) # print(update_str) print('building apk begin ...') # 获取apk名称 apk_name = os.path.basename(self.prj_path) apk_out_path = self.prj_path + '/build/outputs/apk/' apk_path = '{}{}-{}.apk'.format(apk_out_path, apk_name, apk_builder.MODE_MAP[mode]) apk_path = os.sep.join(re.split('[\\\/]+', apk_path)) # 先把现有的apk文件直接删除 if os.path.exists(apk_path) and os.path.isfile(apk_path): os.remove(apk_path) apk_builder.make_apk(self.prj_path, mode) # mode_flag = apk_builder.MODE_MAP[mode] # src_file = self.prj_path + os.sep + 'bin' + os.sep + apk_name + '-' + mode_flag + '.apk' src_file = apk_path if os.path.exists(src_file): apk_items = apk.get_apk_info(src_file) if apk_items['versionName'] != self.info[ProjectBuilder.VER_NAME_FLAG]: info = 'set version name is {}, but actual is {}!'.format(self.info[ProjectBuilder.VER_NAME_FLAG], apk_items['versionName']) raise Exception(info) if apk_items['versionCode'] != self.info[ProjectBuilder.VER_CODE_FLAG]: info = 'set version code is {}, but actual is {}!'.format(self.info[ProjectBuilder.VER_CODE_FLAG], apk_items['versionCode']) raise Exception(info) dst_file = self.info[ProjectBuilder.OUTPUT_DIRECTORY_FLAG] + os.sep + self.info[ProjectBuilder.OUTPUT_NAME_FLAG] myfile.replace_file(src_file, dst_file) print('built the apk {}.'.format(dst_file)) else: print('build {} failed!'.format(apk_name))
def build(self, chan_id, mode=apk_builder.RELEASE_MODE): self._update_chan_info(chan_id) # update_str = 'updated version info with chan_id "{0}".'.format(chan_id) # print(update_str) print('building apk begin ...') # 获取apk名称 apk_name = os.path.basename(self.prj_path) apk_out_path = self.prj_path + '/build/outputs/apk/' apk_path = '{}{}-{}.apk'.format(apk_out_path, apk_name, apk_builder.MODE_MAP[mode]) apk_path = os.sep.join(re.split('[\\\/]+', apk_path)) # 先把现有的apk文件直接删除 if os.path.exists(apk_path) and os.path.isfile(apk_path): os.remove(apk_path) cmd_str = self.get_build_cmd() make_apk_with_gradle(self.prj_path, cmd_str) src_file = apk_path if os.path.exists(src_file): apk_items = apk_util.get_apk_info(src_file) if apk_items['versionName'] != self.info[ ProjectBuilder.VER_NAME_FLAG]: info = 'set version name is {}, but actual is {}!'.format( self.info[ProjectBuilder.VER_NAME_FLAG], apk_items['versionName']) raise Exception(info) if apk_items['versionCode'] != self.info[ ProjectBuilder.VER_CODE_FLAG]: info = 'set version code is {}, but actual is {}!'.format( self.info[ProjectBuilder.VER_CODE_FLAG], apk_items['versionCode']) raise Exception(info) dst_file = self.info[ ProjectBuilder.OUTPUT_DIRECTORY_FLAG] + os.sep + self.info[ ProjectBuilder.OUTPUT_NAME_FLAG] file_util.replace_file(src_file, dst_file) # 拷贝编译生成的class文件,便于服务器生成代码覆盖率文件 if ProjectBuilder.BUILD_CLASS_FLAG in self.info and len( self.info[ProjectBuilder.BUILD_CLASS_FLAG]) >= 2: src_class_path = self.prj_path + os.sep + self.info[ ProjectBuilder.BUILD_CLASS_FLAG][ ProjectBuilder.SRC_PATH_FLAG] src_class_path = file_util.normalpath(src_class_path) dst_class_relative_path = self.info[ ProjectBuilder.BUILD_CLASS_FLAG][ ProjectBuilder.DST_PATH_FLAG] dst_class_zip_path = self.info[ ProjectBuilder. OUTPUT_DIRECTORY_FLAG] + os.sep + 'classes.zip' # dst_class_path = self.info[ProjectBuilder.OUTPUT_DIRECTORY_FLAG] + os.sep + dst_class_relative_path # dst_class_path = file_util.normalize_path(dst_class_path) # # if os.path.isdir(dst_class_path): # shutil.rmtree(dst_class_path) if os.path.isdir(src_class_path): # shutil.copytree(src_class_path, dst_class_path) rev_index = -len(dst_class_relative_path) zip_src_root = src_class_path[:rev_index] zip_util.zip_dir(src_class_path, dst_class_zip_path, zip_src_root) print('success zip {} to {}.'.format( dst_class_relative_path, dst_class_zip_path)) print('built the apk {}.'.format(dst_file)) else: print('build {} failed!'.format(apk_name))
def build(self): print('building apk begin ...') # 获取apk名称 apk_name = os.path.basename(self.main_prj_path) apk_out_path = self.main_prj_path + '/build/outputs/apk/' # 自定义名称形式 apk_path = os.path.join(apk_out_path, self._get_output_relative_path(), self.info[BuilderLabel.OUTPUT_NAME_FLAG]) apk_path = os.path.normpath(apk_path) # 先把现有的apk文件直接删除 if os.path.exists(apk_path) and os.path.isfile(apk_path): os.remove(apk_path) cmd_str = self.get_build_cmd() make_apk_with_gradle(self.main_prj_path, cmd_str) src_file = apk_path print('source apk path: {}'.format(src_file)) if os.path.exists(src_file): apk_items = apk.get_apk_info(src_file) actual_ver_name = self.get_main_ver_name(apk_items['versionName']) if actual_ver_name != self.info[BuilderLabel.VER_NAME_FLAG]: info = 'set version name is {}, but actual is {}!'.format( self.info[BuilderLabel.VER_NAME_FLAG], actual_ver_name) raise Exception(info) if apk_items['versionCode'] != str( self.info[BuilderLabel.VER_CODE_FLAG]): info = 'set version code is {}, but actual is {}!'.format( self.info[BuilderLabel.VER_CODE_FLAG], apk_items['versionCode']) raise Exception(info) dst_file = self.info[ BuilderLabel.OUTPUT_DIRECTORY_FLAG] + os.sep + self.info[ BuilderLabel.OUTPUT_NAME_FLAG] file_util.replace_file(src_file, dst_file) # 拷贝编译生成的class文件,便于服务器生成代码覆盖率文件 if BuilderLabel.BUILD_CLASS_FLAG in self.info and len( self.info[BuilderLabel.BUILD_CLASS_FLAG]) >= 2: src_class_path = self.main_prj_path + os.sep + self.info[ BuilderLabel.BUILD_CLASS_FLAG][BuilderLabel.SRC_PATH_FLAG] src_class_path = file_util.normalpath(src_class_path) dst_class_relative_path = self.info[ BuilderLabel.BUILD_CLASS_FLAG][BuilderLabel.DST_PATH_FLAG] dst_class_zip_path = self.info[ BuilderLabel. OUTPUT_DIRECTORY_FLAG] + os.sep + 'classes.zip' if os.path.isdir(src_class_path): # shutil.copytree(src_class_path, dst_class_path) rev_index = -len(dst_class_relative_path) zip_src_root = src_class_path[:rev_index] zip_util.zip_dir(src_class_path, dst_class_zip_path, zip_src_root) print('success zip {} to {}.'.format( dst_class_relative_path, dst_class_zip_path)) print('built the apk {}.'.format(dst_file)) else: print('build {} failed!'.format(apk_name))