JDK 11 with android?

Has anyone played with jdk 11 in android yet?
New features in Android Studio Preview | Android Developers

Just curious as it would make porting jme applications to android much simpler as many of us now use jdk 11.

1 Like

Yes, it’s working.

1 Like

Sweet. I am getting ready to fly back to work so I won’t have a change to play with it for a couple weeks, but when I get back home I am very interested in trying out somethings.

1 Like

@Pavl_G by any chance, do you know if android supports Pattern Matching? (I think it is added in java 12)

if (x instanceof Integer i) {
    // can use i here, of type Integer
}
1 Like

Hi @Ali_RS , i am sorry for very late reply, yes it may be presented on VERSION_12 which is not supported by AGP 7.0.2 till now, Android Arctic Fox is now on the Stable Channel, i have tested it with jme, Gradle 7.0, AGP 7.0.2, everything is fine, but i cannot use JDK11 language features, donot know why … repo :

1 Like

I see. Thanks for the response @Pavl_G .
The next Java release is going to be an LTS release, I hope AGP adds support for it.

Edit:

By the way, this might be interesting

1 Like

So this may be the reason why I cannot experience java11 key features on android code ? “The forkoptions”

Not sure.

I tried with Java 14 and using instanceof Pattern Matching on Android 7.1 using AGP 7.0.0 and it works fine for me.

1 Like

So far var works fine, but i cannot access other jdk11 language features, like the new String methods, etc, seems there is a one more step to enable language features not only build.

I’m using this flag if it helps.

compileOptions {
        // Flag to enable support for the new language APIs
        coreLibraryDesugaringEnabled true
        // Sets Java compatibility to Java 14
        sourceCompatibility JavaVersion.VERSION_14
        targetCompatibility JavaVersion.VERSION_14
    }

also enabled the preview language features

tasks.withType(JavaCompile).configureEach { task ->
    task.options.compilerArgs += "--enable-preview"
}
1 Like

@Ali_RS Thanks for sharing :slight_smile: .

2 Likes

You’re welcome :slightly_smiling_face:

1 Like