#coding=utf-8
importsysimportosimportsubprocessimporttimedefget_sdk_infos(sdk_path):
cmd= "lipo -info %s" %sdk_path
cmpsplit=cmd.split()
output=subprocess.check_output(cmpsplit)
result=set(output.split())
architectures=[];
thin_sdks=[];for d inresult:if('armv7' in d or 'armv7s' in d or 'arm64' in d or 'x86_64' in d or 'i386' ind):
architectures.append(d);
output_path=create_arch_framework(sdk_path, d);if ('armv7' in d or 'armv7s' in d or 'arm64' ind):
thin_sdks.append(output_path);
str= ' '.join(thin_sdks)
created_file_path=sdk_path
cmd= u"lipo -create %s -output %s" %(str, created_file_path)
cmpsplit=cmd.split()try:
output=subprocess.check_output(cmpsplit)exceptsubprocess.CalledProcessError, e:print '%s error:%s!' %(cmd, e)
time.sleep(2)for file_temp inthin_sdks:if(os.path.exists(file_temp)):pass
pass
defget_file_path(sdk_path,rename_name):
root_path=os.path.dirname(sdk_path);
output_sdk_path= ''
if(os.path.isfile(sdk_path)):
array_result= sdk_path.split('/');
framework_path= array_result[len(array_result)-2];
framework_sdk_path=array_result[len(array_result)-1];if '.a' inframework_sdk_path:
temp_sdk_path=os.path.split(sdk_path)
file_name= temp_sdk_path[1];
file_name_ext= file_name.split('.');
file_name= file_name_ext[0] + '_%s' %(rename_name);
new_file_name= '%s/%s.%s' % (root_path, file_name, file_name_ext[1]);
output_sdk_path=new_file_name;else:
framework_root_path=os.path.dirname(sdk_path);
output_sdk_path=os.path.join(framework_root_path,'%s_%s' %(framework_sdk_path,rename_name));pass
returnoutput_sdk_path;defcreate_arch_framework(sdk_path,arch):
output_sdk_path=get_file_path(sdk_path,arch);
cmd= u"lipo %s -thin %s -output %s" %(sdk_path,arch,output_sdk_path)
cmpsplit=cmd.split()try:
output=subprocess.check_output(cmpsplit)exceptsubprocess.CalledProcessError, e:print '%s error:%s!' %(cmd,e)pass
returnoutput_sdk_path;if __name__ == '__main__':
paras_len=len(sys.argv)#检查执行命令是否有效,举例: python SDK_Thinning.py /Users/您的电脑用户名/Desktop/python/AMap_iOS_SDK_ALL/MAMapKit.framework/MAMapKit
if paras_len>=1:
source_file_path= sys.argv[1]#获取源文件路径参数,源文件类型为.a或者.framework静态库文件
print 'source_file_path:',source_file_path
result_file_path=get_sdk_infos(source_file_path);print 'success!'
else:print 'error!'