Android — 15. Optimization Tips&Tricks — 1. part

Jan Turský
2 min readDec 4, 2017

--

  1. Refactor — Remove unused resources -> remove unnecessary dimens, strings, images, colors etc. It could downsize the size of the application about 10 kB, but the project will be much more clean. But be careful, what you are going to remove. Sometimes it could happen, that this feature could offer you to delete files, that are not directly references in the code through „R.“ notation, but like getResources().getIdentifier(“icon_close”, “drawable”, …)
  2. Analyze — Inspect code -> mostly removing unused imports, still makes the code cleaner. But of course, take a note of the others categories, that will display the results.
  3. Convert jpg to WebP (for Android 4.0 and higher), or even better png’s files to WebP (for Android 4.3 and higher)
  4. Remove unused libraries, try to reduce their usage.
  5. vectorDrawables.useSupportLibrary = true — vector images will help you reduce size of the app
  6. material.io/icons — switch for using the TextView filled with this custom Font, that contains more than 900 icons supported by Google Material Icons.
  7. Try to use the latest version of compileSdkVersion, buildToolsVersion, targetSdkVersion
  8. Don’t use the global depencency for the specific library (if it isn’t necessary) like com.google.firebase:firebase-core, but better try to focus only on the library parts, that you will really use like com.google.firebase:firebase-storage
  9. Try to keep the basic structure that was started use massively after Gradle implementation into Android projects, better than the old one used during the age of Eclipse.The modularization of the project will keep the dependency libraries separated in the modules, instead of all source codes inside one directory
  10. Fabric+Crashlytics — use only for the release version. If you want to not go through crashes and bugs in the Fabric system that occurred during the development of the debug version, disable the usage of Fabric in the App declaration like:
CrashlyticsCore crashlyticsCore = new CrashlyticsCore.Builder()
.disabled(BuildConfig.DEBUG)
.build();
Fabric.with(this, new Crashlytics.Builder().core(crashlyticsCore).build());

11. Caching of assets’s typefaces

12. IntDef/StringDef instead of Enums https://developer.android.com/studio/write/annotations.html

13. Bundle — putExtra, putString, etc… — don’t forget, that you can’t send more than 1 MB of data between Activities or Fragments

14. Try to use Tools Attributes in the xml — for example tools:text, tools:listitem, tools:layout, tools:visibility

https://developer.android.com/studio/write/tool-attributes.html

15. Prepare gradle file for compiling of the debug/release with the keystore mentioned in this file. It is much faster to release just with shortcut of „Run“ command instead of Build->Generate Signed APK…

signingConfigs {
release {
storeFile file(“../keystore/keystore.jks”)
storePassword “store_password”
keyAlias “alias_name”
keyPassword “key_password”
}
debug {
storeFile file(“../keystore/keystore.jks”)
storePassword “store_password”
keyAlias “alias_name”
keyPassword “key_password”
}
}
buildTypes {
release {
signingConfig signingConfigs.release
}
debug {
signingConfig signingConfigs.debug
}
}

I will appreciate your comments and ideas, or posts. Thank you and have a nice day.

--

--