After executing an upgrade gradle from Android Studio after ionic capacitor build android --prod command to make a signed release, now when trying to execute ionic cap run android -l --external the process ends with this error:
[capacitor] A problem occurred evaluating project ':app'.
[capacitor] > Failed to apply plugin 'com.android.internal.application'.
[capacitor] > Android Gradle plugin requires Java 11 to run. You are currently using Java 1.8.
[capacitor] You can try some of the following options:
[capacitor] - changing the IDE settings.
[capacitor] - changing the JAVA_HOME environment variable.
[capacitor] - changing `org.gradle.java.home` in `gradle.properties`.
Gradle settings in Android Studio is set to Java 11. I don’t know where to look to solve this.
If I understand correctly, it only errors out when running ionic cap run android -l --external, correct?
If so, make sure your JAVA_HOME variable is set correctly in your terminal. Android Studio and the adb tools don’t use JAVA_HOME if you’ve set it manually in the IDE, but it will use JAVA_HOME from the cli. On Mac and Linux, you can check this by running echo $JAVA_HOME.
On Mac, my current Java 11 JAVA_HOME variable looks like this
In case anyone here is on a windows machine, this worked for me:
Download most up-to-date jdk from oracle website.
Create system environment variable called “JAVA_HOME” (type “view advanced system settings” in the windows search bar, click “Environment Variables”, add a new system variable.
The value of the variable should be the path where you installed the jdk. Mine was C:\Program Files\Java\jdk-17.0.1