I'm facing an issue in my Android project where I'm trying to use annotations defined in Module B in my code within Module C. However, I'm getting an "Unresolved reference" error in Android Studio. I've tried various configurations, but I'm unable to resolve this issue. Here's my project structure and what I've done so far:
Module B: Annotation processor module containing annotations and an annotation processor. Module A: Android app module that includes Module B as a dependency for annotation processing. Module C: Android app module that includes Module A and aims to use annotations from Module B.
Despite following the outlined steps and confirming the setup, I'm still unable to import and use the annotations from Module B in my code within Module C. The import statement for MyAnnotation in Module C is showing the "Unresolved reference" error.
Any insights into why I'm encountering this issue and how I can resolve it would be greatly appreciated.
Please let me know if there are any additional details I should provide. Thank you in advance for your help!
If you have a dependency such as C depends on A depends on B, using implementation()
to add the dependency will not work. In order to get the transient dependency in the module C you can set api
in the gradle file of A when you specify dependency B, then the classes and method of module B will be available in module C.
Gradle file of module A
api(project(":moduleB")) // moduleB's source will be able with moduleA
Gradle file of Module C
imeplementation(project(":moduleA")) // source of both moduleA and moduleB will be available for module C
However, the best way to specify this would be to add both the dependencies in the module C.
imeplementation(project(":moduleA"))
annotationProcessor(project(":moduleB"))