Search code examples
javaandroidgradleandroid-activitysource-compatibility

What is the difference between sourceCompatibility 8 and 11? What happens when they are set to different values?


When I target Android API level 21 what I set as sourceCompatibility 11 or 8 and what's the differences in my build gradle I always set it like that

 compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_8
    targetCompatibility JavaVersion.VERSION_1_8
}

but on android studio Electric Eel it says: Starting with Android Gradle plugin 7.4.0-alpha04, AGP ships wth JVM 11 bytecode.


Solution

  • When you set your compile options to

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_11
        targetCompatibility JavaVersion.VERSION_11
    }
    

    you will be able to compile with Java 11 language features