Add android-builder wrapper command
This commit is contained in:
@@ -39,6 +39,7 @@ Available commands:
|
|||||||
- `android-builder setup`
|
- `android-builder setup`
|
||||||
- `android-builder doctor`
|
- `android-builder doctor`
|
||||||
- `android-builder new MyApp`
|
- `android-builder new MyApp`
|
||||||
|
- `android-builder wrapper`
|
||||||
- `android-builder new MyApp --template empty`
|
- `android-builder new MyApp --template empty`
|
||||||
- `android-builder build`
|
- `android-builder build`
|
||||||
- `android-builder export`
|
- `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.
|
- The project is designed around Termux.
|
||||||
- `android-builder setup` installs the SDK command-line tools and platform packages into `~/android-sdk`.
|
- `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.
|
- `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 <ProjectName>`.
|
||||||
|
- 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`.
|
||||||
|
|||||||
+1
-1
@@ -6,7 +6,7 @@ COMMAND="${1:-help}"
|
|||||||
TARGET="$COMMAND"
|
TARGET="$COMMAND"
|
||||||
|
|
||||||
case "$COMMAND" in
|
case "$COMMAND" in
|
||||||
setup|doctor|new|build|export|help|-h|--help)
|
setup|doctor|new|wrapper|build|export|help|-h|--help)
|
||||||
case "$COMMAND" in
|
case "$COMMAND" in
|
||||||
-h|--help) TARGET="help" ;;
|
-h|--help) TARGET="help" ;;
|
||||||
esac
|
esac
|
||||||
|
|||||||
@@ -22,5 +22,8 @@ if [ -f ./gradlew ]; then
|
|||||||
else
|
else
|
||||||
echo "Error: ./gradlew is missing."
|
echo "Error: ./gradlew is missing."
|
||||||
echo "This project needs the vendored Gradle wrapper generated by android-builder new."
|
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 <ProjectName>"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|||||||
@@ -12,6 +12,9 @@ if [ ! -f "$APK" ]; then
|
|||||||
echo
|
echo
|
||||||
echo "Run:"
|
echo "Run:"
|
||||||
echo " android-builder build"
|
echo " android-builder build"
|
||||||
|
echo
|
||||||
|
echo "If build fails because ./gradlew is missing, regenerate the project with:"
|
||||||
|
echo " android-builder new <ProjectName>"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ echo "Usage:"
|
|||||||
echo " android-builder setup"
|
echo " android-builder setup"
|
||||||
echo " android-builder doctor"
|
echo " android-builder doctor"
|
||||||
echo " android-builder new MyApp"
|
echo " android-builder new MyApp"
|
||||||
|
echo " android-builder wrapper"
|
||||||
echo " android-builder new MyApp --template empty"
|
echo " android-builder new MyApp --template empty"
|
||||||
echo " android-builder build"
|
echo " android-builder build"
|
||||||
echo " android-builder export"
|
echo " android-builder export"
|
||||||
|
|||||||
@@ -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
|
||||||
+20
-14
@@ -51,6 +51,25 @@ get_apk_path() {
|
|||||||
esac
|
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" <<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 "$TARGET_DIR/gradle/wrapper/gradle-wrapper.properties"
|
||||||
|
}
|
||||||
|
|
||||||
create_base_project() {
|
create_base_project() {
|
||||||
NAME="$1"
|
NAME="$1"
|
||||||
MESSAGE="$2"
|
MESSAGE="$2"
|
||||||
@@ -170,20 +189,7 @@ public class MainActivity extends Activity {
|
|||||||
}
|
}
|
||||||
EOF2
|
EOF2
|
||||||
|
|
||||||
mkdir -p "$NAME/gradle/wrapper"
|
install_gradle_wrapper_assets "$NAME"
|
||||||
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"
|
|
||||||
|
|
||||||
echo "Created project: $NAME"
|
echo "Created project: $NAME"
|
||||||
echo
|
echo
|
||||||
|
|||||||
Reference in New Issue
Block a user