Status Update
Comments
so...@google.com <so...@google.com> #2
A project attached to this comment demonstrates that Gradle does not support (there is a bug) consuming annotation processor output within the same project if it produces .class
files. Therefore, it doe snot make sense to create a module level library in the module itself as these symbols are not resolved by the compiler anyway. However, to make them visible to consuming projects it is enough to include them in CLASSES
order entries.
so...@google.com <so...@google.com> #3
We are attaching a non-exported module level library to the main module to represent generated classes. However,
(1) even though these classes are visible to the main module in the IDE they are not visible during compilation, and
(2) while these symbols can be consumed by projects depending on this project when compiling, the IDE does not resolve these symbols because this library is not exported and this is a problem in IDEA as well (see the screenshot)
so...@google.com <so...@google.com> #4
It is not a problem match the behaviour of Gradle in the IDE, however it is not clear if there is anything that should be fixed in Gradle.
je...@google.com <je...@google.com>
ga...@google.com <ga...@google.com> #5
so...@google.com <so...@google.com> #6
so...@google.com <so...@google.com>
so...@google.com <so...@google.com>
ga...@google.com <ga...@google.com> #8
I've modified example in #2 a bit to make it Android-specific. The issues are summarized below.
-
:myjavalib
is an Android lib with *.java sources only:build/intermediates/javac/debug/classes/com/example/generated/Created.class
gets generated by annotation processorOther2.java
andFooTest.java
referenceCreated
and both:myjavalib:compileDebugUnitTestJavaWithJavac
and:myjavalib:compileDebugJavaWithJavac
pass- IDE does not resolve
Created
[1]
-
:mylibary
is an Android lib with both *.java and *.kt:build/tmp/kapt3/classes/debug/com/example/generated/Created.class
gets generated by KAPTFoo.java
andOther.kt
referenceCreated
and:mylibrary:cDJWJ
passes, and IDE resolves symbolsExampleUnitTest.kt
andFooTest.java
referenceCreated
and:mylibrary:cDUTJWJ
passes, but the IDE does NOT resoolve symbols [2]
-
:app
is an Android lib that depends on:myjavalib
App.java
referencesCreated
andgradle :app:cDJWJ
passes, but the IDE does not resolve symbols. The issue is the same as [1].
-
:app
is an Android lib that depends on:mylibrary
(please modifyapp/build.gradle
to test this scenario):App.java
referencesCreated
andgradle :app:cDJWJ
passes, but the IDE does not resolve symbols. The issue is the same as [1].
==============
[1] is impossible to fix as it'd require adding build/intermediates/javac/debug/classes
as a library. This would cause duplicate symbol definition for every class (as both its *.java and *.class versions would start showing up).
[2] can be solved by configuring kaptGeneratedClasses
library to be exported.
ga...@google.com <ga...@google.com> #9
Scenario [2] from #8 is now fixed in ag/Ia7163b3375eda263cb8cb0fc0ce8d6a0cf181bda. It will be released in the next Studio J canary.
an...@google.com <an...@google.com> #10
Thank you for your patience while our engineering team worked to resolve this issue. A fix for this issue is now available in:
- Android Studio Jellyfish | 2023.3.1 Canary 5
- Android Gradle Plugin 8.4.0-alpha05
We encourage you to try the latest update.
If you notice further issues or have questions, please file a new bug report.
Thank you for taking the time to submit feedback — we really appreciate it!
Description
It looks like kapt generated classes are not added as dependencies to Android and unit test modules. They get their own version of kpat generated libraries but not the one from
main
.