This repository tracks your ability to use new Java language features in an Android app.
AGP / Java | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 |
---|---|---|---|---|---|---|---|---|
3.4.2 | ✅ | ✅ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ |
3.5.3 | ✅ | ✅ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ |
3.6.1 | ✅ | ✅ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ |
4.0.0-beta03 | ✅ | ✅ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ |
4.1.0-alpha03 | ✅ | ✅ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ |
Depressing! While there's no problem using JDK 14 to compile your app with source/target level 8,
once you change the source/target level to 9 or higher the way javac
compiles your code changes.
Prior to Java 9, Java's APIs were exposed through something called rt.jar
which was put on the
"bootclasspath" of javac
. Android used the same mechanism with its android.jar
. When set to 9
or higher, javac
uses the new module system which requires an entirely new mechanism of exposing
the Android APIs.
So yeah. Not great.
Here's D8/R8's support of Java versions though:
AGP / Java | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 |
---|---|---|---|---|---|---|---|---|
3.4.2 | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❌ | ❌ |
3.5.3 | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❌ |
3.6.1 | ✅ | ✅ | ✅ | ✅ | ✅ | ❌ | ❌ | ❌ |
4.0.0-beta03 | ✅ | ✅ | ✅ | ✅ | ✅ | ❌ | ❌ | ❌ |
4.1.0-alpha03 | ✅ | ✅ | ✅ | ✅ | ✅ | ❌ | ❌ | ❌ |
Notes:
- Just because a Java language version is supported does not mean all tools will handle it properly. For example, annotation processors and bytecode transformers may need updated.
- Lint is not run on the test projects because is consumes an inordinate amount of memory and seems to have JVM metaspace leaks making automated testing difficult. Anecdotally, it seems to work fine on the latest stable, beta, and alpha for the working Java versions.
- All projects are built with Gradle 6.3 RC4 which is required for running on Java 14. Older Gradle versions can probably be used with lower Java versions but are not tracked here.
- Binary literals
- Diamond operator
- Multi-catch
- Save varargs
- Switch on string
- Try-with-resources
- Underscore literals
- Default methods in interfaces
- Static methods in interfaces
- Lambdas
- Method references
- Repeated annotations
- Type annotations
❌ AGP usage blocked by https://issuetracker.google.com/issues/139013660.
- Anonymous diamond operator
- Try-with-resources on effectively-final variables
- Private methods in interfaces
- Save varargs on private methods
❌ AGP usage blocked by https://issuetracker.google.com/issues/139013660.
❌ AGP usage blocked by https://issuetracker.google.com/issues/139013660.
❌ AGP usage blocked by https://issuetracker.google.com/issues/139013660.
❌ D8 usage blocked by https://issuetracker.google.com/issues/141587937.
- (preview) Switch expressions
❌ AGP usage blocked by https://issuetracker.google.com/issues/139013660.
❌ D8 usage blocked by https://issuetracker.google.com/issues/141587937.
- (preview) Switch expressions
- (preview) Text blocks
❌ AGP usage blocked by https://issuetracker.google.com/issues/139013660.
❌ D8 usage blocked by https://issuetracker.google.com/issues/141587937.
- Switch expressions
- (preview) Instanceof pattern matching
- (preview) Text blocks
- ❌ (preview) Records (requires runtime API support)