New to Android Studio + Gradle.
I'm trying to run my app from the command line using:
gradlew installDebug
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:
export JAVA_HOME="path/to/a/folder/with/JDK/jdk1.8.0_60"
and restarted the terminal.
我从项目根目录中删除了.gradle
文件并重建了应用程序,然后一切正常。
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:
Changed the JDK's path in the project structure to the new path:
C:\\Program Files\\Java\\jdk1.8.X_XX
Gradle sync
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
"/Library/Java/JavaVirtualMachines/jdk1.8.0_65.jdk/Contents/Home"
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: /.../projectlocation
Then to android folder: /.../projectlocation/android
Find gradle.properties
file and add this line anywhere in the file: org.gradle.java.home=/usr/local/jdk1.8.0_91
Notice that there are no quotes and the right side of the example is my JDK folder.
我遇到了同样的问题。我正在寻找几个小时的堆栈溢出并尝试了他们所说的所有方式,但无法解决问题。然后我发现问题出在我的项目文件夹名称中 。我只是重命名文件夹名称一切都很好。
export JAVA_HOME="/Library/Java/JavaVirtualMachines/jdk1.8.0_171.jdk/Contents/Home/"
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.
Execution Failed for task :app:compileDebugJavaWithJavac in Android Studio
-> after 7 hours i found SOLUTION of this issue in my project level "build.gradle" file.
-> Simple to Remove only 2 things from your "build.gradle" file.
buildscript {
maven { url 'https://jitpack.io' }
}
allprojects{
mavenCentral{ url "http://jcenter.bintray.com/" }
maven { url "https://jitpack.io" }
}
-> and update the version of gradle just like.
dependencies {
classpath 'com.android.tools.build:gradle:4.2.2'
}
-> done.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.