- 將 build_universal_framework.sh 放入 framework 的根目錄 ,記得給予執行權限(若用 xcworkspace 請使用 build_universal_framework_workspace.sh)
- 將 shell script 裡的
TARGET_NAME
,SCHEME
,CONFIGURATION
和PROJECT_NAME
改成你自己專案的值 - (可省略)在 .gitignore 裡最後面加上
_Archive
,結果都會放在這個資料夾裡,它不應該被版控 ./build_universal_framework.sh
以執行- 結果會在
_Archive/Universal
裡 - 覺得不夠潮的我也附上了 Fastfile 裡的 lane 實作,放入後
fastlane build_universal
就搞定了,潮度+1
Last active
March 26, 2023 01:58
-
-
Save pofat/35c585a6749a3237ce5fc7517b68a7ab to your computer and use it in GitHub Desktop.
Shell script and Fastfile to build universal framework.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
###################### | |
# Create log file | |
###################### | |
exec > ~/logs/Xcode/UniversalBuild_Log_$(date +"%Y%m%d%H%M%S").log2>&1 | |
# exit on failure | |
set -ex | |
###################### | |
# Param setup | |
###################### | |
TARGET_NAME=MyTarget | |
SCHEME=${TARGET_NAME} | |
CONFIGURATION=Release | |
PROJECT_NAME=MyProject | |
SRCROOT=. | |
SYMROOT=$(xcodebuild -scheme ${SCHEME} -showBuildSettings | grep -w BUILD_DIR | awk -F' = ' '/BUILD_DIR =/{print $2}') | |
echo "BUILD_DIR is '${SYMROOT}'" | |
###################### | |
# Build with both targets | |
###################### | |
echo "Clean ${TARGET_NAME} for simulator" | |
xcodebuild -destination 'platform=iOS Simulator,name=iPhone 6,OS=latest' -scheme ${SCHEME} clean | |
echo "Clean ${TARGET_NAME} for generic device" | |
xcodebuild -configuration ${CONFIGURATION} -destination generic/platform=iOS -scheme ${SCHEME} clean | |
echo "Build ${PROJECT_NAME} for simulator" | |
xcrun xcodebuild -project ${PROJECT_NAME}.xcodeproj -scheme ${SCHEME} -configuration ${CONFIGURATION} -destination 'platform=iOS Simulator,name=iPhone 6,OS=latest' -sdk iphonesimulator | |
echo "Build ${PROJECT_NAME} for generice device" | |
xcrun xcodebuild -project ${PROJECT_NAME}.xcodeproj -scheme ${SCHEME} -configuration ${CONFIGURATION} -destination generic/platform=iOS -sdk iphoneos | |
###################### | |
# Options | |
###################### | |
BUILD_PRODUCTS="${SYMROOT}" | |
DEVICE_BIN="${BUILD_PRODUCTS}/${CONFIGURATION}-iphoneos/${TARGET_NAME}.framework" | |
SIMULATOR_BIN="${BUILD_PRODUCTS}/${CONFIGURATION}-iphonesimulator/${TARGET_NAME}.framework" | |
ARCHIVE_PATH="${SRCROOT}/_Archive" | |
rm -rf "${ARCHIVE_PATH}" | |
mkdir "${ARCHIVE_PATH}" | |
echo "product path:${DEVICE_BIN}" | |
echo "simu path : ${SIMULATOR_BIN}" | |
###################### | |
# Copy frameworks | |
###################### | |
if [ "${CONFIGURATION}" = "Release" ]; then | |
if [ -d "${DEVICE_BIN}" ]; then | |
DEVICE_PATH="${ARCHIVE_PATH}/Release" | |
mkdir "${DEVICE_PATH}" | |
cp -r "${DEVICE_BIN}" "${DEVICE_PATH}" | |
echo "Copy device framework done" | |
else | |
echo "Device framework doesn't exist in given path" | |
fi | |
if [ -d "${SIMULATOR_BIN}" ]; then | |
SIMULATOR_PATH="${ARCHIVE_PATH}/Debug" | |
mkdir "${SIMULATOR_PATH}" | |
cp -r "${SIMULATOR_BIN}" "${SIMULATOR_PATH}" | |
echo "Copy simulator framework done" | |
else | |
echo "Simulator framework doesn't exist in given path" | |
fi | |
###################### | |
# Merge into universal framework | |
###################### | |
UNIVERSAL_PATH="${ARCHIVE_PATH}/Universal" | |
mkdir "${UNIVERSAL_PATH}" | |
cp -r "${SIMULATOR_BIN}" "${UNIVERSAL_PATH}" | |
lipo -create "${DEVICE_BIN}/${TARGET_NAME}" "${SIMULATOR_BIN}/${TARGET_NAME}" -output "${UNIVERSAL_PATH}/${TARGET_NAME}.framework/${TARGET_NAME}" | |
echo "Universal framework created successfully" | |
fi | |
exit 0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
###################### | |
# Create log file | |
###################### | |
exec > ~/logs/Xcode/UniversalBuild_Log_$(date +"%Y%m%d%H%M%S").log2>&1 | |
# exit on failure | |
set -ex | |
###################### | |
# Param setup | |
###################### | |
TARGET_NAME=MyTarget | |
SCHEME=${TARGET_NAME} | |
CONFIGURATION=Release | |
WORKSPACE_NAME=MyWorkspace | |
SRCROOT=. | |
SYMROOT=$(xcodebuild -scheme ${SCHEME} -showBuildSettings | grep -w BUILD_DIR | awk -F' = ' '/BUILD_DIR =/{print $2}') | |
echo "BUILD_DIR is '${SYMROOT}'" | |
###################### | |
# Build with both targets | |
###################### | |
echo "Clean ${TARGET_NAME} for simulator" | |
xcodebuild -destination 'platform=iOS Simulator,name=iPhone 6,OS=latest' -scheme ${SCHEME} clean | |
echo "Clean ${TARGET_NAME} for generic device" | |
xcodebuild -configuration ${CONFIGURATION} -destination generic/platform=iOS -scheme ${SCHEME} clean | |
echo "Build ${WORKSPACE_NAME} for simulator" | |
xcrun xcodebuild -workspace ${WORKSPACE_NAME}.xcworkspace -scheme ${SCHEME} -configuration ${CONFIGURATION} -destination 'platform=iOS Simulator,name=iPhone 6,OS=latest' -sdk iphonesimulator | |
echo "Build ${WORKSPACE_NAME} for generice device" | |
xcrun xcodebuild -workspace ${WORKSPACE_NAME}.xcworkspace -scheme ${SCHEME} -configuration ${CONFIGURATION} -destination generic/platform=iOS -sdk iphoneos | |
###################### | |
# Options | |
###################### | |
BUILD_PRODUCTS="${SYMROOT}" | |
DEVICE_BIN="${BUILD_PRODUCTS}/${CONFIGURATION}-iphoneos/${TARGET_NAME}.framework" | |
SIMULATOR_BIN="${BUILD_PRODUCTS}/${CONFIGURATION}-iphonesimulator/${TARGET_NAME}.framework" | |
ARCHIVE_PATH="${SRCROOT}/_Archive" | |
rm -rf "${ARCHIVE_PATH}" | |
mkdir "${ARCHIVE_PATH}" | |
echo "product path:${DEVICE_BIN}" | |
echo "simu path : ${SIMULATOR_BIN}" | |
###################### | |
# Copy frameworks | |
###################### | |
if [ "${CONFIGURATION}" = "Release" ]; then | |
if [ -d "${DEVICE_BIN}" ]; then | |
DEVICE_PATH="${ARCHIVE_PATH}/Release" | |
mkdir "${DEVICE_PATH}" | |
cp -r "${DEVICE_BIN}" "${DEVICE_PATH}" | |
echo "Copy device framework done" | |
else | |
echo "Device framework doesn't exist in given path" | |
fi | |
if [ -d "${SIMULATOR_BIN}" ]; then | |
SIMULATOR_PATH="${ARCHIVE_PATH}/Debug" | |
mkdir "${SIMULATOR_PATH}" | |
cp -r "${SIMULATOR_BIN}" "${SIMULATOR_PATH}" | |
echo "Copy simulator framework done" | |
else | |
echo "Simulator framework doesn't exist in given path" | |
fi | |
###################### | |
# Merge into universal framework | |
###################### | |
UNIVERSAL_PATH="${ARCHIVE_PATH}/Universal" | |
mkdir "${UNIVERSAL_PATH}" | |
cp -r "${SIMULATOR_BIN}" "${UNIVERSAL_PATH}" | |
lipo -create "${DEVICE_BIN}/${TARGET_NAME}" "${SIMULATOR_BIN}/${TARGET_NAME}" -output "${UNIVERSAL_PATH}/${TARGET_NAME}.framework/${TARGET_NAME}" | |
echo "Universal framework created successfully" | |
fi | |
exit 0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fastlane_version "2.50.1" | |
default_platform :ios | |
platform :ios do | |
before_all do | |
# ENV["SLACK_URL"] = "https://hooks.slack.com/services/..." | |
# cocoapods | |
end | |
desc "Build universal framework" | |
lane :build_universal do |options| | |
sh "cd .. && ./build_universal_framework.sh" | |
end | |
# You can define as many lanes as you want | |
after_all do |lane| | |
# This block is called, only if the executed lane was successful | |
# slack( | |
# message: "Successfully deployed new App Update." | |
# ) | |
end | |
error do |lane, exception| | |
# slack( | |
# message: exception.message, | |
# success: false | |
# ) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment