14

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:

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.

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.

sepp2k
  • 363,768
  • 54
  • 674
  • 675
Tobi F.
  • 299
  • 1
  • 4
  • 8
  • You say you could run/import other projects before? Please try it again with a project you know worked before. Maybe in the meantime some program removed your JAVA_HOME entry? Or there is really no longer a jdk installed. – cherry-wave Oct 20 '16 at 13:16
  • Could you explain how i can do this? For me it seems like that in the settings of this project something is wrong or missing because other projects are working. How can i check this? Maybe it's really simple but i've been working with java and android studio only for months. – Tobi F. Oct 20 '16 at 13:23
  • When you think it is the project's settings, create a new Android Project and replace "app\src" with the "app\src" from your downloaded project. Maybe you also need to add some dependencies in build.gradle – cherry-wave Oct 20 '16 at 13:27
  • 1
    I now used your advice and created a new project. Then i copied the app/src/main folder to the new project and the app is starting on my smartphone. So it should be the project settings of the imported project. – Tobi F. Oct 20 '16 at 13:45
  • This is great. If you are still interested in what caused the problem, you could use total commander or something else to compare your new project to the original one. Then you can see which files were missing or wrong. – cherry-wave Oct 20 '16 at 13:48

4 Answers4

14

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

This can be achieve editing inside 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.

ZdaR
  • 22,343
  • 7
  • 66
  • 87
Suman Astani
  • 1,181
  • 11
  • 16
9

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

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

mchern1kov
  • 450
  • 3
  • 10
  • in my main questionen i now posted a screenshot of the project structure. Cann you say me if they are right? – Tobi F. Oct 20 '16 at 13:38
  • 1
    @TobiF. no, it's not. The sign said to insert the path for JDK location, not JRE. JDK location supposed to be like : **C:\Program Files\Java\jdk1.8.0_101** or whenever you've loaded it. – mchern1kov Oct 20 '16 at 13:47
  • No this shouldn't be the problem. The path is wrong, yes, but "Use embedded JDK" is checked so the path posted below is ignored. (In my apps, this looks exactly like in the picture too) – cherry-wave Oct 20 '16 at 13:51
  • 1
    @cherry-wave oh. Didn't noticed it to be set) – mchern1kov Oct 20 '16 at 14:14
5

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.

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

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)

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.

Now I can compile the project in Android Studio successfully.

(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.)

gregn3
  • 1,728
  • 2
  • 19
  • 27
0

editing inside build.gradle(Project: App name)

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

then sync it.