diff --git a/BUGS_TODO.md b/BUGS_TODO.md index aa4c5e9..ee89864 100644 --- a/BUGS_TODO.md +++ b/BUGS_TODO.md @@ -6,4 +6,4 @@ No known bugs at the moment. ## TODO -- Consider vendoring wrapper files so `android-builder new` does not need a system `gradle` binary at generation time. +No open TODOs at the moment. diff --git a/README.md b/README.md index f1f0b7d..e818102 100644 --- a/README.md +++ b/README.md @@ -57,7 +57,7 @@ The CLI is now split into smaller scripts for readability and maintenance: - Gradle settings and properties - a single `app` module -- a real Gradle wrapper for the generated project +- vendored Gradle wrapper files for the generated project - a minimal `MainActivity` - a simple default theme and string resources @@ -67,6 +67,8 @@ The template defaults are controlled in one place through environment variables: - `ANDROID_BUILDER_AGP_VERSION` defaults to `8.5.2` - `ANDROID_BUILDER_GRADLE_DISTRIBUTION_SHA256` defaults to the official checksum for `gradle-8.7-bin.zip` +The project generator and the generated projects themselves do not need a system `gradle` binary anymore. + ## Notes - The project is designed around Termux. diff --git a/bin/android-builder b/bin/android-builder index 36ea698..7d9fc93 100755 --- a/bin/android-builder +++ b/bin/android-builder @@ -11,7 +11,7 @@ case "$COMMAND" in -h|--help) TARGET="help" ;; esac shift || true - exec "$ROOT_DIR/lib/commands/$TARGET.sh" "$@" + exec bash "$ROOT_DIR/lib/commands/$TARGET.sh" "$@" ;; *) echo "Unknown command: $COMMAND" diff --git a/lib/commands/build.sh b/lib/commands/build.sh index 90cb7c3..2717c33 100755 --- a/lib/commands/build.sh +++ b/lib/commands/build.sh @@ -20,5 +20,7 @@ if [ -f ./gradlew ]; then chmod +x ./gradlew ./gradlew "$TASK" else - gradle "$TASK" + echo "Error: ./gradlew is missing." + echo "This project needs the vendored Gradle wrapper generated by android-builder new." + exit 1 fi diff --git a/lib/commands/doctor.sh b/lib/commands/doctor.sh index a030d20..7a42936 100755 --- a/lib/commands/doctor.sh +++ b/lib/commands/doctor.sh @@ -9,8 +9,6 @@ echo java -version echo -gradle -v | grep Gradle -echo aapt2 version echo diff --git a/lib/commands/setup.sh b/lib/commands/setup.sh index d097086..d65fc69 100755 --- a/lib/commands/setup.sh +++ b/lib/commands/setup.sh @@ -9,7 +9,7 @@ ensure_termux echo "==> Installing packages" pkg update -y pkg install -y git curl wget unzip zip nano \ - openjdk-21 gradle aapt2 apksigner d8 dx android-tools + openjdk-21 aapt2 apksigner d8 dx android-tools echo "==> Configuring Java" JAVA_BIN="$(command -v java)" diff --git a/lib/common.sh b/lib/common.sh index bb6c8a8..e6a0059 100644 --- a/lib/common.sh +++ b/lib/common.sh @@ -8,6 +8,7 @@ PLATFORM="${ANDROID_BUILDER_PLATFORM:-android-33}" GRADLE_VERSION="${ANDROID_BUILDER_GRADLE_VERSION:-8.7}" AGP_VERSION="${ANDROID_BUILDER_AGP_VERSION:-8.5.2}" GRADLE_DISTRIBUTION_SHA256="${ANDROID_BUILDER_GRADLE_DISTRIBUTION_SHA256:-544c35d6bd849ae8a5ed0bcea39ba677dc40f49df7d1835561582da2009b961d}" +TEMPLATE_DIR="$ROOT_DIR/templates/gradle-wrapper" ensure_termux() { if [ -z "${PREFIX:-}" ] || [ ! -d "/data/data/com.termux/files/usr" ]; then @@ -16,14 +17,6 @@ ensure_termux() { fi } -require_gradle() { - if ! command -v gradle >/dev/null 2>&1; then - echo "Error: gradle is required to generate the project wrapper." - echo "Run: android-builder setup" - exit 1 - fi -} - set_gradle_wrapper_sha256() { WRAPPER_PROPERTIES="$1" @@ -59,8 +52,6 @@ get_apk_path() { } create_base_project() { - require_gradle - NAME="$1" MESSAGE="$2" PACKAGE="com.example.$(echo "$NAME" | tr '[:upper:]' '[:lower:]' | tr -cd 'a-z0-9')" @@ -179,7 +170,19 @@ public class MainActivity extends Activity { } EOF2 - (cd "$NAME" && gradle wrapper --gradle-version "$GRADLE_VERSION" --distribution-type bin) + mkdir -p "$NAME/gradle/wrapper" + cp "$TEMPLATE_DIR/gradle-wrapper.jar" "$NAME/gradle/wrapper/gradle-wrapper.jar" + cp "$TEMPLATE_DIR/gradlew" "$NAME/gradlew" + chmod +x "$NAME/gradlew" + + cat > "$NAME/gradle/wrapper/gradle-wrapper.properties" <