Android Java or Kotlin Code Generation with GeneratorApp

As I have 13 applications published in Google Play Store at the moment, a couple of personal projects not in published state, several freelance projects completed I gained some experience on the Android Platform. To have more productivity on it, I added to my tool four options for generating database code and  basic user interfaces code for managing the records of the database models.

The build-in SQL option for working with an Android SQLite Database is a little bit clumsy: https://developer.android.com/training/data-storage/sqlite.html#java
It gives you full power to do whatever you want, but in the same time it is very poor on abstracting the database layer. You have to take care all the details – present and empty in every call API parameters, also all the columns that are retrieved from or passed to the API methods, you have to define every query string and so on.

In the past I have used three Object Oriented Java Libraries for improving my interaction with the Android SQLite Database. Two of them, the more recent ones that I use, are integrated into my GeneratorApp:

  • The first library is OrmLite: http://ormlite.com/. It uses annotations on every data model class for mapping database stuff, it uses Java Reflection API at run-time to map stuff with possibility to optimize – providing a generated during development reflection mapping file. It sets the fields from the objects, it has API to execute most of the more simple queries without adding additional custom stuff.
  • The second library is GreenDao. The models here are clean – plain old java objects. The database specific stuff is encapsulated in data access layer with methods to map the stuff from objects to the database and vise versa that can be reused. It has APIs for the simple CRUD operations.
    When I first started using it, It already had a model and data access code generator. But it needed to code to generate code. My tool has graphical user interface. I used the output that it was generating and made my tool generate the same code, but much more than just model and data access – Activities for listing, viewing and editing the records. I also integrated and I am also generating architectural components recommended by Google. I may add additional stuff that I encounter with any next project that is not specific to some domain.
  • The third ORM library i’ve used is the one recomended by Google – Room. It pollutes the models and the data access objects with annotations but it tries to take care of the details by checking and implementing the stuff at compile time (The DAO Layer is actually Java Interfaces) minimizing length of the code of the application developers . It forces us to minimize the database complexity as much as we can. For more advanced stuff I personally will probably prefer one of the other options.

So The four options for generating Android Code that I have implemented in my GeneratorApp are:

  • GreenDao with Java
  • GreenDao with Kotlin (currently not working because of the way static fields are generated on byte-code level and missing Object Oriented methods to overwrite the GreenDao settings.
  • Room with Java
  • Room with Kotlin

My personal To-Do for the Android Generators is improve a little bit the generated UI and add some more architectural components. If you use other data access technology or have an idea about some other components, you could contact me and I’ll try to add them so it helps you get started and completed your projects faster.

Share
Add comment