JakeWharton / agp-java-support

Tracking your ability to use new Java language features and APIs in an Android app
Apache License 2.0
154 stars 2 forks source link

Updates for 4.x stables and 7.x previews #1

Open TWiStErRob opened 3 years ago

TWiStErRob commented 3 years ago

Could I help doing this? Is it just a matter of adding the AgpVersions and re-running, then updating the readme?

JakeWharton commented 3 years ago

I don't recall the process, but that sounds right. Arctic Fox and Bumblebee are the IDE whereas AGP just has versions like 7.0 and 7.1 that we'll want to use.

Definitely needs updating since Java 11 source language is supported now!

andob commented 3 years ago

Some good news:

Today I tried Android Studio Arctic Fox with one of my projects. Tried Java 11, 15, 16. Java 11 works fine, as officially announced.

Java 15 also works fine. Tried var, switch expressions and instanceof pattern matching. It's not officially supported so I had to configure gradle like this:

allprojects {
    gradle.projectsEvaluated {
        tasks.withType(JavaCompile) {
            options.fork = true
            options.forkOptions.executable = 'path/to/openjdk-15/bin/javac'
            options.compilerArgs << "--enable-preview"
            options.compilerArgs << "-Xmaxerrs" << "5000"
            options.compilerArgs << "-Xlint:deprecation"
        }
    }
}
android {
    compileOptions {
        targetCompatibility JavaVersion.VERSION_15
        sourceCompatibility JavaVersion.VERSION_15
    }
    kotlinOptions {
        jvmTarget = "15"
    }
}

Java 16 doesn't work, got the error

com.android.tools.r8.internal.oa: Unsupported class file version: 60

@JakeWharton You did submit an issue to Google to make D8 support class version 57, they solved it, now we have support on 57,58,59. Can you please submit another issue to them to support class version 60? Maybe with you reputation, they may consider the issue more seriously :).

I guess sealed classes and records are tricky to implement, but they can split the task into three: support for sealed classes, support for records and support for other java 16 / 17 language features. We android developers won't use records and sealed classes anytime soon anyway.

andob commented 3 years ago

@TWiStErRob @JakeWharton

Android Studio Arctic Fox was released the day before yesterday. I tried today both Java 11 and Java 15 (with AdoptOpenJDK build), on one of my projects - the project builds fine!

However, Android Studio has some troubles seeing generated ViewBinding classes if Java 11 is set in gradle build script. Project compiles, yet *Binding classes are rendered in red. If I change back to Java 8, AS will immediately start seeing them again. I submitted an issue to Google.

Also I've submitted another issue asking them to implement support on Java 16 and the upcoming Java 17. 17 will be the next LTS release after 11, so let's hope AS will start officially supporting it in the future 🤞

andob commented 3 years ago

Java 17 LTS is out now.