30

I need 1.7 for a library which uses diamond operators.

I followed these sO answers...but no joy.

From gradle build

    compileSdkVersion 19
buildToolsVersion '19.0.3'

compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_7
    targetCompatibility JavaVersion.VERSION_1_7
}

defaultConfig {
    minSdkVersion 10
    targetSdkVersion 19
    versionCode 22
    versionName "1.3.1"
}

Error: Execution failed for task ':MyApp:compileDefaultFlavorDebugJava'.

invalid source release: 1.7

Java home is set : $ echo $JAVA_HOME /Library/Java/JavaVirtualMachines/jdk1.7.0_25.jdk/Contents/Home

Community
  • 1
  • 1
serenskye
  • 3,387
  • 5
  • 32
  • 50

3 Answers3

27

check your JVM versions. It should not be 1.6.

./gradlew --version
javac -version

on OSX check your $JAVA_HOME

echo $JAVA_HOME

You can set your JAVA_HOME environment variable in ~/.bash_profile JDK:

/Library/Java/JavaVirtualMachines/jdk1.7.0_60.jdk/Contents/Home/

zr0gravity7
  • 2,308
  • 1
  • 6
  • 22
David Dehghan
  • 18,323
  • 7
  • 100
  • 88
8

Go to Project Structure->SDK Location and make sure the JDK Location is set to the correct location of your JDK. Setting JAVA_HOME will fix it for command line builds, but in Android Studio it still failed for me until I fixed this setting.

Android Studio JDK location

Kekoa
  • 27,056
  • 13
  • 71
  • 90
0

The answers here require you to make global changes using environment variables or IDE settings which may not be ideal if you have to support multiple projects and JVMs or simply don't want to make global permanent changes.

The proper way to set the JVM version in Gradle is to add a property setting in your gradle.properties file. The property is org.gradle.java.home and the value should be the path to the root directory of your JDK or JRE installation.

PeterToTheThird
  • 359
  • 1
  • 2
  • 9