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.
也许你们中有人有办法。
3 个解决方案
#1
9
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)
这可以实现内部编辑。gradle(项目:软件名称)
dependencies {
classpath 'com.android.tools.build:gradle:2.3.3'
//update latese gradle build version.
}
This might do the trick.
这可能会奏效。
#2
6
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.
你可以在这里做:文件>项目结构>[平台设置]> SDKs。
#3
3
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.
我也有同样的问题。它原来是构建脚本依赖项类路径的旧版本,以及包含在项目配置文件中的buildToolsversion。这与JDK路径无关,更改JDK路径没有帮助。
I followed this answer, with these additions:
我按照这个答案做了补充:
In step 1, the gradle-wrapper.properties
file is inside the gradle/wrapper
folder in my main project folder. The lowest gradle version that Android Studio accepted here was gradle-3.3-all.zip
在第1步中,渐变包装。属性文件在我的主项目文件夹的gradle/wrapper文件夹中。Android Studio在这里接受的最低级版本是level -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,这是我在这里找到的最新的非alpha版本。(不知道为什么这些版本不同。但它的工作原理)
I also had to change the buildToolsVersion to '25.0.0' from the old '20.0.0', inside the file build.gradle
in my module sub-folder.
我还必须将buildToolsVersion从旧的“20.0.0”更改为“25.0.0”,在文件构建中。我的模块子文件夹中的渐变。
Now I can compile the project in Android Studio successfully.
现在我可以在Android Studio中成功的编译这个项目了。
(The file gradlew
in 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命令,例如调试这个问题。但这一解决方案并不需要它。
#1
9
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)
这可以实现内部编辑。gradle(项目:软件名称)
dependencies {
classpath 'com.android.tools.build:gradle:2.3.3'
//update latese gradle build version.
}
This might do the trick.
这可能会奏效。
#2
6
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.
你可以在这里做:文件>项目结构>[平台设置]> SDKs。
#3
3
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.
我也有同样的问题。它原来是构建脚本依赖项类路径的旧版本,以及包含在项目配置文件中的buildToolsversion。这与JDK路径无关,更改JDK路径没有帮助。
I followed this answer, with these additions:
我按照这个答案做了补充:
In step 1, the gradle-wrapper.properties
file is inside the gradle/wrapper
folder in my main project folder. The lowest gradle version that Android Studio accepted here was gradle-3.3-all.zip
在第1步中,渐变包装。属性文件在我的主项目文件夹的gradle/wrapper文件夹中。Android Studio在这里接受的最低级版本是level -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,这是我在这里找到的最新的非alpha版本。(不知道为什么这些版本不同。但它的工作原理)
I also had to change the buildToolsVersion to '25.0.0' from the old '20.0.0', inside the file build.gradle
in my module sub-folder.
我还必须将buildToolsVersion从旧的“20.0.0”更改为“25.0.0”,在文件构建中。我的模块子文件夹中的渐变。
Now I can compile the project in Android Studio successfully.
现在我可以在Android Studio中成功的编译这个项目了。
(The file gradlew
in 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命令,例如调试这个问题。但这一解决方案并不需要它。