Is it possible to use guice in android?

Viewed 148

I made a mistake during planning of an Android application and we decided on using Spring in developing core functionality for this project. When we finally ran app on Android, then we realized that Spring is using CGLib under the hood which is not supported in Android.

We are now thinking about migrating to Guice and we wonder if it uses any forbidden techniques like CGLib which could miserably fail on Android. Is there any reason to use RoboGuice other than convenient Android classes? - or is this library specially modified so it can be working with Android?

We are fully aware of the additional memory footprint of Guice.

Cheers.

1 Answers

Android has its own powerful Dependency Injection library called Dagger2(which is kinda like Guice descendant for Android). It is Google supported, there are tons of guides online and supportive community.

Also I would recommend you to use Kotlin for fresh android projects since it is a cutting edge and java project are considered legacy as for now. Also it has few lightweight DI frameworks as Koin or Kodein built specifically for Android.

Regarding Guice - it is an enterprise framework - using it will be a huge overkill and generally is not recommended since in time support cost may be completely insane due to the high learning curve for further devs that will be working of the project, productivity issues(Android is bug prone regarding memory) and lack of tutorial and troubleshooting techniques since it is not very used basically anywhere in open source.

Regarding RoboGuice - it is a nice wrapper for android and you should use it...if you are in 2012 when it was fire. Since 2016 it is deprecated and is not supported anymore. Last meaningful commits were made in 2014.

As I understand you are a Java dev that wants to start with android. Sometimes it makes sense to use familiar tools from javaee in android development but it is wiser to use Android specific stuff.

Hope it helps.

Related