-
Notifications
You must be signed in to change notification settings - Fork 30
Expand file tree
/
Copy pathbuild-release.sh
More file actions
executable file
Β·169 lines (137 loc) Β· 4.79 KB
/
build-release.sh
File metadata and controls
executable file
Β·169 lines (137 loc) Β· 4.79 KB
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
#!/bin/bash
# SubTrackr Release Build Script
# This script builds a release APK with bundled JavaScript for physical device testing
set -e # Exit on any error
echo "π SubTrackr Release Build Script"
echo "=================================="
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
# Function to print colored output
print_status() {
echo -e "${BLUE}[INFO]${NC} $1"
}
print_success() {
echo -e "${GREEN}[SUCCESS]${NC} $1"
}
print_warning() {
echo -e "${YELLOW}[WARNING]${NC} $1"
}
print_error() {
echo -e "${RED}[ERROR]${NC} $1"
}
# Check if we're in the right directory
if [ ! -f "package.json" ] || [ ! -f "app.json" ]; then
print_error "This doesn't appear to be a SubTrackr project directory."
print_error "Please run this script from the project root."
exit 1
fi
echo ""
print_status "Starting release build process..."
# Step 1: Ensure we have a clean prebuild
print_status "Step 1: Ensuring clean prebuild..."
if [ ! -d "android" ]; then
print_status "Android directory not found. Running prebuild..."
npx expo prebuild --platform android --clean
else
print_status "Android directory exists. Cleaning and rebuilding..."
rm -rf android/
npx expo prebuild --platform android --clean
fi
print_success "Prebuild completed successfully!"
# Step 2: Bundle JavaScript for release
print_status "Step 2: Bundling JavaScript for release..."
mkdir -p android/app/src/main/assets
# Create the bundle directory
print_status "Creating bundle directory..."
mkdir -p android/app/src/main/assets
# Bundle the JavaScript using Expo export
print_status "Bundling JavaScript code using Expo export..."
npx expo export --platform android --output-dir android/app/src/main/assets --clear
if [ $? -eq 0 ]; then
print_success "JavaScript bundled successfully!"
# Check if the bundle was created and copy it to the right location
if [ -f "android/app/src/main/assets/index.android.bundle" ]; then
print_success "Bundle found in expected location!"
else
print_status "Looking for bundle in exported files..."
# Find the bundle file that Expo export created (including .hbc files)
BUNDLE_FILE=$(find android/app/src/main/assets -name "*.bundle" -o -name "*.js" -o -name "*.hbc" | head -n 1)
if [ -n "$BUNDLE_FILE" ]; then
print_status "Found bundle: $BUNDLE_FILE"
# Copy it to the expected location with the right name
cp "$BUNDLE_FILE" "android/app/src/main/assets/index.android.bundle"
print_success "Bundle copied to expected location!"
else
print_error "No bundle file found after Expo export!"
exit 1
fi
fi
else
print_error "Failed to bundle JavaScript!"
exit 1
fi
# Step 3: Build release APK
print_status "Step 3: Building release APK..."
cd android
# Clean the project
print_status "Cleaning Android project..."
./gradlew clean
# Build release APK
print_status "Building release APK..."
./gradlew assembleRelease
# Check if build was successful
if [ $? -eq 0 ]; then
print_success "Release APK built successfully!"
else
print_error "Release APK build failed!"
cd ..
exit 1
fi
# Go back to project root
cd ..
# Step 4: Create builds directory and copy APK
print_status "Step 4: Organizing build output..."
mkdir -p builds
# Find the generated release APK
APK_PATH=$(find android/app/build/outputs/apk/release/ -name "*.apk" | head -n 1)
if [ -z "$APK_PATH" ]; then
print_error "Could not find generated release APK!"
exit 1
fi
# Rename and copy APK
APK_NAME="subtrackr-release.apk"
FINAL_APK_PATH="builds/$APK_NAME"
print_status "Copying release APK to: $APK_NAME"
cp "$APK_PATH" "$FINAL_APK_PATH"
# Get APK info
APK_SIZE=$(du -h "$FINAL_APK_PATH" | cut -f1)
BUNDLE_SIZE=$(du -h android/app/src/main/assets/index.android.bundle 2>/dev/null | cut -f1 || echo "N/A")
BUILD_DATE=$(date '+%Y-%m-%d %H:%M:%S')
echo ""
print_success "π Release build completed successfully!"
echo ""
echo "π± Release APK Details:"
echo " Name: $APK_NAME"
echo " Size: $APK_SIZE"
echo " Location: $FINAL_APK_PATH"
echo " Built: $BUILD_DATE"
echo " JS Bundle: $BUNDLE_SIZE"
echo ""
print_status "What was built:"
echo " β
Clean prebuild with native code"
echo " β
JavaScript bundled for release"
echo " β
Release APK with bundled JS"
echo " β
Ready for physical device testing"
echo ""
print_status "Next steps:"
echo " 1. Install $APK_NAME on your device"
echo " 2. App should work without Metro bundler"
echo " 3. Test all features on physical device"
echo " 4. Share with hackathon judges"
echo ""
print_success "Your SubTrackr release APK is ready for device testing! ππ±"
print_warning "Note: This APK contains bundled JavaScript and will work offline!"