Android: build on JDK 25 with Gradle 9.6.1, AGP 9.4.1, Kotlin 2.2.10

Android Studio now bundles JBR 25, which Gradle 8.14's embedded Kotlin
can't parse. Follow Tauri's current template: Gradle 9.6.1, Kotlin 2.2.10,
the builtInKotlin/newDsl/failOnMissingFiles compatibility flags, the
compilerOptions DSL, and ExecOperations in BuildTask (project.exec is gone
in Gradle 9). AGP goes to 9.4.1 rather than the template's 9.3.1.

Release lint vital is turned off: AGP 9.3/9.4's lint crashes analysing the
.gradle.kts scripts (findFirCompiledSymbol), failing every release build.

The env scripts now accept JDK 17 through 25, preferring Studio's JBR.
This commit is contained in:
2026-10-16 22:39:36 -05:00
parent 89378a41fb
commit 1641d9aa47
10 changed files with 96 additions and 61 deletions

View File

@@ -36,24 +36,22 @@ _mtgc_android_env() {
return 1
fi
# --- JDK: Gradle/AGP reject very new JDKs. Studio's bundled JBR is preferred,
# but newer Studio releases bundle JBR 25, so check each candidate's version.
# --- JDK: Gradle 9.6 / AGP 9 run on 17 through 25 (25 is the newest tested).
# Prefer Studio's bundled JBR, then the newest system JDK in that range.
for d in \
"$HOME/.local/share/JetBrains/Toolbox/apps/android-studio/jbr" \
"$HOME/.local/share/JetBrains/Toolbox/apps/android-studio"/*/jbr \
"$HOME/android-studio/jbr" \
/opt/android-studio/jbr \
/usr/lib/jvm/java-21-openjdk /usr/lib/jvm/java-21-openjdk-* /usr/lib/jvm/temurin-21-jdk* \
/usr/lib/jvm/java-17-openjdk /usr/lib/jvm/java-17-openjdk-* /usr/lib/jvm/temurin-17-jdk*
$(ls -d /usr/lib/jvm/* 2>/dev/null | sort -rV)
do
[ -x "$d/bin/javac" ] || continue
case "$(sed -n 's/^JAVA_VERSION="\([0-9]*\).*/\1/p' "$d/release" 2>/dev/null)" in
21 | 17) jdk="$d"; break ;;
esac
local v
v="$(sed -n 's/^JAVA_VERSION="\([0-9]*\).*/\1/p' "$d/release" 2>/dev/null)"
if [ -n "$v" ] && [ "$v" -ge 17 ] && [ "$v" -le 25 ]; then jdk="$d"; break; fi
done
if [ -z "$jdk" ]; then
echo "android-env: no JDK 21/17 found (Gradle rejects newer ones, incl. Studio's JBR 25)" >&2
echo "android-env: sudo dnf install temurin-21-jdk" >&2
echo "android-env: no JDK 17–25 found (sudo dnf install java-25-openjdk-devel)" >&2
return 1
fi