[英]android - Execution failed for task ':app:compileDebugJavaWithJavac'
New to Android Studio + Gradle. 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.仅当我在 Studio 刚刚打开并执行初始同步/构建操作时执行该命令时,该应用程序才会安装在我的设备上。
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. 将JAVA_HOME变量设置为C:\\ Program Files \\ Java \\ jdkX.XX对我有用 。
It was previously set to the JRE directory for some reason. 由于某种原因,它之前已设置为JRE目录。
Are you on Linux? 你在Linux上吗? What does
echo $JAVA_HOME
outputs? echo $JAVA_HOME
输出什么?
I had a similar issue when running react-native run-android
. 运行
react-native run-android
时遇到了类似的问题。 After setting $JAVA_HOME (which hadn't existed) to a JDK folder, the problem was solved. 将$ JAVA_HOME(尚不存在)设置为JDK文件夹后,问题就解决了。 In my case, I added the following line to the end of .bashrc file:
在我的例子中,我将以下行添加到.bashrc文件的末尾:
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 对于在更新到AndroidStudio-2.0后面临此问题的任何人
I previously had AndroidStudio-1.3 and jdk-1.7.X_XX. 我以前有AndroidStudio-1.3和jdk-1.7.X_XX。 When I updated to AndroidStudio-2.0, things worked fine until I rebooted the computer.
当我更新到AndroidStudio-2.0时,一切正常,直到我重新启动计算机。 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: 将项目结构中的JDK路径更改为新路径:
C:\\Program Files\\Java\\jdk1.8.X_XX C:\\ Program Files \\ Java \\ jdk1.8.X_XX
Gradle sync 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
我只想提一下,如果你使用MAC,那么JDK路径的完整路径应该是
"/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)
这是有用的:( Ubuntu,但也应该为其他人工作)
Go to your project folder: /.../projectlocation
转到项目文件夹:
/.../projectlocation
Then to android folder: /.../projectlocation/android
然后到android文件夹:
/.../projectlocation/android
android
Find gradle.properties
file and add this line anywhere in the file: org.gradle.java.home=/usr/local/jdk1.8.0_91
找到
gradle.properties
文件并在文件中的任何位置添加此行: 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. 请注意,没有引号,示例的右侧是我的JDK文件夹。
我遇到了同样的问题。我正在寻找几个小时的堆栈溢出并尝试了他们所说的所有方式,但无法解决问题。然后我发现问题出在我的项目文件夹名称中 。我只是重命名文件夹名称一切都很好。
export JAVA_HOME="/Library/Java/JavaVirtualMachines/jdk1.8.0_171.jdk/Contents/Home/" export JAVA_HOME =“/ Library / Java / JavaVirtualMachines / jdk1.8.0_171.jdk / Contents / Home /”
i'am using zshrc i added up line. 我使用zshrc我加起来了。 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.
之后仔细回复终端中的$ JAVA_HOME你应该看看/Library/Java/JavaVirtualMachines/jdk-9.jdk/Contents/Home之后的构建将会完成。
Execution Failed for task :app:compileDebugJavaWithJavac in Android Studio Android Studio 中任务 :app:compileDebugJavaWithJavac 的执行失败
-> after 7 hours i found SOLUTION of this issue in my project level "build.gradle" file. -> 7 小时后,我在我的项目级别“build.gradle”文件中找到了此问题的解决方案。
-> Simple to Remove only 2 things from your "build.gradle" file. -> 只需从“build.gradle”文件中删除 2 个内容即可。
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. -> 并像更新 gradle 一样更新版本。
dependencies {
classpath 'com.android.tools.build:gradle:4.2.2'
}
-> done. -> 完成。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.