Reputation: 91630
I can't seem to get my Android applications to compile due to a really annoying exception from Android Studio:
Execution failed for task ':myapp-services: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.
I'm on Ubuntu 12.04, and I'm running Oracle's Java 7 JRE/JDK.
In ~/.bashrc
:
export JAVA_HOME="/usr/lib/jvm/java-7-oracle/"
In android-studio/bin/studio.sh
:
export JAVA_HOME="/usr/lib/jvm/java-7-oracle/"
Output of javac -version
:
javac 1.7.0_51
Output of java -version
:
java version "1.7.0_51"
Java(TM) SE Runtime Environment (build 1.7.0_51-b13)
Java HotSpot(TM) 64-Bit Server VM (build 24.51-b03, mixed mode)
Output of printenv JAVA_HOME
:
/usr/lib/jvm/java-7-oracle
Output of which javac
:
/usr/bin/javac
I have also logged out and logged back in again to my session.
I'm really not sure what I'm missing here. Why can't Android Studio compile my application?
Upvotes: 11
Views: 42251
Reputation: 8979
Go To Settings->Project Structure->JDK path and change it to the system JDK instead of Studio JDK, you will be up and running.
Upvotes: 2
Reputation: 11244
update build.gradle module
classpath 'com.android.tools.build:gradle:3.0.1'
Solved my issue
Upvotes: 1
Reputation: 372
I have solved it by updating classpath of (build.gradle (Project:projectName))
classpath 'com.android.tools.build:gradle:2.2.3'
Upvotes: 2
Reputation: 7560
I solved it by updating build.gradle (Top-Level) with
classpath 'com.android.tools.build:gradle:2.1.2'
Upvotes: 16
Reputation: 196
Check echo $JAVA_HOME
if it doesn't gives you correct path. follow setting JAVA_HOME path on Ubuntu
if it gives you correct path set then you need to update your gradle plugin version (It worked for me) and rebuild project.
Upvotes: 0
Reputation: 81
I was getting this error too. After many hours trying to solve it, I've managed to solve the problem.
In my case, executing the app from command line did the trick!
Here's what I did (I'm using Windows 10). Please, run these commands on the root of the project (where we have the app directory):
1) gradlew assembleDebug
2) adb install -r app\build\outputs\apk\app-debug-unaligned.apk
3) adb shell am start -n package_name/package_name.MainActivity, where "package_name" must be replaced by your package name (you can find it on AndroidManifest.xml). If "MainActivity" is not your launcher activity, replace it by your own activity.
It will install the app on your device and after that, Android Studio seems to find the JAVA_HOME variable again. You should be able to run the app by hitting the "Run" button on Android Studio.
Hope it helps someone!
Upvotes: 2
Reputation: 429
I have found a problem with the Android Studio studio.bat file and here it is
::------------------------------------------------------
:: Locate a JDK installation directory which will be used to run the IDE.
:: Try (in order): ANDROID_STUDIO_JDK, ..\jre, JDK_HOME, JAVA_HOME.
:: ---------------------------------------------------------------------
IF EXIST "%ANDROID_STUDIO_JDK%" SET JDK=%ANDROID_STUDIO_JDK%
IF NOT "%JDK%" == "" GOTO jdk
IF EXIST "%~dp0\..\jre" SET JDK=%~dp0\..\jre
IF NOT "%JDK%" == "" GOTO jdk
IF EXIST "%JDK_HOME%" SET JDK=%JDK_HOME%
IF NOT "%JDK%" == "" GOTO jdk
IF EXIST "%JAVA_HOME%" SET JDK=%JAVA_HOME%
IF "%JDK%" == "" GOTO error
Do you get the problem in the last 2 lines of code?
It seems that if your environmental variable is %JAVA_HOME% the batch file will GOTO error and an error message will be displayed and that's it NO ANDROID STUDIO FOR YOU, even though %JAVA_HOME% contains a valid path but if the environmental variable is something like %ANDROID_STUDIO_JDK% like mine is because I created it myself then it will work
(1) Edit the batch file
Where you see this
IF EXIST "%JAVA_HOME%" SET JDK=%JAVA_HOME%
IF "%JDK%" == "" GOTO error
Change it to this
IF EXIST "%JAVA_HOME%" SET JDK=%JAVA_HOME%
IF NOT "%JDK%" == "" GOTO jdk
IF "%JDK%" == "" GOTO error
(2) Create an environmental variable named %ANDROID_STUDIO_JDK%
as shown here
https://kb.wisc.edu/cae/page.php?id=24500
Upvotes: 0
Reputation: 694
Just downloaded the latest version (android-studio-ide-1641136.dmg) and I just changed the Info.plist file content. It's originally configured to use 1.6* as of Java version. I have 1.8 installed, so just changed to 1.8* and worked.
I am on Mac Yosemite.
Upvotes: 0
Reputation: 91630
I found a solution in a different answer:
rm ~/.AndroidStudioPreview/config/options/jdk.table.xml
What seems to have happened is that something was configured for a previous version of Android Studio and this configuration lived too long :)
Upvotes: 10