lightsaber
lightsaber copied to clipboard
Using Lightsaber to inject dependencies into AAR libraries
Hello!
I have a question regarding using Lightsaber to push dependencies into AAR libraries.
My setup is, I have an application, and several libraries it relies on, in one project, the libraries being submodules.
What I'm doing is, I've wrapped a Lightsaber "Injector" instance into a generic interface, that I've pushed down to the libraries, so that they can then call "injector.injectMembers(this)" to init their @Inject annotated fields.
Which is working fine, as long as I'm in one project, and the libraries are submodules. However, if I build the libraries as AAR-s, and pull them into the app like that, so they are not submodules anymore, the whole thing stops working.
I've checked the "InjectionDispatcher" class in the "transformClassesWithLightsaberForDebug" folder, and it simply doesn't call "membersInjectors.put()" on the classes from the libraries. My guess is that it only scans app source, and not the source coming from AAR-s.
I've tried with a completely runtime injector (https://github.com/zsoltherpai/feather) and the same setup works fine there. However I really like the fact that Lightsaber doesn't even compile if there are unsatisfied dependencies, so I'd prefer to stick to your library if possible.
Is there anything else I need to do with my libraries to get them working in AAR form aswell? Or is this a use-case that is not supported?
Thanks for the help in advance!
Hi @tpasztor and thank you for reporting this issue. Lightsaber doesn't really support this case at the moment. I'm not sure that injection into external dependencies is a good idea but it seems to be quite easy to implement. Unfortunately this change will make compilation slower so it should be opt-in.
I think I'll try to implement this feature in the nearest future but until that moment the only workaround is to use your libraries as submodules.
@MichaelRocks Hello! Well yes, I normally agree that it doesn't sound like a good idea to do. 🙂
What we have is a fairly specific use case, where we have a few projects, on which separate teams work in separate repositories. But these projects share large chunks of code, complete pages and such. These shared parts we distribute as libraries in our private maven repo. We've been passing down config and dependencies to these libraries manually so far, but it is getting more and more cumbersome, so we figured it'd make sense to explore some libraries that could help deal with this issue for us. 🙂
Thanks for the quick reply, and for checking this out for me!
+1 would be nice to have it.
+1 need it for support