-
Notifications
You must be signed in to change notification settings - Fork 30
Expand file tree
/
Copy pathbuild.sh
More file actions
executable file
Β·236 lines (204 loc) Β· 6.03 KB
/
build.sh
File metadata and controls
executable file
Β·236 lines (204 loc) Β· 6.03 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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
#!/bin/bash
# SubTrackr Android Build Script
# This script builds an Android APK without using EAS
# and automatically renames the APK to "subtrackr"
#
# Usage: ./build.sh [options]
# Options:
# --clean Clean all build artifacts before building
# --install Automatically install on connected device
# --help Show this help message
set -e # Exit on any error
# Parse command line arguments
CLEAN_BUILD=false
AUTO_INSTALL=false
while [[ $# -gt 0 ]]; do
case $1 in
--clean)
CLEAN_BUILD=true
shift
;;
--install)
AUTO_INSTALL=true
shift
;;
--help)
echo "π SubTrackr Android Build Script"
echo "=================================="
echo ""
echo "Usage: ./build.sh [options]"
echo ""
echo "Options:"
echo " --clean Clean all build artifacts before building"
echo " --install Automatically install on connected device"
echo " --help Show this help message"
echo ""
echo "Examples:"
echo " ./build.sh # Standard build"
echo " ./build.sh --clean # Clean build"
echo " ./build.sh --install # Build and install"
echo " ./build.sh --clean --install # Clean build and install"
echo ""
exit 0
;;
*)
echo "Unknown option: $1"
echo "Use --help for usage information"
exit 1
;;
esac
done
echo "π SubTrackr Android 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
# Check if Expo CLI is installed
if ! command -v expo &> /dev/null; then
print_error "Expo CLI is not installed. Installing now..."
npm install -g @expo/cli
fi
# Check if Android SDK is available
if [ -z "$ANDROID_HOME" ] && [ -z "$ANDROID_SDK_ROOT" ]; then
print_warning "Android SDK environment variables not set."
print_warning "Make sure you have Android Studio installed and SDK configured."
print_warning "You may need to set ANDROID_HOME or ANDROID_SDK_ROOT."
fi
# Clean previous builds if requested
if [ "$CLEAN_BUILD" = true ]; then
print_status "Cleaning all build artifacts..."
rm -rf android/
rm -rf ios/
rm -rf dist/
rm -rf .expo/
rm -rf builds/
else
print_status "Cleaning previous builds..."
rm -rf android/
rm -rf ios/
rm -rf dist/
rm -rf .expo/
fi
# Install dependencies
print_status "Installing dependencies..."
npm install
# Check if we need to eject
if [ ! -d "android" ]; then
print_status "Ejecting to bare React Native..."
npx expo prebuild --platform android --clean
else
print_status "Using existing Android project..."
fi
# Build the APK
print_status "Building Android APK..."
cd android
# Clean the project
print_status "Cleaning Android project..."
./gradlew clean
# Build debug APK
print_status "Building debug APK..."
./gradlew assembleDebug
# Check if build was successful
if [ $? -eq 0 ]; then
print_success "Android build completed successfully!"
else
print_error "Android build failed!"
exit 1
fi
# Go back to project root
cd ..
# Find the generated APK
APK_PATH=$(find android/app/build/outputs/apk/debug/ -name "*.apk" | head -n 1)
if [ -z "$APK_PATH" ]; then
print_error "Could not find generated APK!"
exit 1
fi
# Create output directory
mkdir -p builds
# Rename and copy APK
APK_NAME="subtrackr.apk"
FINAL_APK_PATH="builds/$APK_NAME"
print_status "Renaming APK to: $APK_NAME"
cp "$APK_PATH" "$FINAL_APK_PATH"
# Get APK info
APK_SIZE=$(du -h "$FINAL_APK_PATH" | cut -f1)
BUILD_DATE=$(date '+%Y-%m-%d %H:%M:%S')
print_success "Build completed successfully!"
echo ""
echo "π± APK Details:"
echo " Name: $APK_NAME"
echo " Size: $APK_SIZE"
echo " Location: $FINAL_APK_PATH"
echo " Built: $BUILD_DATE"
echo ""
# Optional: Install on connected device
if [ "$AUTO_INSTALL" = true ] || command -v adb &> /dev/null; then
DEVICES=$(adb devices | grep -v "List of devices" | grep "device$" | wc -l)
if [ $DEVICES -gt 0 ]; then
echo "π± Connected devices detected:"
adb devices | grep -v "List of devices"
echo ""
if [ "$AUTO_INSTALL" = true ]; then
print_status "Auto-installing APK on device..."
adb install "$FINAL_APK_PATH"
if [ $? -eq 0 ]; then
print_success "APK installed successfully on device!"
else
print_error "Failed to install APK on device."
fi
else
read -p "Do you want to install the APK on a connected device? (y/N): " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]; then
print_status "Installing APK on device..."
adb install "$FINAL_APK_PATH"
if [ $? -eq 0 ]; then
print_success "APK installed successfully on device!"
else
print_error "Failed to install APK on device."
fi
fi
fi
fi
else
print_warning "ADB not found. Cannot install on device automatically."
fi
echo ""
print_success "π SubTrackr Android build completed!"
print_status "Your APK is ready at: $FINAL_APK_PATH"
echo ""
print_status "Next steps:"
echo " 1. Test the APK on a device"
echo " 2. Share with team members"
echo " 3. Submit to hackathon judges"
echo ""
# Optional: Open builds folder
if command -v open &> /dev/null; then
read -p "Open builds folder? (y/N): " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]; then
open builds/
fi
fi