AGP Java Support
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.
Java 7
- Binary literals
- Diamond operator
- Multi-catch
- Save varargs
- Switch on string
- Try-with-resources
- Underscore literals
Java 8
- Default methods in interfaces
- Static methods in interfaces
- Lambdas
- Method references
- Repeated annotations
- Type annotations
Java 9
❌ 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
Java 10
❌ AGP usage blocked by https://issuetracker.google.com/issues/139013660.
Java 11
❌ AGP usage blocked by https://issuetracker.google.com/issues/139013660.
Java 12
❌ AGP usage blocked by https://issuetracker.google.com/issues/139013660.
- (preview) Switch expressions
Java 13
❌ AGP usage blocked by https://issuetracker.google.com/issues/139013660.
- (preview) Switch expressions
- (preview) Text blocks
Java 14
❌ 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)