New to Android Studio + Gradle.
I’m trying to run my app from the command line using:
The app gets installed on my device only when I execute that command when Studio just got opened and do that initial syncing/building thing.
Whenever I modified my code, and try to run that command again, the build fails and shows this error:
Execution failed for task ':app:compileDebugJavaWithJavac' > Could not find tools.jar
How do I solve this problem? Thanks in advance.
Setting the JAVA_HOME variable to C:\Program Files\Java\jdkX.XX worked for me.
It was previously set to the JRE directory for some reason.
Are you on Linux? What does
echo $JAVA_HOME outputs?
I had a similar issue when running
react-native run-android. After setting $JAVA_HOME (which hadn’t existed) to a JDK folder, the problem was solved. In my case, I added the following line to the end of .bashrc file:
and restarted the terminal.
.gradle file from project root directory and rebuilt the app and then everything was working fine.
For anyone facing this issue after updating to AndroidStudio-2.0
I previously had AndroidStudio-1.3 and jdk-1.7.X_XX. When I updated to AndroidStudio-2.0, things worked fine until I rebooted the computer. After reboot, I encountered this error and none of the above answers worked for me.
Here’s what I did:
- Copied the project into a new folder
- Upgraded my jdk version from 1.7.X_XX to 1.8.X_XX
Changed the JDK’s path in the project structure to the new path:
And things worked.
ALL above answers are correct. I just wanna mention that if you are using MAC, and the full path of JDK path should be
Do not miss /Contents/Home
The previous answers did not work for me. This is what worked:
(Ubuntu, but should work for others as well)
Go to your project folder:
Then to android folder:
gradle.propertiesfile and add this line anywhere in the file:
Notice that there are no quotes and the right side of the example is my JDK folder.
I faced the same issue.I was looking for several hours on stack overflow and tried all of the way they said but was not able to solve the problem.Then I found that problem was in my project folder name.I just rename the folder name and everything worked fine.
i’am using zshrc i added up line.
after that carefully
echo $JAVA_HOME in terminal
You should see /Library/Java/JavaVirtualMachines/jdk-9.jdk/Contents/Home after that build will be done.