chore: update ui-mobile-base android script to support Java 21 and gradle 8+ (#10907)

Also allows fallbacks per detection.
This commit is contained in:
Nathan Walker
2025-10-30 10:41:52 -07:00
committed by GitHub
parent 8d3c3c3416
commit d856826b7a
4 changed files with 36 additions and 16 deletions

View File

@ -6,7 +6,8 @@ buildscript {
mavenCentral() mavenCentral()
} }
dependencies { dependencies {
classpath 'com.android.tools.build:gradle:7.1.0' // Updated for Java 21 compatibility via Gradle 8.4
classpath 'com.android.tools.build:gradle:8.3.2'
// NOTE: Do not place your application dependencies here; they belong // NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files // in the individual module build.gradle files

View File

@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4-bin.zip distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-bin.zip
zipStoreBase=GRADLE_USER_HOME zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists zipStorePath=wrapper/dists

View File

@ -6,7 +6,7 @@ def isWinOs = System.properties['os.name'].toLowerCase().contains('windows')
apply plugin: 'com.android.library' apply plugin: 'com.android.library'
def computeCompileSdkVersion () { def computeCompileSdkValue () {
if(project.hasProperty("compileSdk")) { if(project.hasProperty("compileSdk")) {
return compileSdk return compileSdk
} }
@ -15,15 +15,6 @@ def computeCompileSdkVersion () {
} }
} }
def computeBuildToolsVersion() {
if(project.hasProperty("buildToolsVersion")) {
return buildToolsVersion
}
else {
return "32.0.0"
}
}
def computeTargetSdkVersion() { def computeTargetSdkVersion() {
if(project.hasProperty("targetSdk")) { if(project.hasProperty("targetSdk")) {
return targetSdk return targetSdk
@ -34,12 +25,13 @@ def computeTargetSdkVersion() {
} }
android { android {
compileSdkVersion computeCompileSdkVersion() // AGP 8 DSL: use 'compileSdk' and specify namespace
buildToolsVersion computeBuildToolsVersion() compileSdk computeCompileSdkValue()
namespace "org.nativescript.widgets"
defaultConfig { defaultConfig {
minSdkVersion 17 minSdk 17
targetSdkVersion computeTargetSdkVersion() targetSdk computeTargetSdkVersion()
versionCode 1 versionCode 1
versionName "1.0" versionName "1.0"
} }

View File

@ -6,6 +6,33 @@ set -e
echo "Use dumb gradle terminal" echo "Use dumb gradle terminal"
export TERM=dumb export TERM=dumb
# Prefer running with JDK 21 for Gradle 8.4+/AGP 8.3+
if [ "$(uname)" = "Darwin" ]; then
# On macOS, prefer JDK 21, fall back to JDK 17
if /usr/libexec/java_home -v 21 >/dev/null 2>&1; then
export JAVA_HOME=$(/usr/libexec/java_home -v 21)
export PATH="$JAVA_HOME/bin:$PATH"
echo "Using Java (21) at $JAVA_HOME"
java -version 2>&1 | head -n 1
elif /usr/libexec/java_home -v 17 >/dev/null 2>&1; then
export JAVA_HOME=$(/usr/libexec/java_home -v 17)
export PATH="$JAVA_HOME/bin:$PATH"
echo "Using Java (17) at $JAVA_HOME"
java -version 2>&1 | head -n 1
else
echo "Warning: JDK 21 or 17 not found via /usr/libexec/java_home. Using current JAVA_HOME: ${JAVA_HOME:-unset}"
java -version 2>&1 || true
echo "Install JDK 21 (preferred) or JDK 17."
fi
else
# Non-macOS: print Java version for visibility
if command -v java >/dev/null 2>&1; then
echo "Detected Java runtime: $(java -version 2>&1 | head -n 1)"
else
echo "Warning: 'java' not found on PATH. Build will likely fail."
fi
fi
rm -rf dist/package/platforms/android || true rm -rf dist/package/platforms/android || true
mkdir -p dist/package/platforms/android mkdir -p dist/package/platforms/android