Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Studio can't find java compiler

Tags:

java

android

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.

like image 785
Tobi F. Avatar asked Oct 20 '16 13:10

Tobi F.


People also ask

Where is Java compiler located?

The value that you want to add is most likely C:\Program Files\Java\jdk-14.0. 2\bin if you are installing "JDK 14.0. 2". This is the location where the Java compiler ('java.exe') was installed in your file system.

Why is my Java compiler not working?

It means that javac.exe executable file, which exists in bin directory of JDK installation folder is not added to PATH environment variable. You need to add JAVA_HOME/bin folder in your machine's PATH to solve this error. You cannot compile and run Java program until your add Java into your system's PATH variable.

Where is the JDK in Android Studio?

Open your project in Android Studio and select File > Settings... > Build, Execution, Deployment > Build Tools > Gradle (Android Studio > Preferences... > Build, Execution, Deployment > Build Tools > Gradle on a Mac). Under Gradle JDK, choose the Embedded JDK option.

Can I use Java 17 with Android Studio?

As per the docs, JDK 17 isn't supported yet in Android Studio.


2 Answers

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.

like image 199
Suman Astani Avatar answered Sep 27 '22 20:09

Suman Astani


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.

like image 40
mchern1kov Avatar answered Sep 27 '22 22:09

mchern1kov