静态库架构合并,静态库抽离架构,静态库去除.o文件脚本

新建父文件夹,下面新建文件夹os里面放libPingAn.a的真机包,simulator里面放libPingAn.a的模拟器包,shell文件命名release。如果改名,脚本文件也要改名。
shell文件内容:

#!/bin/bash
lipo -extract_family armv7 -output os/libPingAn_arm.a os/libPingAn.a
lipo os/libPingAn.a -thin arm64 -output os/libPingAn_arm64.a
lipo -extract_family i386 -output simulator/libPingAn_i386.a simulator/libPingAn.a
lipo -extract_family x86_64 -output simulator/libPingAn_x86_64.a simulator/libPingAn.a
echo "extract libs finish."
wait

mkdir arm64 arm7 x86_64 i386

cp os/libPingAn_arm.a arm7/libPingAn_arm7.a
cp os/libPingAn_arm64.a arm64/libPingAn_arm64.a
cp simulator/libPingAn_x86_64.a x86_64/libPingAn_x86_64.a
cp simulator/libPingAn_i386.a i386/libPingAn_i386.a
echo "copy file OK."
wait

cd arm64/
ar -x libPingAn_arm64.a
echo "unpack lib...1/4"
wait
rm lib*.a

cd ../arm7
ar -x libPingAn_arm7.a
echo "unpack lib...2/4"
wait
rm lib*.a

cd ../x86_64/
ar -x lib*.a
echo "unpack lib...3/4"
wait
rm lib*.a

cd ../i386/
ar -x lib*.a
echo "unpack lib...4/4"
wait
rm lib*.a

cd ..

echo "remove something unused..."

rm -rf arm7/ASI*.o
rm -rf arm7/Reachability.o
rm -rf arm7/EGORefreshTableHeaderView.o
rm -rf arm7/MBProgressHUD.o
rm -rf arm7/KxMenu.o
rm -rf arm7/MGSwipeTableCell.o
libtool -static -o libPingAn-armv7.a arm7/*.o
echo "packing lib...1/4"
wait

rm -rf arm64/ASI*.o
rm -rf arm64/Reachability.o
rm -rf arm64/EGORefreshTableHeaderView.o
rm -rf arm64/MBProgressHUD.o
rm -rf arm64/KxMenu.o
rm -rf arm64/MGSwipeTableCell.o
libtool -static -o libPingAn-arm64.a arm64/*.o
echo "packing lib...2/4"
wait

rm -rf x86_64/ASI*.o
rm -rf x86_64/Reachability.o
rm -rf x86_64/EGORefreshTableHeaderView.o
rm -rf x86_64/MBProgressHUD.o
rm -rf x86_64/KxMenu.o
rm -rf x86_64/MGSwipeTableCell.o
libtool -static -o libPingAn-x86_64.a x86_64/*.o
echo "packing lib...3/4"
wait

rm -rf i386/ASI*.o
rm -rf i386/Reachability.o
rm -rf i386/EGORefreshTableHeaderView.o
rm -rf i386/MBProgressHUD.o
rm -rf i386/KxMenu.o
rm -rf i386/MGSwipeTableCell.o
libtool -static -o libPingAn-i386.a i386/*.o
echo "packing lib...4/4"
wait

lipo -create -output libPingAn.a libPingAn-armv7.a libPingAn-arm64.a libPingAn-x86_64.a libPingAn-i386.a
echo "creat final library success!"

echo "clear..."
rm -rf libPingAn-*.a
rm -rf x86_64/
rm -rf i386/
rm -rf arm7/
rm -rf arm64/
rm -rf os/libPingAn_*.a
rm -rf simulator/libPingAn_*.a
echo "done!!"

# print('remove i386.')
# lipo -remove i386 libPingAn.a -o libPingAn.a

# print('查看arm7中包含的.o文件')
# ar -t libPingAn_arm7

arm64等文件夹里面是静态库说包含的.o文件,因项目需要里面,去掉了一些三方的.o文件,可适当去除。
使用:
终端 cd 到父目录,ls看到release.sh,./启动脚本。
仅供参考,实际使用中,自己修改即可。


执行命令截图.png

查询支持哪些指令集:
lipo -info /user/pingan.a

附一:
各架构对应机型:
arm64e:iPhone XS\XR\XS Max
arm64:iPhone6s | iphone6s plus|iPhone6| iPhone6 plus|iPhone5S | iPad Air| iPad mini2(iPad mini with Retina Display)
armv7s:iPhone5|iPhone5C|iPad4(iPad with Retina Display)
armv7:iPhone4|iPhone4S|iPad|iPad2|iPad3(The New iPad)|iPad mini|iPod Touch 3G|iPod Touch4
i386 :针对intel通用微处理器32位处理器,模拟器32位处理器
x86_64 :针对x86架构的64位处理器,模拟器64位处理器

附二:(基于之前的改的python版本,shell更简单一些。留着看吧)
python os.system('')可直接调用shell语句,写着练手的。

#!/usr/bin/env python
#coding=utf-8
import os
import shutil
# 真机32位处理器需要armv7,或者armv7s架构
os.system('lipo -extract_family armv7 -output os/libPingAn_arm.a os/libPingAn.a')
# 真机64位处理器需要arm64架构
os.system('lipo os/libPingAn.a -thin arm64 -output os/libPingAn_arm64.a')
# 模拟器32位处理器测试需要i386架构
os.system('lipo -extract_family i386 -output simulator/libPingAn_i386.a simulator/libPingAn.a')
# 模拟器64位处理器测试需要x86_64架构
os.system('lipo -extract_family x86_64 -output simulator/libPingAn_x86_64.a simulator/libPingAn.a')
print('extract libs finish.')
os.wait
print('create Dir.')

path = os.getcwd()
os.mkdir(path + '/arm64')
os.mkdir(path + '/arm7')
os.mkdir(path + '/x86_64')
os.mkdir(path + '/i386')

oldFile = os.path.join(path + '/os','libPingAn_arm.a')
newFile = os.path.join(path+'/arm7','libPingAn_arm7.a')
shutil.copy(oldFile,newFile)

oldFile = os.path.join(path + '/os','libPingAn_arm64.a')
newFile = os.path.join(path+'/arm64','libPingAn_arm64.a')
shutil.copy(oldFile,newFile)

oldFile = os.path.join(path + '/simulator','libPingAn_x86_64.a')
newFile = os.path.join(path+'/x86_64','libPingAn_x86_64.a')
shutil.copy(oldFile,newFile)

oldFile = os.path.join(path + '/simulator','libPingAn_i386.a')
newFile = os.path.join(path+'/i386','libPingAn_i386.a')
shutil.copy(oldFile,newFile)
# os.system('cp os/libPingAn_arm.a arm7/libPingAn_arm7.a')
# os.system('cp os/libPingAn_arm64.a arm64/libPingAn_arm64.a')
# os.system('cp simulator/libPingAn_x86_64.a x86_64/libPingAn_x86_64.a')
# os.system('cp simulator/libPingAn_i386.a i386/libPingAn_i386.a')
print('copy file OK.')
os.wait

os.chdir(path + '/arm64')
os.system('ar -x libPingAn_arm64.a')
print('unpack lib...1/4.')
os.wait
os.system('rm lib*.a')

os.chdir(path + '/arm7')
os.system('ar -x libPingAn_arm7.a')
print('unpack lib...2/4.')
os.wait
os.system('rm lib*.a')

os.chdir(path + '/x86_64')
os.system('ar -x lib*.a')
print('unpack lib...3/4.')
os.wait
os.system('rm lib*.a')

os.chdir(path + '/i386')
os.system('ar -x lib*.a')
print('unpack lib...4/4.')
os.wait
os.system('rm lib*.a')

os.chdir(path)
print('remove something unused...')


os.system('rm -rf arm7/ASI*.o')
os.system('rm -rf arm7/Reachability.o')
os.system('rm -rf arm7/EGORefreshTableHeaderView.o')
os.system('rm -rf arm7/MBProgressHUD.o')
os.system('rm -rf arm7/KxMenu.o')
os.system('rm -rf arm7/MGSwipeTableCell.o')
os.system('libtool -static -o libPingAn-armv7.a arm7/*.o')
print('packing lib...1/4')
os.wait

os.system('rm -rf arm64/ASI*.o')
os.system('rm -rf arm64/Reachability.o')
os.system('rm -rf arm64/EGORefreshTableHeaderView.o')
os.system('rm -rf arm64/MBProgressHUD.o')
os.system('rm -rf arm64/KxMenu.o')
os.system('rm -rf arm64/MGSwipeTableCell.o')
os.system('libtool -static -o libPingAn-arm64.a arm64/*.o')
print('packing lib...2/4')
os.wait

os.system('rm -rf x86_64/ASI*.o')
os.system('rm -rf x86_64/Reachability.o')
os.system('rm -rf x86_64/EGORefreshTableHeaderView.o')
os.system('rm -rf x86_64/MBProgressHUD.o')
os.system('rm -rf x86_64/KxMenu.o')
os.system('rm -rf x86_64/MGSwipeTableCell.o')
os.system('libtool -static -o libPingAn-x86_64.a x86_64/*.o')
print('packing lib...3/4')
os.system('wait')

os.system('rm -rf i386/ASI*.o')
os.system('rm -rf i386/Reachability.o')
os.system('rm -rf i386/EGORefreshTableHeaderView.o')
os.system('rm -rf i386/MBProgressHUD.o')
os.system('rm -rf i386/KxMenu.o')
os.system('rm -rf i386/MGSwipeTableCell.o')
os.system('libtool -static -o libPingAn-i386.a i386/*.o')
print('packing lib...4/4')
os.wait

os.system('lipo -create -output libPingAn.a libPingAn-armv7.a libPingAn-arm64.a libPingAn-x86_64.a libPingAn-i386.a')
print('creat final library success!')

print('clear...')
os.system('rm -rf libPingAn-*.a')
os.system('rm -rf x86_64/')
os.system('rm -rf i386/')
os.system('rm -rf arm7/')
os.system('rm -rf arm64/')
os.system('rm -rf os/libPingAn_*.a')
os.system('rm -rf simulator/libPingAn_*.a')
print('success!!')

# print('remove i386.')
# os.system('lipo -remove i386 libPingAn.a -o libPingAn.a')
# print('查看arm7中包含的.o文件')
# os.system('ar -t libPingAn_arm7')

你可能感兴趣的:(静态库架构合并,静态库抽离架构,静态库去除.o文件脚本)