22 May 2024 Leave a comment Tech-Help
If you’ve encountered the following error when trying to run an Android project in Android Studio, you’re not alone:
> Failed to apply plugin 'com.android.internal.application'.
> Android Gradle plugin requires Java 11 to run. You are currently using Java 1.8.
This error typically arises when your project is configured to use an older version of Java (1.8) instead of the required Java 11. Here’s a comprehensive guide to resolving this issue.
Step-by-Step Solution
1. Verify Your Java Version
First, ensure that Java 11 is installed on your system. You can verify this by running:
java -version
If Java 11 is not installed, you will need to download and install it from the official Oracle JDK download page.
2. Update Gradle JDK in Android Studio
Once Java 11 is installed, you need to configure Android Studio to use it. Follow these steps:
- Open Android Studio.
- Navigate to Preferences (or Settings on Windows) → Build, Execution, Deployment → Build Tools → Gradle.
- In the Gradle JDK section, select the Java 11 JDK from the dropdown list.
If you cannot find Java 11 in the dropdown, you might need to set the path manually. You can do this by adding the following line to your gradle.properties
file:
org.gradle.java.home=/path/to/your/java11
On macOS, the path might look something like this:
org.gradle.java.home=/Applications/Android Studio.app/Contents/jre/Contents/Home
3. Verify Gradle Configuration
After updating the JDK, verify your Gradle configuration by running:
./gradlew --version
The output should indicate that Gradle is using Java 11:
------------------------------------------------------------
Gradle 7.0
------------------------------------------------------------
Build time: 2021-04-01 21:26:39 UTC
Revision: 912a3368b654b71250dfc925a20d620393
Kotlin: 1.4.31
Groovy: 3.0.7
Ant: Apache Ant(TM) version 1.10.9 compiled on September 27 2020
JVM: 11.0.10 (Ubuntu 11.0.10+9-Ubuntu-0ubuntu1.20.10)
OS: Linux 5.11.4-051104-generic amd64
Additional Tips
If you are still encountering issues, ensure that your JAVA_HOME
environment variable is set correctly. On macOS, you can add the following line to your ~/.zshrc
or ~/.bash_profile
file:
export JAVA_HOME="/Applications/Android Studio.app/Contents/jre/Contents/Home"
Then, reload the terminal:
source ~/.zshrc
Verify the changes by running:
echo $JAVA_HOME
Conclusion
By following these steps, you should be able to resolve the “Android Gradle plugin requires Java 11 to run” error and continue with your development work.
Streamlining Your Mobile Development with Repeato
While configuring your development environment is crucial, ensuring the quality of your apps through automated testing is equally important. This is where Repeato comes into play.
Repeato is a No-code test automation tool for iOS and Android, designed to simplify the process of creating, running, and maintaining automated tests. With its intuitive interface and powerful features, Repeato allows developers to focus on building great apps while enabling non-technical team members to contribute to the testing process.
Learn more about how Repeato can enhance your mobile development workflow by exploring our documentation and blog.