1

To give you the context of what I want to accomplish I will describe my project structure first:

Application
|
| - Library Module
|   |
|   | - Core Library Module
|       | Module 1
|       |- Jar dependency 1
|       |
|       | Module 2
|       |- Jar dependency 2

Module 1 and 2 where created to contain 2 jar files created by the shadow gradle plugin to relocate dagger 2 dependencies. This is done because the application uses Dagger 1 and they cannot be used at same time in regular bases.

Core library Module contains the core functionality for different libraries and that is why is a separate library, it also uses dagger 2 for Dependency injection.

Library Module contains the functionality we offer to the applications from our clients it also uses dagger 2 for dependency injection.

Now the real problem is the application because it uses Dagger 1 for dependency injection. So with the shadowed jars it it possible to use dagger 1 and 2 in the same project because shadow renames and relocates all the classes that dagger 2 uses to for example @Inject to @Inject2.

In the libraries everything works as expected because I use the relocated and renamed classes Like @Module2, @Inject2, etc.

but in the application that I use dagger 1 the tags are @Inject, @Module as is normally used in dagger 1. As the dependency imported in my build.gradle is Dagger1. But when I build the application I get and error indication that I also have to add the modified Dagger 2 tags like @Module2, @Inject2. And That is exactly what I dont want.

Is there any way to hide or ignore those dependencies using gradle so the application can't see the modified jars for dagger 2 but they can still be used in the libraries?

So far the only solution I have is to remove Dagger 2 from the library and implement the dependency injection by myself but that is time consuming and not exactly what I want

Edit:

complete error:

Error:(25, 8) error: com.sample.model.ApplicationModule is listed as a module, but is not annotated with @Module2

Edit 2:

  relocate 'javax.inject.Inject', 'javax.inject.Inject2'
  relocate 'javax.inject.Named', 'javax.inject.Named2'
  relocate 'javax.inject.Provider', 'javax.inject.Provider2'
  relocate 'javax.inject.Qualifier', 'javax.inject.Qualifier2'
  relocate 'javax.inject.Scope', 'javax.inject.Scope2'
  relocate 'javax.inject.Singleton', 'javax.inject.Singleton2'
  relocate 'dagger.Lazy', 'dagger.Lazy2'
  relocate 'dagger.MembersInjector', 'dagger.MembersInjector2'
  relocate 'dagger.Module', 'dagger.Module2'
  relocate 'dagger.Provides', 'dagger.Provides2'
  relocate 'dagger.Provides$Type', 'dagger.Provides$Type2'
  relocate 'dagger.internal', 'dagger.internal2'
  relocate 'dagger.producers', 'dagger.producers2'
  relocate 'dagger.Component', 'dagger.Component2'
Cœur
  • 37,241
  • 25
  • 195
  • 267
acabezas
  • 731
  • 1
  • 7
  • 20
  • I updated the question with the complete error, but it is not very useful – acabezas Sep 05 '16 at 13:42
  • Have you renamed or used the correct `@Component` annotation referencing `ApplicationModule.class`? – tynn Sep 05 '16 at 13:51
  • Yes, actually the idea is the app doesn't need to know that i have renamed the dagger 2 libraries, so The application is using all the annotations as are usually used with dagger 1 – acabezas Sep 05 '16 at 13:56
  • Let me rephrase the question. `ApplicationModule` seems to be a dagger 1 module. The error seems to come from dagger 2. Have you taken care of the annotation processor and `@Component` completely? Dagger 2 tries to compile the dagger 1 components and obviously fails. – tynn Sep 05 '16 at 14:04
  • you are correct, I checked the jar files generated by shadow and it didn't remaned the @component Annotation. I will check the Script that renames the clases. Thanks a lot! – acabezas Sep 05 '16 at 14:07

1 Answers1

0

ApplicationModule seems to be a dagger 1 module. The error seems to come from dagger 2. So obviously the dagger 2 annotation processor operates on the non renamed @Component. You need to make sure the processor only operates on dagger 2 components.

tynn
  • 38,113
  • 8
  • 108
  • 143
  • You were right, I was missing to rename the @component annotation, I renamed but i still get the error. I added the script i am using to rename the classes, can you tell me what am i missing? – acabezas Sep 05 '16 at 14:44
  • You need to process the [compiler](https://github.com/google/dagger/tree/master/compiler). Maybe this helps a bit http://fernandocejas.com/2016/08/03/android-dagger-1-and-2-living-together/ – tynn Sep 05 '16 at 14:59