123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131 |
- # -*- coding:utf-8 -*-
- from print_log import printlog
- import package_utils, path_utils, file_utils, update_channnel_sdk_v2
- import os
- from xml.etree import ElementTree as ET
- from xml.etree.ElementTree import SubElement
- androidNS = 'http://schemas.android.com/apk/res/android'
- scheme = '{' + androidNS + '}scheme'
- name_key = '{' + androidNS + '}name'
- def start_merge(apk_decompile_tmp_dir, config):
- share_sdk_path = os.path.join(path_utils.get_sdk_channel_path('share_sdk'), 'pretreatment_project')
- printlog('复制分享SDK资源:%s' % share_sdk_path)
- package_utils.remove_same_values_res(apk_decompile_tmp_dir, share_sdk_path)
- pre_res_dir = os.path.join(share_sdk_path, "res")
- update_channnel_sdk_v2.copy_res_to_apk(pre_res_dir, os.path.join(apk_decompile_tmp_dir, 'res'))
- # 拷贝assets
- printlog('copy assets...')
- sdk_assets_path = os.path.join(share_sdk_path, 'assets')
- temp_assets_path = os.path.join(apk_decompile_tmp_dir, 'assets')
- # 拷贝smali_classes2
- printlog('copy smali_classes2...')
- sdk_smali_path = os.path.join(share_sdk_path, 'smali_classes2')
- temp_smali_path = os.path.join(apk_decompile_tmp_dir, 'smali_classes2')
- if os.path.exists(sdk_smali_path):
- ret = file_utils.copy_file_all_dir(sdk_smali_path, temp_smali_path)
- if ret:
- return ret
- if os.path.exists(sdk_assets_path):
- ret = file_utils.copy_file_all_dir(sdk_assets_path, temp_assets_path)
- if ret:
- return ret
- # 拷贝jniLib
- printlog('copy lib...')
- temp_jni_path = os.path.join(apk_decompile_tmp_dir, 'lib')
- sdk_jni_path = os.path.join(share_sdk_path, 'jniLibs')
- if not os.path.exists(temp_jni_path):
- printlog('There is no need to merge lib .[temp_jni_path:]:%s' % temp_jni_path)
- return 0
- abiFilters = []
- if os.path.exists(temp_jni_path):
- for abi in os.listdir(temp_jni_path):
- printlog('append : ' + abi)
- abiFilters.append(abi)
- else:
- abiFilters = ['armeabi-v7a']
- if os.path.exists(sdk_jni_path):
- ret = file_utils.copy_file_all_dir(
- sdk_jni_path, temp_jni_path, False, abiFilters)
- if ret:
- return ret
- printlog('合并Androidmanifest.xml 文件')
- sdk_base_xml = os.path.join(share_sdk_path, "SDKManifest.xml")
- apk_decom_dir_manifest_xml = os.path.join(apk_decompile_tmp_dir, 'AndroidManifest.xml')
- ret = package_utils.mergeManifest(apk_decom_dir_manifest_xml, sdk_base_xml)
- if ret:
- return ret
- temp_yyxx_share_cfg_path = os.path.join(apk_decompile_tmp_dir, 'assets', 'yyxx_game', 'yyxx_share_cfg.properties')
- weibo_key = config['WEIBO_SHARE']
- if weibo_key:
- for key in weibo_key.keys():
- file_utils.replace_assets_param(temp_yyxx_share_cfg_path, key,
- weibo_key[key])
- qq_key = config['QQ_SHARE']
- if weibo_key:
- for key in qq_key.keys():
- file_utils.replace_assets_param(temp_yyxx_share_cfg_path, key,
- qq_key[key])
- if key == 'QQ_APP_KY':
- repalce_qq_appkey_to_manifest(apk_decompile_tmp_dir, qq_key[key])
- wechat_key = config['WECHAT_SHARE']
- if weibo_key:
- for key in wechat_key.keys():
- file_utils.replace_assets_param(temp_yyxx_share_cfg_path, key,
- wechat_key[key])
- pass
- def repalce_qq_appkey_to_manifest(apk_decompile_tmp_dir, appkey):
- manifest = os.path.join(apk_decompile_tmp_dir, 'AndroidManifest.xml')
- ET.register_namespace('android', androidNS)
- tree = ET.parse(manifest)
- root = tree.getroot()
- appNode = root.find('application')
- if appNode is None:
- return 1
- activityNodeList = appNode.findall('activity')
- if activityNodeList is None:
- return 1
- for activityNode in activityNodeList:
- activityName = activityNode.get(name_key)
- if activityName == 'com.tencent.tauth.AuthActivity':
- intentFilters = activityNode.findall('intent-filter')
- if intentFilters is not None and len(intentFilters) > 0:
- for intentNode in intentFilters:
- dataNode = intentNode.find('data')
- intentNode.remove(dataNode)
- dataNode = SubElement(intentNode, 'data')
- dataNode.set(scheme, 'tencent' + appkey)
- tree.write(manifest, 'UTF-8')
|