Skip to content

Commit 5de80c1

Browse files
committed
chore: add build file
1 parent afef0a6 commit 5de80c1

File tree

1 file changed

+77
-0
lines changed

1 file changed

+77
-0
lines changed

sample/build_ios.sh

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
#!/bin/bash
2+
3+
PATH_UNITY="/Applications/Unity/Unity.app/Contents/MacOS/Unity"
4+
PATH_TO_UNITY_SDK_SAMPLE_APP="./"
5+
BUILD_METHOD="MobileBuilder.BuildForAltTester"
6+
APPLE_TEAM_ID=""
7+
8+
# Define the build paths
9+
BUILD_XCODE_PATH="$(pwd)/build/output/iOS/Xcode"
10+
BUILD_ARCHIVE_PATH="$(pwd)/build/output/iOS/Archive"
11+
BUILD_IPA_PATH="$(pwd)/build/output/iOS/IPA"
12+
13+
# Function to clear a directory
14+
clear_directory() {
15+
local dir_path=$1
16+
if [ -d "$dir_path" ]; then
17+
echo "Clearing contents of $dir_path."
18+
rm -rf "$dir_path"/*
19+
else
20+
echo "Directory not found at $dir_path"
21+
fi
22+
}
23+
24+
# Clear all specified directories
25+
clear_directory "$BUILD_XCODE_PATH"
26+
clear_directory "$BUILD_ARCHIVE_PATH"
27+
clear_directory "$BUILD_IPA_PATH"
28+
29+
# Unity build command
30+
UNITY_COMMAND="$PATH_UNITY -projectPath \"$PATH_TO_UNITY_SDK_SAMPLE_APP\" -executeMethod $BUILD_METHOD -logFile logFile.log -quit -batchmode --buildPath \"$BUILD_XCODE_PATH\" --platform iOS"
31+
echo "Running command: $UNITY_COMMAND"
32+
33+
# Execute the Unity build command
34+
eval "$UNITY_COMMAND"
35+
36+
# Check if the Unity build command was successful
37+
if [ $? -ne 0 ]; then
38+
echo "Unity build failed. Exiting script."
39+
exit 1
40+
fi
41+
42+
# Build and archive project
43+
xcodebuild -project "$(pwd)/build/output/iOS/Xcode/Unity-iPhone.xcodeproj" \
44+
-scheme Unity-iPhone \
45+
-archivePath "$(pwd)/build/output/iOS/Archive/Unity-iPhone.xcarchive" \
46+
-configuration Release \
47+
DEVELOPMENT_TEAM="$APPLE_TEAM_ID" \
48+
CODE_SIGN_STYLE=Automatic \
49+
archive
50+
51+
# Create ExportOptions.plist with the correct APPLE_TEAM_ID
52+
EXPORT_OPTIONS_PATH="$(pwd)/build/output/iOS/Archive/ExportOptions.plist"
53+
54+
cat <<EOF > "$EXPORT_OPTIONS_PATH"
55+
<?xml version="1.0" encoding="UTF-8"?>
56+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
57+
<plist version="1.0">
58+
<dict>
59+
<key>method</key>
60+
<string>development</string> <!-- Use 'ad-hoc' or 'app-store' as needed -->
61+
<key>teamID</key>
62+
<string>$APPLE_TEAM_ID</string>
63+
<key>signingStyle</key>
64+
<string>automatic</string> <!-- Use automatic signing -->
65+
<key>compileBitcode</key>
66+
<false/>
67+
<key>thinning</key>
68+
<string>&lt;none&gt;</string>
69+
</dict>
70+
</plist>
71+
EOF
72+
73+
# Generate .ipa file
74+
xcodebuild -exportArchive \
75+
-archivePath "$(pwd)/build/output/iOS/Archive/Unity-iPhone.xcarchive" \
76+
-exportPath "$(pwd)/build/output/iOS/IPA" \
77+
-exportOptionsPlist "$EXPORT_OPTIONS_PATH"

0 commit comments

Comments
 (0)