Reputation: 471
I am at my wits end trying to get this to work, and I'm not finding a solution. I just upgraded my Android Studio to Arctic Fox and I'm getting this error:
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':firebase_core:compileDebugJavaWithJavac'.
> Could not find tools.jar. Please check that /Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home contains a valid JDK installation.
I am running on macOS BiGSur 11.2.3.
I opened terminal and ran /usr/libexec/java_home -V | grep jdk
Which outputs:
Matching Java Virtual Machines (1):
1.8.301.09 (x86_64) "Oracle Corporation" - "Java" /Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home
I tried editing ~/.zshrc
by adding various export lines such as:
export JAVA_HOME=/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home
export PATH=$JAVA_HOME/bin:$PATH
to which I get this error in the terminal after running source ~/.zscrc
:
.zshrc:export:2: not valid in this context: Plug-Ins/JavaAppletPlugin.plugin/Contents/Home
and tried this:
export JAVA_HOME=$(/usr/libexec/java_home)
which just repeats the same Build failure.
I also tried adding various paths to the Gradle.properties file, such as one of the following:
org.gradle.java.home=/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home
org.gradle.java.home=/Library/Java/JavaVirtualMachines/jdk1.8.0_271.jdk/Contents/Home
Same Build failure for the first one, and Value '/Library/Java/JavaVirtualMachines/jdk1.8.0_271.jdk/Contents/Home' given for org.gradle.java.home Gradle property is invalid (Java home supplied is invalid)
for the second one.
I did a search for tools.jar on my system, and nothing is found.
Also tried uninstalling Java and reinstalling it... nothing.
Please any other suggestions?
Upvotes: 2
Views: 4483
Reputation: 471
Finally found an answer. Apparently I only had the JRE installed, and not the JDK. Steps to fix:
Install Java SE Development Kit 8
Re-run /usr/libexec/java_home -V | grep jdk
to get the new path, which outputs:
Matching Java Virtual Machines (2):
1.8.301.09 (x86_64) "Oracle Corporation" - "Java" /Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home
1.8.0_301 (x86_64) "Oracle Corporation" - "Java SE 8" /Library/Java/JavaVirtualMachines/jdk1.8.0_301.jdk/Contents/Home
Add the Java SE 8 path to android > gradle.properties: org.gradle.java.home=/Library/Java/JavaVirtualMachines/jdk1.8.0_301.jdk/Contents/Home
Rebuild the app.
Hope this helps someone else after I spent 5 hours trying to figure this out.
Upvotes: 5