-
Notifications
You must be signed in to change notification settings - Fork 26
/
xcframework_package.sh
executable file
·76 lines (51 loc) · 2.76 KB
/
xcframework_package.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
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 ".."