高效更新源码中的GMS包
# !/usr/bin/python
#coding=utf-8
# 自动替换 google apk文件
# 使用方法:
# linux环境:执行以下命令
# python
#
import os
import shutil
import sys
#手机中更新的google app包名 data/app
replace_dir = [
'-1',
'-1',
'-1',
'-1',
'-1',
'-1',
'-1',
'-1',
'-1',
'-1',
'-1',
'-1',
'-1',
'-1',
'-1',
'-1',
'-1',
'-1',
'-1',
'-1',
]
#google/apps目录对应的apk dir
target_dir = [
'PlusOne',
'Duo',
'Velvet',
'YouTube',
'Hangouts',
'CalendarGoogle',
'Messenger',
'EditorsDocs',
'Photos',
'Books',
'Gmail2',
'Drive',
'LatinImeGoogle',
'Music2',
'GoogleTTS',
'Chrome',
'Phonesky',
'Maps',
'Videos',
'GmsCore'
]
#
#google/apps目录对应的apk dir/对应的apk文件名
target_apk_name = [
'PlusOne_arm_xhdpi.apk',
'Duo_arm_xhdpi.apk',
'Velvet_arm_xhdpi.apk',
'YouTube_arm_xhdpi.apk',
'Hangouts_arm_xhdpi.apk',
'',
'Messenger_arm_xhdpi.apk',
'EditorsDocs_arm_xhdpi.apk',
'Photos_arm_xhdpi.apk',
'',
'Gmail2_xhdpi.apk',
'Drive_arm_xhdpi.apk',
'LatinImeGoogle_arm.apk',
'',
'GoogleTTS_arm.apk',
'Chrome_arm.apk',
'',
'Maps_arm_xhdpi.apk',
'Videos_arm.apk',
'GmsCore_arm_xhdpi.apk'
]
#定义数组类型
replace_apk_path=[]
target_apk_path=[]
#设置初始路径(写死)
#Android源码中的google app路径
apk_target_dir="vendor/google/apps"
#手机下载的google应用导出到电脑上的路径
apk_replace_dir = "/home/work/download/app/"
def search_file(path):#, filename, newpath)
queue = []
(path);
while len(queue) > 0:
tmp = (0)
if ((tmp)):#如果该路径是文件夹
for item in (tmp):#遍历该路径中文件和文件夹
((tmp, item))#将所得路径加入队列queue
elif ((tmp)):#如果该路径是文件
name = (tmp) # 获取文件名
dirname = (tmp) # 获取文件目录
full_path = (dirname, name) # 将文件名与文件目录连接起来,形成完整路径
if (name)[1]== '.apk':
for x in range(0,len(replace_dir)):
if dirname == apk_replace_dir+replace_dir[x]:
print("需要替换的目录:"+dirname)
print(name)
google_path = (apk_target_dir,target_dir[x])
if (google_path):
print("Google的目录:"+google_path)
print(apk_target_dir+"/"+target_dir[x]+"/"+target_apk_name[x])
replace_apk_path.append(full_path)
target_apk_path.append(apk_target_dir+"/"+target_dir[x]+"/"+target_apk_name[x])
else:
print("not find "+google_path)
break
else:
print(dirname+" not replace ..")
# des_path = newpath+'/'+path+'_'+name #目标路径,将该文件夹信息添加进最后的文件名中
# if filename in name:#匹配符合条件的文件,也可用if((filename)!=-1):
# (full_path, des_path)#移动文件到目标路径(移动+重命名)
print("************************************************************")
print("开始执行替换脚本")
print("搜索替换文件 :"+apk_replace_dir)
search_file(apk_replace_dir)
print("搜索完成\n")
print("list \n")
for x in xrange(1,len(replace_apk_path)):
print(replace_apk_path[x])
print(target_apk_path[x])
print("开始替换文件\n")
for x in range(0,len(replace_apk_path)):
log = '[ apk '+bytes(x)+']'+'replacing '+replace_apk_path[x]+' to '+target_apk_path[x]
print(log)
print("\n")
(target_apk_path[x])
(replace_apk_path[x],target_apk_path[x])
print("success!")