Alex Curran
Alex Curran

Reputation: 8828

Android Studio build fails with "java not found"

I am trying to build a project with Gradle, but the build is failing with the error "java not found". Whilst this works absolutely fine on the command line, it fails in Android Studio. The exact error is:

Error:Execution failed for task ':app:preDexRealDebug'. com.android.ide.common.internal.LoggedErrorException: Failed to run command: /Applications/Android Studio.app/sdk/build-tools/19.1.0/dx --dex --output /Users/amlcurran/Projects/Messages/app/build/intermediates/pre-dexed/real/debug/libGoogleAnalyticsServices-9d8e3e3fe0cc3007420cb25dbd38e357c5461aad.jar /Users/amlcurran/Projects/Messages/app/libs/libGoogleAnalyticsServices.jar Error Code: 127 Output: /Applications/Android Studio.app/sdk/build-tools/19.1.0/dx: line 89: exec: java: not found

My JDK Location (in Project Settings>SDK Locations) is set to "/Library/Java/JavaVirtualMachines/jdk1.7.0_45.jdk/Contents/Home", although every time I change this it seems to revert itself.

UPDATE: A non-Gradle project builds fine.

Upvotes: 0

Views: 923

Answers (1)

Alex Curran
Alex Curran

Reputation: 8828

It turns out to be an issue I introduced yesterday trying to get the non-Gradle project working.

I had set my JDK to the one specified above but had issues with compiling, so moved my java executable in usr/bin/java. This clearly messed up Gradle - moving it back made Gradle work again (although I assume it has now broken the non-Gradle project).

Upvotes: 2

Related Questions