Vendor Gradle wrappers for new projects
This commit is contained in:
+1
-1
@@ -6,4 +6,4 @@ No known bugs at the moment.
|
|||||||
|
|
||||||
## TODO
|
## 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.
|
||||||
|
|||||||
@@ -57,7 +57,7 @@ The CLI is now split into smaller scripts for readability and maintenance:
|
|||||||
|
|
||||||
- Gradle settings and properties
|
- Gradle settings and properties
|
||||||
- a single `app` module
|
- a single `app` module
|
||||||
- a real Gradle wrapper for the generated project
|
- vendored Gradle wrapper files for the generated project
|
||||||
- a minimal `MainActivity`
|
- a minimal `MainActivity`
|
||||||
- a simple default theme and string resources
|
- 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_AGP_VERSION` defaults to `8.5.2`
|
||||||
- `ANDROID_BUILDER_GRADLE_DISTRIBUTION_SHA256` defaults to the official checksum for `gradle-8.7-bin.zip`
|
- `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
|
## Notes
|
||||||
|
|
||||||
- The project is designed around Termux.
|
- The project is designed around Termux.
|
||||||
|
|||||||
+1
-1
@@ -11,7 +11,7 @@ case "$COMMAND" in
|
|||||||
-h|--help) TARGET="help" ;;
|
-h|--help) TARGET="help" ;;
|
||||||
esac
|
esac
|
||||||
shift || true
|
shift || true
|
||||||
exec "$ROOT_DIR/lib/commands/$TARGET.sh" "$@"
|
exec bash "$ROOT_DIR/lib/commands/$TARGET.sh" "$@"
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
echo "Unknown command: $COMMAND"
|
echo "Unknown command: $COMMAND"
|
||||||
|
|||||||
@@ -20,5 +20,7 @@ if [ -f ./gradlew ]; then
|
|||||||
chmod +x ./gradlew
|
chmod +x ./gradlew
|
||||||
./gradlew "$TASK"
|
./gradlew "$TASK"
|
||||||
else
|
else
|
||||||
gradle "$TASK"
|
echo "Error: ./gradlew is missing."
|
||||||
|
echo "This project needs the vendored Gradle wrapper generated by android-builder new."
|
||||||
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|||||||
@@ -9,8 +9,6 @@ echo
|
|||||||
|
|
||||||
java -version
|
java -version
|
||||||
echo
|
echo
|
||||||
gradle -v | grep Gradle
|
|
||||||
echo
|
|
||||||
aapt2 version
|
aapt2 version
|
||||||
echo
|
echo
|
||||||
|
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ ensure_termux
|
|||||||
echo "==> Installing packages"
|
echo "==> Installing packages"
|
||||||
pkg update -y
|
pkg update -y
|
||||||
pkg install -y git curl wget unzip zip nano \
|
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"
|
echo "==> Configuring Java"
|
||||||
JAVA_BIN="$(command -v java)"
|
JAVA_BIN="$(command -v java)"
|
||||||
|
|||||||
+14
-11
@@ -8,6 +8,7 @@ PLATFORM="${ANDROID_BUILDER_PLATFORM:-android-33}"
|
|||||||
GRADLE_VERSION="${ANDROID_BUILDER_GRADLE_VERSION:-8.7}"
|
GRADLE_VERSION="${ANDROID_BUILDER_GRADLE_VERSION:-8.7}"
|
||||||
AGP_VERSION="${ANDROID_BUILDER_AGP_VERSION:-8.5.2}"
|
AGP_VERSION="${ANDROID_BUILDER_AGP_VERSION:-8.5.2}"
|
||||||
GRADLE_DISTRIBUTION_SHA256="${ANDROID_BUILDER_GRADLE_DISTRIBUTION_SHA256:-544c35d6bd849ae8a5ed0bcea39ba677dc40f49df7d1835561582da2009b961d}"
|
GRADLE_DISTRIBUTION_SHA256="${ANDROID_BUILDER_GRADLE_DISTRIBUTION_SHA256:-544c35d6bd849ae8a5ed0bcea39ba677dc40f49df7d1835561582da2009b961d}"
|
||||||
|
TEMPLATE_DIR="$ROOT_DIR/templates/gradle-wrapper"
|
||||||
|
|
||||||
ensure_termux() {
|
ensure_termux() {
|
||||||
if [ -z "${PREFIX:-}" ] || [ ! -d "/data/data/com.termux/files/usr" ]; then
|
if [ -z "${PREFIX:-}" ] || [ ! -d "/data/data/com.termux/files/usr" ]; then
|
||||||
@@ -16,14 +17,6 @@ ensure_termux() {
|
|||||||
fi
|
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() {
|
set_gradle_wrapper_sha256() {
|
||||||
WRAPPER_PROPERTIES="$1"
|
WRAPPER_PROPERTIES="$1"
|
||||||
|
|
||||||
@@ -59,8 +52,6 @@ get_apk_path() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
create_base_project() {
|
create_base_project() {
|
||||||
require_gradle
|
|
||||||
|
|
||||||
NAME="$1"
|
NAME="$1"
|
||||||
MESSAGE="$2"
|
MESSAGE="$2"
|
||||||
PACKAGE="com.example.$(echo "$NAME" | tr '[:upper:]' '[:lower:]' | tr -cd 'a-z0-9')"
|
PACKAGE="com.example.$(echo "$NAME" | tr '[:upper:]' '[:lower:]' | tr -cd 'a-z0-9')"
|
||||||
@@ -179,7 +170,19 @@ public class MainActivity extends Activity {
|
|||||||
}
|
}
|
||||||
EOF2
|
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" <<EOF2
|
||||||
|
distributionBase=GRADLE_USER_HOME
|
||||||
|
distributionPath=wrapper/dists
|
||||||
|
distributionUrl=https\://services.gradle.org/distributions/gradle-$GRADLE_VERSION-bin.zip
|
||||||
|
distributionSha256Sum=$GRADLE_DISTRIBUTION_SHA256
|
||||||
|
zipStoreBase=GRADLE_USER_HOME
|
||||||
|
zipStorePath=wrapper/dists
|
||||||
|
EOF2
|
||||||
set_gradle_wrapper_sha256 "$NAME/gradle/wrapper/gradle-wrapper.properties"
|
set_gradle_wrapper_sha256 "$NAME/gradle/wrapper/gradle-wrapper.properties"
|
||||||
|
|
||||||
echo "Created project: $NAME"
|
echo "Created project: $NAME"
|
||||||
|
|||||||
Binary file not shown.
+5
@@ -0,0 +1,5 @@
|
|||||||
|
#!/data/data/com.termux/files/usr/bin/bash
|
||||||
|
set -e
|
||||||
|
|
||||||
|
APP_HOME="$(cd "$(dirname "$0")" && pwd -P)"
|
||||||
|
exec java -classpath "$APP_HOME/gradle/wrapper/gradle-wrapper.jar" org.gradle.wrapper.GradleWrapperMain "$@"
|
||||||
Reference in New Issue
Block a user