The first step after creating a project is to properly configure the build.gradle and proguard-rules.pro files
Gradle
We like magic right? who doesn’t!
While programming though magic (numbers) are nice when grouped in classes or files all together instead of scattered all around the code base. This applies also to the ones used in the gradle files, that is why in the Project build.gradle we can write the one we’ll need all together
Furthermore, to have files clean and to the point, we can also create a dependencies.gradle file containing the libraries used in the project
Then we can refer to the file from the Project build.gradle with the line
These two tricks combines make then possible to write a Module build.gradle that looks like this
From android gradle plugin 2.2 the support for annotations is granted by the keyword annotationProcessor, whereas before we needed to use the apt-plugin from Hugo Visser
Useful libraries
Of course writing a post about Retrofit and RxJava means dealing with these two main libraries, but there are some other nice libraries which could help us out, namely:
-
Butterknife: Used to bind fields and methods to views
-
Icepick: Used to automate saving and restoring instance state
-
AutoValue: Used for value types classes to remove boilerplate code
ProGuard
ProGuard, we know, is used to obfuscate our code to prevent (or delay) reverse engineering of the app, and is enabled enabling useProguard inside the Module build.gradle
Enabling minifyEnabled instead shrinks the total size of the app pruning unused files and classes and compressing the heck out of them
Since some of the external libraries we use do not work well with complete brute-force obfuscation we need to write these lines in the proguard-rules.pro file otherwise the production version of our app will not build
Next topic will be core classes (MVP architecture)
Leave a Comment