Articles > Version 0.8.0

Version 0.8.0

Shortly after I finished the transition to dependency injection using the guice framework I found out that it’s reflection abilities were not supported on android.


I tried for a few weeks to find an official answer on why it would not work on android without success. This was confusing as I read on multiples stackoverflow questions that some people were using guice in their android project.


Anyway I decided to keep moving forward and to use this opportunity to learn about Dagger2 which is yet another dependency injection framework. Unlike the more conventional one Dagger2 do not use reflection. It is based on code generation at compile time.


The advantage is the performance gains since there is no reflection involved but at the cost of a setup a bit more tedious and a bit less flexible.


I am not going to lie it was incredibly unpleasant and non intuitive at first. Hopefully I had already laid down the new architecture with DI in mind using guice so it was mostly a replacing of the DI framework rather than a refactor of the code. Even tough as I said before since it is less flexible I had to adapt some small part of the code. After 2 weeks I managed to entirely replace guice.


To give you an idea on why DI is a huge benefit lets talk about numbers. The source code of my project is now divided in two parts:


  • Hand written code

  • Dagger generated code


The hand written part is approximately 41k LOC and the generated part is 14k LOC. This mean that the generated part represent 34% of the hand written part which is huge and I am not even mentioning the fact that this generated code need to change every time I change the dependencies of an object so its not like it is generated once and then set in stone. Hopefully now you start to understand why using DI in a big project is a game changer. Life is too short to write factories...


Now that the game work on android I noticed that I still have some work to do on the viewport to better supports devices with different aspect ratio. Once I’m done with it I will release an apk on the play store.


See you next time.



Edit: The evening after I posted this article I got a response on my stackoverflow question about the guice incompatibility with android. It turned out since android do not support byte code generation, which is used in guice for performance reason, we need to import a different flavour of guice called no-aop. Using this version fix the issue I had on android but since I already moved on to dagger2 which has no runtime performances cost I’ll keep moving forward.





Published on: 11/05/2020 in Devblog