打包脚本
# 确保xcodebuild路径正确,如果报下边错误
# ```
# xcode-select: error: tool 'xcodebuild' requires Xcode, but active developer directory '/Library/Developer/CommandLineTools' is a command line tools instance
# ```
# 将路径切换到Xcode的目录下
# ```
# sudo xcode-select --switch /Applications/Xcode.app/Contents/Developer/
# ```
# 程序根目录
SRCROOT=$(cd "$(dirname "$0")";pwd)
# default is Debug
if [ -n "$1" ]; then
CONFIGURATION='Release'
else
CONFIGURATION='Debug'
fi
echo "------------------\n当前编译版本为: $CONFIGURATION"
TARGET_NAME="project name"
OUTPUT_FOLDER="${SRCROOT}/output/${CONFIGURATION}"
BUILD_DIR_Iphoneos="${SRCROOT}/buildIphones"
BUILD_DIR_IphoneSimulator="${SRCROOT}/buildIphonesimulator"
mkdir -p ${OUTPUT_FOLDER}
echo "------------------\n:开始构建真机..."
xcodebuild -target ${TARGET_NAME} -configuration ${CONFIGURATION} ONLY_ACTIVE_ARCH=NO -sdk iphoneos BUILD_DIR=${BUILD_DIR_Iphoneos} clean build
echo "------------------\n:开始构建模拟器..."
xcodebuild -target ${TARGET_NAME} -configuration ${CONFIGURATION} ONLY_ACTIVE_ARCH=NO -sdk iphonesimulator VALID_ARCHS="x86_64" BUILD_DIR=${BUILD_DIR_IphoneSimulator} clean build
cp -R "$BUILD_DIR_Iphoneos/${CONFIGURATION}-iphoneos/${TARGET_NAME}.framework" "${OUTPUT_FOLDER}/"
echo "$BUILD_DIR_Iphoneos/${CONFIGURATION}-iphoneos/${TARGET_NAME}.framework"
echo "------------------\n开始合并Framework..."
lipo -create "$BUILD_DIR_IphoneSimulator/${CONFIGURATION}-iphonesimulator/${TARGET_NAME}.framework/${TARGET_NAME}" "$BUILD_DIR_Iphoneos/${CONFIGURATION}-iphoneos/${TARGET_NAME}.framework/${TARGET_NAME}" -output "$OUTPUT_FOLDER/${TARGET_NAME}.framework/${TARGET_NAME}"
echo "------------------\n移除多余文件..."
rm -r $BUILD_DIR_Iphoneos
rm -r $BUILD_DIR_IphoneSimulator
echo "------------------ \nframework 输出地址: $OUTPUT_FOLDER/${TARGET_NAME}.framework \n"
上面是一个shell脚本,大家执行 sh ***.sh
就可以了.
在写脚本的时候遇到一个问题,早期我们打包都是在xcode里面配置一个Target
在run script
里添加类似的脚本,这里我发现由Xcode调用的shell脚本可以拿到很多参数比如:
BUILD_DIR=""
BUILD_ROOT=""
CONFIGURATION=""
而我们自己写的脚本这些参数是要自己去配置的,所以我看了一下Xcode是什么时候把值内置到shell脚本的执行环境中,并且这些参数的默认值又是什么
我找到
找到这里就很清楚了,xcode在执行自定义shell脚本之前已经将所有参数进行了
export
知道了这些参数和默认值,就可以帮助我们在写自定义shell打包脚本的时候有些参数的使用和默认值有一些参考
网友评论