ios打包可以用fastlane,也可以用shell脚本,下面是用shell脚本打包framework
echo "输入sdk的版本号"
read current_version
echo "输入的版本号为:$current_version"
#当前项目所在路径
current_path=`pwd`
product_name='demo'
project_name="$product_name.xcodeproj"
framework_config=Release
#修改target的版本号
/usr/libexec/PlistBuddy -c "Set :'CFBundleShortVersionString' $current_version" $product_name/Info.plist
product_dir=$current_path/"Products"
build_dir=$current_path/'build'
archiveWorkSpace(){
#模拟器build
xcodebuild -project ${project_name} -configuration framework_config -sdk iphonesimulator SYMROOT=${build_dir}
#真机build
xcodebuild -project ${project_name} -configuration framework_config -sdk iphoneos SYMROOT=${build_dir}
#将模拟器中的framework复制出来
cp -R ${build_dir}/${framework_config}-iphonesimulator/${product_name}.framework ${product_dir}
#从模拟器中移除arm64架构
lipo ${build_dir}/${framework_config}-iphonesimulator/${product_name}.framework/${product_name} -remove arm64 -output ${build_dir}/${framework_config}-iphonesimulator/${product_name}.framework/${product_name}
#合并真机和模拟器文件并输出到构建的framework中
lipo -create ${build_dir}/${framework_config}-iphonesimulator/${product_name}.framework/${product_name} ${build_dir}/${framework_config}-iphoneos/${product_name}.framework/${product_name} -output ${product_dir}/${product_name}.framework/${product_name}
#删除无用的三方bundle
find ${product_dir}/${product_name}.framework -maxdepth 1 -name '*.bundle' -not -name "${product_name}*.bundle" | xargs rm -rf
#自动打开文件夹
open $product_dir
}
makeFramework(){
#判断临时文件夹是否存在,存在的话先删除
if [ -d $build_dir ];then
rm -rf $build_dir
fi
# 判断输出文件夹是否存在,存在的话先删除
if [ -d ${product_dir} ];then
rm -rf ${product_dir}
fi
#创建临时文件夹
mkdir -p ${build_dir}
#创建输出文件夹
mkdir -p ${product_dir}
archiveWorkSpace
rm -rf $build_dir
}
makeFramework