-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathapkgen
More file actions
executable file
·209 lines (187 loc) · 6.31 KB
/
apkgen
File metadata and controls
executable file
·209 lines (187 loc) · 6.31 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
#!/data/data/com.termux/files/usr/bin/bash
SCRIPT_DIR="$(cd "$(dirname "$(readlink -f "${BASH_SOURCE[0]}")")" && pwd)"
source "$SCRIPT_DIR/lib/common.sh"
# ------------------------------
# BANNER
# ------------------------------
show_banner() {
clear 2>/dev/null
gum style \
--border double \
--border-foreground 39 \
--padding "1 3" \
--align center \
--width 50 \
--margin "1 2" \
"$(gum style --foreground 39 --bold 'apkgen') $(gum style --foreground 241 "v${VERSION}")" \
"$(gum style --italic --foreground 241 'Generate & Build Android APKs')"
}
# ------------------------------
# BUILD COMMANDS
# ------------------------------
ensure_gradlew() {
if [ -f "gradlew" ] && [ ! -x "gradlew" ]; then
chmod +x gradlew
fi
}
build_apk() {
local build_type="$1"
echo
step "Building APK (${build_type})..."
ensure_gradlew
if [ ! -f "gradlew" ]; then
error "No gradlew found. Are you in an Android project directory?"
fi
echo
if [ "$build_type" = "release" ]; then
./gradlew assembleRelease --no-daemon
else
./gradlew assembleDebug --no-daemon
fi
local apk_path
if [ "$build_type" = "release" ]; then
apk_path=$(find app/build/outputs/apk/release -name "*.apk" 2>/dev/null | head -1)
else
apk_path=$(find app/build/outputs/apk/debug -name "*.apk" 2>/dev/null | head -1)
fi
echo
if [ -n "$apk_path" ]; then
success "Build complete!"
echo -e " ${BOLD}APK:${RESET} ${WHITE}$(pwd)/$apk_path${RESET}"
if [ "$build_type" = "release" ]; then
echo -e " ${YELLOW}Warning: Release APK is unsigned. Use apksigner or jarsigner to sign it.${RESET}"
fi
else
error "Build output not found"
fi
echo
}
build_flutter() {
local build_type="$1"
echo
if [ ! -f "pubspec.yaml" ]; then
error "No pubspec.yaml found. Are you in a Flutter project directory?"
fi
if [ "$build_type" = "release" ]; then
error "Release builds are not supported on Termux. Use 'apkgen build flutter' for debug builds."
fi
step "Building Flutter APK (debug)..."
flutter build apk --debug --split-per-abi
local apk_path
apk_path=$(find build/app/outputs -name "*.apk" 2>/dev/null | head -1)
echo
if [ -n "$apk_path" ]; then
success "Build complete!"
echo -e " ${BOLD}APK:${RESET} ${WHITE}$(pwd)/$apk_path${RESET}"
else
error "Build output not found"
fi
echo
}
clean_project() {
echo
if [ -f "pubspec.yaml" ] && [ -f "lib/main.dart" ]; then
step "Detected Flutter project"
flutter clean
success "Flutter project cleaned"
elif [ -f "gradlew" ]; then
step "Detected Gradle project"
ensure_gradlew
./gradlew clean --no-daemon
success "Gradle project cleaned"
else
error "No supported project found. Run this from a project root directory."
fi
echo
}
# ------------------------------
# HELP
# ------------------------------
show_help() {
show_banner
echo
echo -e "${BOLD}USAGE${RESET}"
echo -e " ${WHITE}apkgen${RESET} ${GREEN}<command>${RESET} ${YELLOW}[options]${RESET}"
echo
echo -e "${BOLD}COMMANDS${RESET}"
echo -e " ${GREEN}create${RESET} ${YELLOW}<dir>${RESET} Create a new Java project (default)"
echo -e " ${GREEN}create${RESET} ${YELLOW}<dir> --kotlin${RESET} Create a new Kotlin project"
echo -e " ${GREEN}create${RESET} ${YELLOW}<dir> --flutter${RESET} Create a new Flutter project"
echo -e " ${GREEN}create${RESET} ${YELLOW}<dir> --nativecpp${RESET} Create a new Native C++ project"
echo
echo -e " ${GREEN}build debug${RESET} Build debug APK (Gradle)"
echo -e " ${GREEN}build release${RESET} Build release APK (Gradle, unsigned)"
echo -e " ${GREEN}build flutter${RESET} Build debug APK (Flutter)"
echo
echo -e " ${GREEN}clean${RESET} Clean build artifacts"
echo -e " ${GREEN}help${RESET} Show this help message"
echo
echo -e "${BOLD}EXAMPLES${RESET}"
echo -e " ${DIM}# Create and build a Java app${RESET}"
echo -e " ${WHITE}apkgen create myapp${RESET}"
echo -e " ${WHITE}cd myapp && apkgen build debug${RESET}"
echo
echo -e " ${DIM}# Create a Kotlin app${RESET}"
echo -e " ${WHITE}apkgen create myapp --kotlin${RESET}"
echo
echo -e " ${DIM}# Create a Flutter app${RESET}"
echo -e " ${WHITE}apkgen create myapp --flutter${RESET}"
echo
}
# ------------------------------
# MAIN DISPATCHER
# ------------------------------
if [ $# -eq 0 ]; then
show_help
exit 0
fi
case "$1" in
create)
shift
template_type="java"
app_dir=""
for arg in "$@"; do
case "$arg" in
--kotlin) template_type="kotlin" ;;
--flutter) template_type="flutter" ;;
--nativecpp) template_type="nativecpp" ;;
-*) error "Unknown option: $arg" ;;
*) app_dir="$arg" ;;
esac
done
if [ -z "$app_dir" ]; then
error "Usage: apkgen create <dir> [--kotlin|--flutter|--nativecpp]"
fi
if [ -d "$app_dir" ]; then
error "Directory '$app_dir' already exists"
fi
case "$template_type" in
java) source "$SCRIPT_DIR/lib/create_java.sh"; create_java "$app_dir" ;;
kotlin) source "$SCRIPT_DIR/lib/create_kotlin.sh"; create_kotlin "$app_dir" ;;
flutter) source "$SCRIPT_DIR/lib/create_flutter.sh"; create_flutter "$app_dir" ;;
nativecpp) source "$SCRIPT_DIR/lib/create_nativecpp.sh"; create_nativecpp "$app_dir" ;;
esac
;;
build)
case "$2" in
debug|release)
build_apk "$2"
;;
flutter)
build_flutter "$3"
;;
*)
error "Usage: apkgen build [debug|release|flutter]"
;;
esac
;;
clean)
clean_project
;;
help|--help|-h)
show_help
;;
*)
error "Unknown command: $1. Run 'apkgen help' for usage."
;;
esac