error: invalid source release: 21
A Capacitor 8 Android build needs Java 21, and the machine is using Java 17.
01What you see
Execution failed for task ':capacitor-android:compileReleaseJavaWithJavac'.
> Java compilation initialization error
error: invalid source release: 21
From our own run of cd android && ./gradlew assembleRelease
02Why it happens
Capacitor 8's Android library is compiled for Java 21. Our image has JDK 17, which Flutter and React Native use, and Java 17 cannot compile code written for Java 21.
03The fix
Install Java 21 from Homebrew inside the build and point JAVA_HOME at it. Installing took 28 seconds and the APK then built in 36 seconds in our test:
HOMEBREW_NO_AUTO_UPDATE=1 brew install --quiet openjdk@21
export JAVA_HOME="$(brew --prefix openjdk@21)/libexec/openjdk.jdk/Contents/Home"
cd android && ./gradlew assembleRelease --no-daemon -q && cd ..
04How we checked
On 25 November 2026 we started a fresh machine from our default image (Xcode 27.2), made a new project, caused this error on purpose with the command above, then ran the fix until it built. We do the same before adding any page to this list.
More on this kind of project: the guide. Other errors: Common errors. Still stuck? Send the build URL to support@macbuildcloud.com.