Cheatsheet about tips and tricks for Android Development
This is a simple set of tips and tricks regarding Android Development which I have gathered from various sources. It helps me direct other android devs in my community regarding stuff each android dev should know about. Its also there for me to keep track of anything I either learn on my own or from other sources now and then when browsing the internet.
Contributions are always welcome, hoping people will help me in growing this. To contribute, simply open up a PR with the changes.
###Know Your Tools
####Android Studio
-
Code faster by using keyboard shortcuts
Description Mac Linux/Win Open Class Cmd
+O
Ctrl
+O
Open File Cmd
+Shift
+O
Ctrl
+Shift
+N
Open recently edited file Cmd
+Shift
+E
Ctrl
+Shift
+E
Lookup Actions Cmd
+Shift
+A
Ctrl
+Shift
+A
Open Symbol Cmd
+Opt
+O
Alt
+Shift
+N
Open recently used file Cmd
+E
Ctrl
+E
Last Edited Location Cmd
+Shift
+Backspace
Ctrl
+Shift
+Backspace
Find Usage in persistent window Opt
+F7
Alt
+F7
Find Usage in floating window Cmd
+Opt
+F7
Ctrl
+Alt
+F7
Format the code with proper Indentation Cmd
+Opt
+L
Ctrl
+Alt
+L
Surround With Opt
+Cmd
+T
Alt
+Ctrl
+T
Open Terminal Opt
+F12
Alt
+F12
-
Use plugins to become more efficient
The plugin basically will annoy the hell out of you by showing you a big screen overlay with the key combination you should have used , if you used your mouse to execute some command to a level when you basically would start using the key combination just to avoid KeyPromoter annoying you all the time. Its also is useful features, like it will prompt you to create a key binding for a command which does not have a key binding and you have used it 3 times.
-
Use the Darcula Theme in Android Studio Ok, I know its more like a preference , but trust me using that keeps your eyes less strained as they would be if you used the Default Light theme.
-
Don't use a small font Preferably use a font in Android Studio thats easy to read and is at a font size which doesnot forces you to strain your eyes. I use Menlo font.
-
Use a code style You should use a standard codestyle So possible contenders can be
-
Use the Memory/Network/CPU Monitor inside Android Studio to profile your code/app
####Emulator Apart from using physical devices , one should use emulators as they are as of now easy to manage and equivalently powerful.
###Make better choices while coding
-
Use OkHttp over HttpUrlConnect HttpUrlConnect suffers from quite some bugs. Okhttp solves them in a more elegant manner. [Reference Link]
-
Use Pidcat for logging
-
Use some Version Control System(VCS) like Git
-
Use ClassyShark Its a standalone tool for Android Devs used to browse any Android executable and show important info such as class interfaces and members, dex counts and dependencies
-
Use Stetho Debug your android apps using Chrome Dev Tools.
-
Use Battery Historian A tool to analyze battery consumers using Android "bugreport" files.
-
Always use a constant version value like "24.1.1" Avoid using
+
when specifying the version of dependencies.- Keeps one secured from unexpected API changes in the dependency.
- Avoids doing an extra network call for the checking latest version of each dependency on every build.
-
Do not use your own personal email for Google Play Developer Account
-
Use Vectors instead of PNG If you do have to use png, compress them. Take a look at TinyPNG.
-
Use proguard
android { ... buildTypes { release { minifyEnabled true proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } }
}
+ **Use shrinkResources**
```gradle
android {
...
buildTypes {
release {
shrinkResources true
minifyEnabled true
...
}
}
}
-
Simulating Android killing your app in the background, run in terminal
adb shell am kill
-
Follow the below rule to have faster gradle builds
Gradle memory >= Dex memory + 1Gb
-
Split your apk using gradle when using Native code, do not bundle all of em together and ship!.. coz that will make you evil
defaultConfig { ... ndk { abiFilters "armeabi", "armeabi-v7a", "mips", "x86" } } //Split into platform dependent APK splits { abi { enable true reset() include 'armeabi', 'armeabi-v7a', 'mips', 'x86' //select ABIs to build APKs for universalApk false //generate an additional APK that contains all the ABIs } } // map for the version code project.ext.versionCodes = ['armeabi': 1, 'armeabi-v7a': 2, 'mips': 5, 'x86': 8] // Rename with proper versioning android.applicationVariants.all { variant -> // assign different version code for each output variant.outputs.each { output -> output.versionCodeOverride = project.ext.versionCodes.get(output.getFilter(com.android.build.OutputFile.ABI), 0) * 1000000 + android.defaultConfig.versionCode } }
-
Learn about some architecture such as MVP or Clean
-
Try to understand and follow TDD (Test Driven Development)
-
Follow the DRY principle DRY = Do not Repeat Yourself
-
Learn about Dependency Resolution With the speed android dependencies update, sooner or later you are going to encounter some sort of dependency conflict. Solution is making use of Dependency Resoultion. Official Reference
###Other Resources
-
Listen to podcasts
There are others too, but the above two are the popular ones, you can lookup more using tag
android
on sites offering Podcast Services.P.S : I use Player.fm to listen to these podcasts. They even have an Android Client , all for FREE.
-
Checkout new android libraries Android Arsenal
-
Follow on Twitter
-
Create a List on Twitter
-
Bookmark these sites for staying upto date
- Android Developers - Youtube Channel
- Android Niceties - UI Showcase
- Material Design Specs
- Platform Version Distribution
- Android Studio Release Notes
- Android Developers Blog
- AndroidDev-Reddit
- Github Trending Java Projects
- Stackoverflow-Android tag
- Support Library History
- Android Conferences
- Android Dev Docs
- Material Up - DesignShowcase
- Dribbble - MaterialDeisgnShowcase
-
Use freely available mockable api points
- Mockey - A tool for testing application interactions over http, with a focus on testing web services, specifically web applications that consume XML, JSON, and HTML.
- JSON Placeholder - Fake Online REST API for Testing and Prototyping
- API Studio - a playground for API developers
- Mocky - Mock your HTTP responses to test your REST API
- Mockbin - Mockbin allows you to generate custom endpoints to test, mock, and track HTTP requests & responses between libraries, sockets and APIs.
-
Subscribe to newsletters to stay upto date
- EasyDeviceInfo - Enabling device information to be at android developers hand like a piece of cake!
- Sensey - Android library to make detecting gestures easy
- PackageHunter - Android library to hunt down package information
- Zentone - Easily generate audio tone in android
- RecyclerViewHelper - RecyclerViewHelper provides the most common functions around recycler view like Swipe to dismiss, Drag and Drop, Divider in the ui, events for when item selected and when not selected, on-click listener for items.
- StackedHorizontalProgressbar - Android Library to implement stacked horizontal progressbar
- QREader - A library that uses google's mobile vision api and simplify the QR code reading process
- ScreenShott - Simple library to take a screenshot of the device screen , programmatically!
- EvTrack - Android library to make event and exception tracking easy
- OptimusHTTP - Android library that simplifys networking in android via an async http client
- ShoutOut - Android library for logging information in android
####Credits Some of the tips and tricks are something I have been following in my workflow and some of them have been from various other sources. I have tried to add direct links wherever I could remember, giving people due credit who have explained the concepts. If you think I have missed any , then either send a PR or open an issue and I will fix it asap.
Copyright 2016 Nishant Srivastava
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.