From c364031f9f3a20b4e493ed558d208756651ddb1e Mon Sep 17 00:00:00 2001 From: garenwang Date: Fri, 29 Nov 2024 16:48:01 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0xcframework=E6=89=93=E5=8C=85?= =?UTF-8?q?=E8=84=9A=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- xcframework_build.sh | 29 ++++++++++++++++ xcframework_package.sh | 76 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 105 insertions(+) create mode 100755 xcframework_build.sh create mode 100755 xcframework_package.sh diff --git a/xcframework_build.sh b/xcframework_build.sh new file mode 100755 index 0000000..f7a58d6 --- /dev/null +++ b/xcframework_build.sh @@ -0,0 +1,29 @@ +sed -i '' "s/^\(.*s.pod_target_xcconfig.*\)$/#\1/" "QCloudTrack.podspec" +sed -i '' "s/^\(.*s.pod_target_xcconfig.*\)$/#\1/" "QCloudCore.podspec" +sed -i '' "s/^\(.*s.user_target_xcconfig.*\)$/#\1/" "QCloudCore.podspec" +sed -i '' "s/^\(.*s.pod_target_xcconfig.*\)$/#\1/" "QCloudCOSXML.podspec" +sed -i '' "s/^\(.*s.user_target_xcconfig.*\)$/#\1/" "QCloudCOSXML.podspec" +sed -i '' "s/^\(.*pod 'QCloudTrack\/Cls'.*\)$/#\1/" "Podfile" + +pod install +chmod +x xcframework_package.sh +cd "Pods" + +# 设置其他变量 +OUTPUT_DIR="xcframework" + +# 清理之前的构建 +rm -rf "$OUTPUT_DIR" +mkdir -p "$OUTPUT_DIR" + +../xcframework_package.sh QCloudTrack $OUTPUT_DIR +cp -R "$OUTPUT_DIR"* "../" +../xcframework_package.sh QCloudCore $OUTPUT_DIR +cp -R "$OUTPUT_DIR"* "../" +../xcframework_package.sh QCloudCOSXML $OUTPUT_DIR +cp -R "$OUTPUT_DIR"* "../" + +rm -rf "$OUTPUT_DIR" +cd ".." +echo "编译完成. xcframework地址: $OUTPUT_DIR/" + diff --git a/xcframework_package.sh b/xcframework_package.sh new file mode 100755 index 0000000..56b5b7b --- /dev/null +++ b/xcframework_package.sh @@ -0,0 +1,76 @@ +PROJECT_NAME="$1" +OUTPUT_DIR="$2" + +rm -rf "$OUTPUT_DIR" +mkdir -p "$OUTPUT_DIR" + +# 编译 iOS 真机 Release 架构 +xcodebuild archive -project "Pods.xcodeproj" -scheme "$PROJECT_NAME" -archivePath "$OUTPUT_DIR/iphoneos.xcarchive" -sdk iphoneos -configuration Release SKIP_INSTALL=NO BUILD_LIBRARIES_FOR_DISTRIBUTION=YES + +# 编译 iOS 模拟器 arm64 Release 架构 +xcodebuild archive -project "Pods.xcodeproj" -scheme "$PROJECT_NAME" -archivePath "$OUTPUT_DIR/ios_sim_arm64.xcarchive" -sdk iphonesimulator -arch arm64 -configuration Release SKIP_INSTALL=NO BUILD_LIBRARIES_FOR_DISTRIBUTION=YES + +# 编译 iOS 模拟器 x86_64 Release 架构 +xcodebuild archive -project "Pods.xcodeproj" -scheme "$PROJECT_NAME" -archivePath "$OUTPUT_DIR/ios_sim_x86_64.xcarchive" -sdk iphonesimulator -arch x86_64 -configuration Release SKIP_INSTALL=NO BUILD_LIBRARIES_FOR_DISTRIBUTION=YES + +# 创建 iOS 真机 framework 目录 +mkdir -p "$OUTPUT_DIR/iphoneos" +cp -R "$OUTPUT_DIR/iphoneos.xcarchive/Products/Library/Frameworks/$PROJECT_NAME.framework" "$OUTPUT_DIR/iphoneos/" + +# 创建 iOS 模拟器 arm64 framework 目录 +mkdir -p "$OUTPUT_DIR/ios_sim_arm64" +cp -R "$OUTPUT_DIR/ios_sim_arm64.xcarchive/Products/Library/Frameworks/$PROJECT_NAME.framework" "$OUTPUT_DIR/ios_sim_arm64/" + +# 创建 iOS 模拟器 x86_64 framework 目录 +mkdir -p "$OUTPUT_DIR/ios_sim_x86_64" +cp -R "$OUTPUT_DIR/ios_sim_x86_64.xcarchive/Products/Library/Frameworks/$PROJECT_NAME.framework" "$OUTPUT_DIR/ios_sim_x86_64/" + +# 将arm64进行模拟器arm64架构编译, 解决arm64库冲突问题 +rm -rf $OUTPUT_DIR/temp +mkdir $OUTPUT_DIR/temp +cd $OUTPUT_DIR/temp + +ar x "../ios_sim_arm64/$PROJECT_NAME.framework/$PROJECT_NAME" + +ARM64_TO_SIM_PATH="Path/arm64-to-sim-main/.build/apple/Products/Release/arm64-to-sim" + +for file in *.o; do echo processing $file && $ARM64_TO_SIM_PATH $file; done; + +ar crv "../ios_sim_arm64/$PROJECT_NAME.framework/$PROJECT_NAME-sim-arm64" *.o + +cd .. + +# 合并x86_64与arm64 +rm -rf merge +mkdir -p merge/arm64_x86_64 + +lipo -create ios_sim_arm64/$PROJECT_NAME.framework/$PROJECT_NAME-sim-arm64 ios_sim_x86_64/$PROJECT_NAME.framework/$PROJECT_NAME -output merge/arm64_x86_64/$PROJECT_NAME + +rm -rf ios_sim_arm64/$PROJECT_NAME.framework/$PROJECT_NAME-sim-arm64 + +lipo -info merge/arm64_x86_64/$PROJECT_NAME + +cp -R merge/arm64_x86_64/$PROJECT_NAME ios_sim_arm64/$PROJECT_NAME.framework/ + +lipo -info ios_sim_arm64/$PROJECT_NAME.framework/$PROJECT_NAME + +rm -rf $PROJECT_NAME.xcframework + +# 创建 xcframework +xcodebuild -create-xcframework \ +-framework iphoneos/$PROJECT_NAME.framework \ +-framework ios_sim_arm64/$PROJECT_NAME.framework \ +-output $PROJECT_NAME.xcframework + +rm -rf ios_sim_arm64 +rm -rf ios_sim_arm64.xcarchive + +rm -rf ios_sim_x86_64 +rm -rf ios_sim_x86_64.xcarchive + +rm -rf iphoneos +rm -rf iphoneos.xcarchive + +rm -rf merge +rm -rf temp +cd ".."