简体   繁体   中英

Is it possible to hide a dependency that is located inside 'libs' folder in aar?

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'

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM