Android Studio 找不到 java 编译器

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/40155462/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-11 22:27:14  来源:igfitidea点击:

Android Studio can't find java compiler

javaandroid

提问by Tobi F.

I downloaded a Android project and wanted to try it. So I imported it to Android Studio (2.2) and when running the project i get the error:

我下载了一个Android项目并想尝试一下。所以我将它导入到 Android Studio (2.2) 并且在运行项目时出现错误:

Error:Execution failed for task ':app:compileDebugJava'. Cannot find System Java Compiler. Ensure that you have installed a JDK (not just a JRE) and configured your JAVA_HOME system variable to point to the according directory.

错误:任务 ':app:compileDebugJava' 的执行失败。找不到系统 Java 编译器。确保您已经安装了 JDK(不仅仅是 JRE)并将您的 JAVA_HOME 系统变量配置为指向相应的目录。

Before the runnning of every project worked and i'm searching for days but still found no working solution.

在每个项目运行之前,我正在寻找几天,但仍然没有找到可行的解决方案。

EDIT: Here is my project structure: project structure

编辑:这是我的项目结构: 项目结构

Maybe someone of you has the solution.

也许你们中有人有解决方案。

回答by Maksym Chernikov

I think, you didn't setup JDK for current project. You've just loaded the code. Do it in project structure.

我认为,您没有为当前项目设置 JDK。您刚刚加载了代码。在项目结构中进行。

You can do it here: File > Project Structure > [Platform Settings] > SDKs.

您可以在此处执行此操作:文件 > 项目结构 > [平台设置] > SDK。

回答by gregn3

I had the same issue. It turned out to be old versions of the buildscript dependencies classpath, and the buildToolsversion, that were included in the project config files. This was not related to the JDK path, changing the JDK path didn't help.

我遇到过同样的问题。结果证明是旧版本的 buildscript 依赖项类路径和 buildToolsversion,它们包含在项目配置文件中。这与 JDK 路径无关,更改 JDK 路径没有帮助。

I followed this answer, with these additions:

我遵循了这个答案,并添加了以下内容:

In step 1, the gradle-wrapper.propertiesfile is inside the gradle/wrapperfolder in my main project folder. The lowest gradle version that Android Studio accepted here was gradle-3.3-all.zip

在步骤 1 中,该gradle-wrapper.properties文件gradle/wrapper位于我的主项目文件夹中的文件夹内。Android Studio 在这里接受的最低 gradle 版本是gradle-3.3-all.zip

In step 4, for the classpath gradle version I used 2.3.2, this is the latest non-alpha version that I found, that works here. (not sure why these versions are different. but it works)

在第 4 步中,对于我使用的 2.3.2 的类路径 gradle 版本,这是我发现的最新非 alpha 版本,可以在这里使用。(不知道为什么这些版本不同。但它有效)

I also had to change the buildToolsVersionto '25.0.0' from the old '20.0.0', inside the file build.gradlein my module sub-folder.

我还必须在模块子文件夹中的文件内将buildToolsVersion从旧的“ 20.0.0”更改为“ 25.0.0” 。build.gradle

Now I can compile the project in Android Studio successfully.

现在我可以在 Android Studio 中成功编译项目了。

(The file gradlewin the project main folder is generated once at the project creation, and can be regenerated. It can be used to run gradle commands manually, such as debugging this issue. But it was not needed for this solution.)

gradlew项目主文件夹中的文件在项目创建时生成一次,可以重新生成。它可以用于手动运行gradle命令,例如调试此问题。但本解决方案不需要它。)

回答by Suman Astani

This kind of problem arises when you compile old project in your new updated Android Studio IDE Version. Technically speaking : gradle build version is old. Just update with new

当您在新更新的 Android Studio IDE 版本中编译旧项目时,会出现此类问题。从技术上讲:gradle 构建版本很旧。只需更新新的

This can be achieve editing inside build.gradle(Project: App name)

这个可以在 build.gradle(Project: App name) 里面实现编辑

    dependencies {
        classpath 'com.android.tools.build:gradle:2.3.3'
//update latese gradle build version.
    }

This might do the trick.

这可能会奏效。

回答by Fidato Ali Sarker

editing inside build.gradle(Project: App name)

在 build.gradle 中编辑(项目:应用程序名称)

dependencies {
    implementation 'com.android.tools.build:gradle:3.6.2'
    //update latese gradle build version.
        }

then sync it.

然后同步它。