gitignore

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.

tools folder

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

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:

applicationId

versionCode / versionName

server endpoints

google services keys

…

Check out productFlavors in template project.

keystore

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:

expiration date of 365 days

installing application from multiple computers requires uninstalling first

google services require keystore SHA-1 fingerprint

That’s why I usually generate debug keystore and commit it to version control system.

Check out signingConfigs in template project.

proguard

On Android proguard is used for three things:

shrink unused code — helps you to survive the 64k limit

optimize code & APK

obfuscate code — makes your APK difficult to reverse engineer

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:

rules-proguard.pro

rules-proguard-debug.pro

Proguard rules for debug build must have following lines to force proguard ignore warnings, skip code obfuscation and optimization:

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.

Check out rules-proguard.pro and rules-proguard-debug.pro in template project.

strict mode

Android StrictMode helps you to detect different kinds of problems:

closable object is not closed

file reading / network requests performed on main thread

uri exposed

…

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.

Here is example of log when you forgot to close SQLiteCursor: