RoboGuice: Using full reflection. Try using the RoboGuice annotation processor for better performance

When I run the RoboGuice Android app, the following message appears in the logs:

roboguice.RoboGuice: using full reflection. Try using the RoboGuice annotation processor for best performance.

What does it mean?

All my activities (including my MainActivity) are propagated to RoboGuice classes. Perhaps I am missing something and there is a way to improve the performance of RoboGuice which I am not doing right now.

Note. I am using RoboBlender

+3


source to share


3 answers


RoboGuice is based on the Google Guice library, which is a reflection-based dependency injection framework. Unfortunately Guice doesn't work well on Android. For example, in my last project, it took 1 to 1.5 seconds to initialize the injector.

At some point the developer RoboGuice decided to improve the performance of his library by doing some work at compile time and about what RoboBlender is. It creates an annotation database at compile time and RoboGuice uses this database at runtime to find injection points. You can read more about RoboBlender here . This approach required a lot of changes in Guice, so the author of RoboGuice had to fork it and even sent a pull request to Guice. But this PR was rejected mainly because it contradicts the idea of ​​the Guice library (as a DI framework).



Sorry for such a long introduction and here is the answer to your question. When called, RoboGuice.setUseAnnotationDatabases(false)

you are asking RoboGuice to handle everything at runtime through reflection. In other words, RoboGuice works just like the original Guice, and it's not very fast. When you try to use annotation databases and application crashes, it can happen because the annotation databases cannot be found. Maybe you forgot to add <meta-data android:name="roboguice.annotations.packages" android:value="..."/>

in AndroidManifest.xml

?

Finally, I would not recommend using Guice or RoboGuice on Android because the former is very slow and the latter is broken by design. It is much better to use a compile time DI library like Dagger and it doesn't take long to switch.

+1


source


Now Roboguice has migrated to version 4.0.0. This is available on github as a branch rg-4-final

. In gradle, you can use it like

compile 'org.roboguice:roboguice:4.0.0'
provided 'org.roboguice:roboblender:4.0.0'

      

I had problems getting Roboblender to work before, but in 4.0.0 it works like a charm.

However, there are changes. Take a look at Astroboy's example on how to use it. You are no longer expanding activities or fragments, you inject members into each one like this:



RoboGuice.getInjector(this).injectMembers(this);

      

They ditched @InjectView

and @InjectResource

now you use Butterknife to inject views and resources that you get in the normal Android way. Don't forget to initialize Roboguice in your application:

RoboGuice.setupBaseApplicationInjector(this, new MyModule(), new OtherModule());

      

Enjoy!

+2


source


I recommend using an oil knife. It's much easier if you are using android studio, it also has a plugin that allows you to generate automatic renderings just once:

helpful documentation: https://github.com/avast/android-butterknife-zelezny

-3


source







All Articles