美文网首页
Xcode脚本打.a包

Xcode脚本打.a包

作者: WeeverLu | 来源:发表于2018-05-07 10:33 被阅读105次
  1. 包大小优化
    打包的时候,注意Build是Debug还是Release环境。
    在Build Settings设置
  • 修改Deployment相关设置,根据Debug还是Release环境设置。
    1)、Deployment Postprocessing:设为YES,这样RELEASE模式下就可以去除符号缩减app的大小(默认NO)
    2)、Strip Debug Symbols During Copy:DEBUG下设为NO,RELEASE下设为YES;(默认NO)
  • 修改Optimization Level
    Optimization Level,设置Debug为Fastest,Smalest,Release为Fastest,Smalest
  1. 生成包
    点击左侧你的项目,在右边的TARGETS下面,新建一个target,然后切换到Build Phases - Run Script中,如果没Run Script,在左上角的+,添加New Run Script Phases,然后加入下面打包脚本,可以打钩Show environment variable in build log
  • 生成通用包
#生成通用包
UNIVERSAL_OUTPUTFOLDER=${BUILD_DIR}/${CONFIGURATION}-universal
LIB_NAME="libTest"
LIB_OUTPUT_NAME="libTest" #导出的包名称

#生成真机:注意要打包的target名称要对应
xcodebuild -target libTest ONLY_ACTIVE_ARCH=NO -configuration ${CONFIGURATION} -sdk iphoneos  
VALID_ARCHS='armv7 armv7s arm64' ARCHS='armv7 armv7s arm64' BUILD_DIR="${BUILD_DIR}" BUILD_ROOT="${BUILD_ROOT}"

#生成模拟器:注意要打包的target名称要对应
xcodebuild -target libTest -configuration ${CONFIGURATION} -sdk iphonesimulator 
ARCHS='i386 x86_64' VALID_ARCHS='i386 x86_64' BUILD_DIR="${BUILD_DIR}" BUILD_ROOT="${BUILD_ROOT}"

mkdir -p "${UNIVERSAL_OUTPUTFOLDER}"

#合并包
lipo -create -output "${UNIVERSAL_OUTPUTFOLDER}/${LIB_NAME}.a" "${BUILD_DIR}/${CONFIGURATION}-iphoneos/${LIB_NAME}.a" "${BUILD_DIR}/${CONFIGURATION}-iphonesimulator/${LIB_NAME}.a"

cd "${PROJECT_DIR}"

cd ..

#拷贝整个目录到新的保存位置
cp -R "${UNIVERSAL_OUTPUTFOLDER}/${LIB_NAME}.a" "YourFileName/lib/${LIB_NAME}.a"
  • 生成真机包(从生成通用包抽取)
#生成真机包
UNIVERSAL_OUTPUTFOLDER=${BUILD_DIR}/${CONFIGURATION}-universal
LIB_NAME="libTest"
LIB_OUTPUT_NAME="libTest_os" #导出的包名称

#生成真机:注意要打包的target名称要对应
xcodebuild -target libTest ONLY_ACTIVE_ARCH=NO -configuration ${CONFIGURATION} -sdk iphoneos  VALID_ARCHS='armv7 armv7s arm64' ARCHS='armv7 armv7s arm64' BUILD_DIR="${BUILD_DIR}" BUILD_ROOT="${BUILD_ROOT}"

mkdir -p "${UNIVERSAL_OUTPUTFOLDER}"

lipo -create -output "${UNIVERSAL_OUTPUTFOLDER}/${LIB_NAME}.a" "${BUILD_DIR}/${CONFIGURATION}-iphoneos/${LIB_NAME}.a"

cd "${PROJECT_DIR}"

cd ..

#拷贝整个目录到新的保存位置
cp -R "${UNIVERSAL_OUTPUTFOLDER}/${LIB_NAME}.a" "YourFileName/lib/${LIB_OUTPUT_NAME}.a"
  • 生成模拟器包(从生成通用包抽取)
#生成模拟器包
UNIVERSAL_OUTPUTFOLDER=${BUILD_DIR}/${CONFIGURATION}-universal
LIB_NAME="libTest"
LIB_OUTPUT_NAME="libTest_simulator" #导出的包名称

#生成模拟器:注意要打包的target名称要对应
xcodebuild -target libTest -configuration ${CONFIGURATION} -sdk iphonesimulator ARCHS='i386 x86_64' VALID_ARCHS='i386 x86_64' BUILD_DIR="${BUILD_DIR}" BUILD_ROOT="${BUILD_ROOT}"

mkdir -p "${UNIVERSAL_OUTPUTFOLDER}"

lipo -create -output "${UNIVERSAL_OUTPUTFOLDER}/${LIB_NAME}.a" "${BUILD_DIR}/${CONFIGURATION}-iphonesimulator/${LIB_NAME}.a"

cd "${PROJECT_DIR}"

cd ..

#拷贝整个目录到新的保存位置
cp -R "${UNIVERSAL_OUTPUTFOLDER}/${LIB_NAME}.a" "YourFileName/lib/${LIB_OUTPUT_NAME}.a"
  1. 处理包

cd到libTest.a的目录位置

  • 查看.a包里面有多少archive
$ file libTest.a
libPAIMLib.a: Mach-O universal binary with 5 architectures: [arm_v7:current ar archive] [arm64]
libTest.a (for architecture armv7): current ar archive
libTest.a (for architecture armv7s):    current ar archive
libTest.a (for architecture i386):  current ar archive
libTest.a (for architecture x86_64):    current ar archive
libTest.a (for architecture arm64): current ar archive
  • 查看.a包支持的环境
$ lipo -info libTest.a 
Architectures in the fat file: libTest.a are: armv7 armv7s i386 x86_64 arm64
  • 要是想不要包里面的某个archive(貌似一次只能删除一个),如下删除掉模拟器
$ lipo libTest.a -remove i386 -output libTest.a
$ lipo libTest.a -remove x86_64 -output libTest.a
  • 取出包里面单个archive,然后可以用lipo -create合并想要的
$ lipo -thin armv7 libTest.a -output libTest_armv7.a
$ lipo -thin armv7s libTest.a -output libTest_armv7s.a
$ lipo -thin arm64 libTest.a -output libTest_arm64.a
$ lipo -create libTest_armv7.a libTest_armv7s.a libTest_arm64 -output libTest_universal.a.a

相关文章

网友评论

      本文标题:Xcode脚本打.a包

      本文链接:https://www.haomeiwen.com/subject/wicmrftx.html