This article is a part of Configuring Android Project series:
Everything we have discussed in current article is available in template project.
When you create a new android project in Android Studio it already comes up with gitignore file, but usually it does not contain all necessary rules.
To quickly generate and download gitignore files I recommend you to use gitignore.io site. Just type in necessary keywords like — Android, Intellij and click generate button.
Check out gitignore file in template project.
If you have some 3rd party scripts, rulesets or other files which are related to your project don’t just drop them in root directory — it will create a mess.(especially for those who are using Project View, not Android View)
Try to create a folder (e.g. tools) and put all those files into this folder.
Usually I put there custom gradle scripts files, rules for proguard and static code analysis tools like pmd, findbugs, lint.
Check out tools folder in template project.
Flavors are used to create builds with different set-up. In most cases I immediately set-up two flavors — dev and prod which have different:
<a href="https://medium.com/media/150ffe9e2eac6e98f04e23425871a4a7/href">https://medium.com/media/150ffe9e2eac6e98f04e23425871a4a7/href</a>
Check out productFlavors in template project.
A keystore is a binary file that contains one or more private keys used to sign your application.
When running or debugging your project from the IDE, Android Studio automatically signs your APK with a debug certificate generated by the Android SDK tools.
There are several issues when using local debug keystore:
That’s why I usually generate debug keystore and commit it to version control system.
<a href="https://medium.com/media/7d4160e8568fb62440027f97bd777ee0/href">https://medium.com/media/7d4160e8568fb62440027f97bd777ee0/href</a>
Check out signingConfigs in template project.
On Android proguard is used for three things:
The problem is that obfuscation and code optimization significantly increase compilation time and make debugging harder.
That’s why it is better to use different proguard rules for release and debug build:
<a href="https://medium.com/media/cbe51bd728c582af5c1df256ac72b760/href">https://medium.com/media/cbe51bd728c582af5c1df256ac72b760/href</a>
Proguard rules for debug build must have following lines to force proguard ignore warnings, skip code obfuscation and optimization:
<a href="https://medium.com/media/c3d6ea14f4008e3de0f5ee2205dd4ae2/href">https://medium.com/media/c3d6ea14f4008e3de0f5ee2205dd4ae2/href</a>
For release version it will be much harder to setup proguard rules, because almost every library has it’s own specific rules. Fortunately there is open source repository called — android-proguard-snippets which contains proguard rules for all major libraries.
<a href="https://medium.com/media/7a10e36468e5b5690187ce6d02c1fcec/href">https://medium.com/media/7a10e36468e5b5690187ce6d02c1fcec/href</a>
Check out rules-proguard.pro and rules-proguard-debug.pro in template project.
Android StrictMode helps you to detect different kinds of problems:
Whenever such problem is detected it can show you appropriate log or crash your application, depending on your configuration.
I suggest you to turn it on only for debug build and use detectAll methods to detect all kind of problems.
<a href="https://medium.com/media/e507e64b63df84012de67395421b43f3/href">https://medium.com/media/e507e64b63df84012de67395421b43f3/href</a>
Here is example of log when you forgot to close SQLiteCursor:
<a href="https://medium.com/media/865507608541eeb989184fb6a8612c92/href">https://medium.com/media/865507608541eeb989184fb6a8612c92/href</a>
Check out StrictMode in template project.