29
votes

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

2

2 Answers

26
votes

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/

8
votes

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