diff --git a/README.md b/README.md index e818102..3a72b0d 100644 --- a/README.md +++ b/README.md @@ -39,6 +39,7 @@ Available commands: - `android-builder setup` - `android-builder doctor` - `android-builder new MyApp` +- `android-builder wrapper` - `android-builder new MyApp --template empty` - `android-builder build` - `android-builder export` @@ -74,3 +75,10 @@ The project generator and the generated projects themselves do not need a system - The project is designed around Termux. - `android-builder setup` installs the SDK command-line tools and platform packages into `~/android-sdk`. - `android-builder export` copies the built APK into `~/storage/documents` after storage permission is granted. + +## Troubleshooting + +- If `android-builder export` says storage is not configured, run `termux-setup-storage`, grant the permission prompt, then rerun `android-builder export`. +- If `android-builder build` says `./gradlew` is missing, regenerate the project with `android-builder new `. +- If you have an existing Android project and want to add wrapper files, run `android-builder wrapper` from the project root. +- If Android SDK packages are missing, rerun `android-builder setup`. diff --git a/bin/android-builder b/bin/android-builder index 7d9fc93..5bc94a7 100755 --- a/bin/android-builder +++ b/bin/android-builder @@ -6,7 +6,7 @@ COMMAND="${1:-help}" TARGET="$COMMAND" case "$COMMAND" in - setup|doctor|new|build|export|help|-h|--help) + setup|doctor|new|wrapper|build|export|help|-h|--help) case "$COMMAND" in -h|--help) TARGET="help" ;; esac diff --git a/lib/commands/build.sh b/lib/commands/build.sh index 2717c33..49f9a55 100755 --- a/lib/commands/build.sh +++ b/lib/commands/build.sh @@ -22,5 +22,8 @@ if [ -f ./gradlew ]; then else echo "Error: ./gradlew is missing." echo "This project needs the vendored Gradle wrapper generated by android-builder new." + echo + echo "If this is an existing project, regenerate it with:" + echo " android-builder new " exit 1 fi diff --git a/lib/commands/export.sh b/lib/commands/export.sh index a87d8cd..61b27e9 100755 --- a/lib/commands/export.sh +++ b/lib/commands/export.sh @@ -12,6 +12,9 @@ if [ ! -f "$APK" ]; then echo echo "Run:" echo " android-builder build" + echo + echo "If build fails because ./gradlew is missing, regenerate the project with:" + echo " android-builder new " exit 1 fi diff --git a/lib/commands/help.sh b/lib/commands/help.sh index 9d249fb..51f2372 100755 --- a/lib/commands/help.sh +++ b/lib/commands/help.sh @@ -7,6 +7,7 @@ echo "Usage:" echo " android-builder setup" echo " android-builder doctor" echo " android-builder new MyApp" +echo " android-builder wrapper" echo " android-builder new MyApp --template empty" echo " android-builder build" echo " android-builder export" diff --git a/lib/commands/wrapper.sh b/lib/commands/wrapper.sh new file mode 100644 index 0000000..14da098 --- /dev/null +++ b/lib/commands/wrapper.sh @@ -0,0 +1,17 @@ +#!/data/data/com.termux/files/usr/bin/bash +set -e + +ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)" +source "$ROOT_DIR/lib/common.sh" + +if [ -f settings.gradle ] || [ -f build.gradle ] || [ -f app/build.gradle ]; then + install_gradle_wrapper_assets "." + echo "Gradle wrapper installed." + echo + echo "Next:" + echo " ./gradlew assembleDebug" +else + echo "Error: run this command from the root of an Android project." + echo "Expected files like settings.gradle, build.gradle, or app/build.gradle." + exit 1 +fi diff --git a/lib/common.sh b/lib/common.sh index e6a0059..607a676 100644 --- a/lib/common.sh +++ b/lib/common.sh @@ -51,6 +51,25 @@ get_apk_path() { esac } +install_gradle_wrapper_assets() { + TARGET_DIR="$1" + + mkdir -p "$TARGET_DIR/gradle/wrapper" + cp "$TEMPLATE_DIR/gradle-wrapper.jar" "$TARGET_DIR/gradle/wrapper/gradle-wrapper.jar" + cp "$TEMPLATE_DIR/gradlew" "$TARGET_DIR/gradlew" + chmod +x "$TARGET_DIR/gradlew" + + cat > "$TARGET_DIR/gradle/wrapper/gradle-wrapper.properties" < "$NAME/gradle/wrapper/gradle-wrapper.properties" <