Assigned
Status Update
Comments
wa...@google.com <wa...@google.com>
ow...@gmail.com <ow...@gmail.com> #2
Thanks, Hung! I'll include this in the release notes for Canary 11, as C10 already released early last week :)
li...@google.com <li...@google.com> #3
Also, I moved this out of a public bug component.
da...@garmin.com <da...@garmin.com> #4
Several users from reddit (https://www.reddit.com/r/androiddev/comments/9h76nu/android_studio_33_canary_11_available/e6abpzh/ , https://www.reddit.com/r/androiddev/comments/9h76nu/android_studio_33_canary_11_available/e6aydtj/ ) would like to know exactly how the feature works and whether it takes effect in their projects. Below I will try to give a more comprehensive description of this feature:
Background
----------------
Conventionally, in Java-only projects, Java compilation and annotation processing is done by the AndroidJavaCompile task (which appears in the users' console as ":module:compile[Variant]JavaWithJavac").
If the user starts using the kotlin-android plugin to write Kotlin code, then the KotlinCompile task will compile Kotlin code in addition to AndroidJavaCompile compiling Java code, and AndroidJavaCompile still takes care of annotation processing.
If both cases above, because AndroidJavaCompile needs to do annotation processing, it will not be incremental if non-incremental annotation processors are present. Note that KotlinCompile, if used, is always incremental.
If the user starts using the kotlin-kapt plugin, then Kapt takes over annotation processing, and AndroidJavaCompile compiles Java code only. AndroidJavaCompile will therefore be incremental as it does not have to do annotation processing. (If it is observed to be non-incremental, then it is either a bug that has been fixed or should be fixed soon.) Kapt, however, is currently not incremental and will require a longer-term effort to be made incremental.
Goal
----------------
The goal of the new feature is to make AndroidJavaCompile incremental when Kapt is not used and non-incremental annotation processors are present. (If Kapt is used or all of the annotation processors used are incremental, then AndroidJavaCompile is already incremental without the need for the new feature.)
The new android.enableSeparateAnnotationProcessing feature
------------------------------------------------------------------------------------
In the new feature, the Android Gradle plugin first determines whether a new separate annotation processing task is needed (see below). If so, it creates a ProcessAnnotationsTask that does annotation processing only (this task appears in the users' console as ":module:process[Variant]AnnotationsWithJavac"). And because AndroidJavaCompile now does not have to do annotation processing, it will be incremental.
ProcessAnnotationsTask is used (i.e., the feature takes effect) if all of the following conditions are met:
1. Kapt is not used
2. Incremental compilation is not disabled by the user through the DSL
3. Not all of the annotation processors are incremental
4. The android.enableSeparateAnnotationProcessing flag is enabled
Incrementality of tasks
------------------------------
When Kapt is used (e.g., in most Kotlin-only or hybrid Kotlin-Java projects):
+ ProcessAnnotationsTask is not created.
+ KaptTask performs annotation processing only, without compiling. KaptTask is not incremental (yet).
+ AndroidJavaCompile and KotlinCompile perform compilation only, without annotation processing. Both tasks are incremental.
When Kapt is not used, (e.g., in Java-only projects):
+ If ProcessAnnotationsTask is needed (see above for when it is needed), ProcessAnnotationsTask first performs annotation processing only, and [AndroidJavaCompile] then performs compilation only. ProcessAnnotationsTask is not incremental (yet), and AndroidJavaCompile will be incremental.
+ Otherwise, ProcessAnnotationsTask is either not created or skipped. AndroidJavaCompile performs both annotation processing and compilation. It will be incremental or not depending on whether all of the annotation processors used are incremental or not.
Background
----------------
Conventionally, in Java-only projects, Java compilation and annotation processing is done by the AndroidJavaCompile task (which appears in the users' console as ":module:compile[Variant]JavaWithJavac").
If the user starts using the kotlin-android plugin to write Kotlin code, then the KotlinCompile task will compile Kotlin code in addition to AndroidJavaCompile compiling Java code, and AndroidJavaCompile still takes care of annotation processing.
If both cases above, because AndroidJavaCompile needs to do annotation processing, it will not be incremental if non-incremental annotation processors are present. Note that KotlinCompile, if used, is always incremental.
If the user starts using the kotlin-kapt plugin, then Kapt takes over annotation processing, and AndroidJavaCompile compiles Java code only. AndroidJavaCompile will therefore be incremental as it does not have to do annotation processing. (If it is observed to be non-incremental, then it is either a bug that has been fixed or should be fixed soon.) Kapt, however, is currently not incremental and will require a longer-term effort to be made incremental.
Goal
----------------
The goal of the new feature is to make AndroidJavaCompile incremental when Kapt is not used and non-incremental annotation processors are present. (If Kapt is used or all of the annotation processors used are incremental, then AndroidJavaCompile is already incremental without the need for the new feature.)
The new android.enableSeparateAnnotationProcessing feature
------------------------------------------------------------------------------------
In the new feature, the Android Gradle plugin first determines whether a new separate annotation processing task is needed (see below). If so, it creates a ProcessAnnotationsTask that does annotation processing only (this task appears in the users' console as ":module:process[Variant]AnnotationsWithJavac"). And because AndroidJavaCompile now does not have to do annotation processing, it will be incremental.
ProcessAnnotationsTask is used (i.e., the feature takes effect) if all of the following conditions are met:
1. Kapt is not used
2. Incremental compilation is not disabled by the user through the DSL
3. Not all of the annotation processors are incremental
4. The android.enableSeparateAnnotationProcessing flag is enabled
Incrementality of tasks
------------------------------
When Kapt is used (e.g., in most Kotlin-only or hybrid Kotlin-Java projects):
+ ProcessAnnotationsTask is not created.
+ KaptTask performs annotation processing only, without compiling. KaptTask is not incremental (yet).
+ AndroidJavaCompile and KotlinCompile perform compilation only, without annotation processing. Both tasks are incremental.
When Kapt is not used, (e.g., in Java-only projects):
+ If ProcessAnnotationsTask is needed (see above for when it is needed), ProcessAnnotationsTask first performs annotation processing only, and [AndroidJavaCompile] then performs compilation only. ProcessAnnotationsTask is not incremental (yet), and AndroidJavaCompile will be incremental.
+ Otherwise, ProcessAnnotationsTask is either not created or skipped. AndroidJavaCompile performs both annotation processing and compilation. It will be incremental or not depending on whether all of the annotation processors used are incremental or not.
ap...@google.com <ap...@google.com> #5
Known Issue with AGP 3.3.0-alpha11
--------------------------------------------------
(This was first reported athttps://www.reddit.com/r/androiddev/comments/9h76nu/android_studio_33_canary_11_available/e69psq5/ , Internal issue 116170968 .)
If the users enable the android.enableSeparateAnnotationProcessing flag in cases when ProcessAnnotationsTask is not needed (i.e., when the feature wouldn't have any real effects---see comment #4 ), then currently the build may fail with this error:
> lateinit property processorListFile has not been initialized```
In the next release, we will make sure that the build doesn't fail in such cases.
--------------------------------------------------
(This was first reported at
If the users enable the android.enableSeparateAnnotationProcessing flag in cases when ProcessAnnotationsTask is not needed (i.e., when the feature wouldn't have any real effects---see
> lateinit property processorListFile has not been initialized```
In the next release, we will make sure that the build doesn't fail in such cases.
li...@google.com <li...@google.com> #6
In AGP 3.3.0-alpha12 I'm having a problem now where processAnnotationsWithJavac trips over not seeing generated code (from the protobuf plugin) when android.enableSeparateAnnotationProcessing is set.
Description
Component used: Emoji2 Emojipicker Version used: Version 1.0.0-alpha03 Devices/Android versions reproduced on: Various
Seeing this issue upon beta'ing the emojipicker. happens uncommonly, various devices.