effective android development
TRANSCRIPT
![Page 1: Effective Android Development](https://reader031.vdocuments.mx/reader031/viewer/2022021921/58ef81381a28abf9768b461f/html5/thumbnails/1.jpg)
EFFECTIV E
ANDROID
DEVELOPMENT
S E R G I I Z H U K @ D R O I D C O N B E R L I N
1 6 - 0 6 - 2 0 1 6
![Page 2: Effective Android Development](https://reader031.vdocuments.mx/reader031/viewer/2022021921/58ef81381a28abf9768b461f/html5/thumbnails/2.jpg)
2
HELLO!
My name is Sergii Zhuk
• Android Developer @ Zalando SE
• Author of Android Digest for Ukrainian Developers Community
• In Berlin since August 2015
• twitter.com/sergiizhuk
• medium.com/@sergii
![Page 3: Effective Android Development](https://reader031.vdocuments.mx/reader031/viewer/2022021921/58ef81381a28abf9768b461f/html5/thumbnails/3.jpg)
3
ZALANDO SE
• Europe’s leading online fashion platform
• ~ 10,000 employees in Europe
• ~ EUR 3bn revenue in 2015
• ~ 60% of shop traffic came from mobile
• 10M+ downloads Android app
![Page 4: Effective Android Development](https://reader031.vdocuments.mx/reader031/viewer/2022021921/58ef81381a28abf9768b461f/html5/thumbnails/4.jpg)
4
AGENDA
• Android Studio
• Test Devices
• Dev & Environment
• Gradle Hacks
![Page 5: Effective Android Development](https://reader031.vdocuments.mx/reader031/viewer/2022021921/58ef81381a28abf9768b461f/html5/thumbnails/5.jpg)
5
ANDROID STUDIO
![Page 6: Effective Android Development](https://reader031.vdocuments.mx/reader031/viewer/2022021921/58ef81381a28abf9768b461f/html5/thumbnails/6.jpg)
6
ANDROID STUDIO – T IP 1
How does your manifest really look like?
![Page 7: Effective Android Development](https://reader031.vdocuments.mx/reader031/viewer/2022021921/58ef81381a28abf9768b461f/html5/thumbnails/7.jpg)
7
ANDROID STUDIO – T IP 1
How does your manifest really look like?
• Manifest Merger
See also: “Hey, Where Did These Permissions Come From?” on The CommonsBlog
![Page 8: Effective Android Development](https://reader031.vdocuments.mx/reader031/viewer/2022021921/58ef81381a28abf9768b461f/html5/thumbnails/8.jpg)
8
ANDROID STUDIO – T IP 2
You need to use new Android APIs. Are there any examples?
![Page 9: Effective Android Development](https://reader031.vdocuments.mx/reader031/viewer/2022021921/58ef81381a28abf9768b461f/html5/thumbnails/9.jpg)
9
ANDROID STUDIO – T IP 2
You need to use new Android APIs. Are there any examples?
• Find Sample Code
![Page 10: Effective Android Development](https://reader031.vdocuments.mx/reader031/viewer/2022021921/58ef81381a28abf9768b461f/html5/thumbnails/10.jpg)
10
ANDROID STUDIO – T IP 3
“I’m not gonna to commit right now…”
![Page 11: Effective Android Development](https://reader031.vdocuments.mx/reader031/viewer/2022021921/58ef81381a28abf9768b461f/html5/thumbnails/11.jpg)
11
ANDROID STUDIO – T IP 3
“I’m not gonna to commit right now…”
Local history for rescue!
![Page 12: Effective Android Development](https://reader031.vdocuments.mx/reader031/viewer/2022021921/58ef81381a28abf9768b461f/html5/thumbnails/12.jpg)
12
ANDROID STUDIO – T IP 4
Support Annotations are your friends
![Page 13: Effective Android Development](https://reader031.vdocuments.mx/reader031/viewer/2022021921/58ef81381a28abf9768b461f/html5/thumbnails/13.jpg)
13
ANDROID STUDIO – T IP 4
Support Annotations are your friends
• Metadata annotations you can decorate your code with, to help catch bugs
• @VisibleForTesting, @Nullable, @AnyThread, @Keep, @StringRes etc.
• Integrated with Android Studio & Lint
![Page 14: Effective Android Development](https://reader031.vdocuments.mx/reader031/viewer/2022021921/58ef81381a28abf9768b461f/html5/thumbnails/14.jpg)
14
ANDROID STUDIO – T IP 5
How to make a code review?
Switch between branches could be slow:
•stash your changes
•checkout branch
• reload gradle config
![Page 15: Effective Android Development](https://reader031.vdocuments.mx/reader031/viewer/2022021921/58ef81381a28abf9768b461f/html5/thumbnails/15.jpg)
15
ANDROID STUDIO – T IP 5
How to make a code review?
• Launch two IDE instances: one for the review, another one for the main work
• Yes, you will need a powerful machine
![Page 16: Effective Android Development](https://reader031.vdocuments.mx/reader031/viewer/2022021921/58ef81381a28abf9768b461f/html5/thumbnails/16.jpg)
16
ANDROID STUDIO – T IP 6
Apply changes fast
![Page 17: Effective Android Development](https://reader031.vdocuments.mx/reader031/viewer/2022021921/58ef81381a28abf9768b461f/html5/thumbnails/17.jpg)
17
ANDROID STUDIO – T IP 6
Swap code fast
• Instant Run
• JRebel
![Page 18: Effective Android Development](https://reader031.vdocuments.mx/reader031/viewer/2022021921/58ef81381a28abf9768b461f/html5/thumbnails/18.jpg)
18
ANDROID STUDIO – T IP 6
Swap code fast
• How changes are handled
• Immediately (Hot swap)
• Activity restart (Warm swap)
• Application restart (Cold swap)
• Rebuild
![Page 19: Effective Android Development](https://reader031.vdocuments.mx/reader031/viewer/2022021921/58ef81381a28abf9768b461f/html5/thumbnails/19.jpg)
19
ANDROID STUDIO – T IP 6
Swap code fast
Change Instant Run JRebel
Change code of the existing method Could be immediately Activity restart
Change/remove resource Activity restart Activity restart
Method or class signature, statics, annotations App restart, API 21+ Activity restart
Add/Remove superclass, implemented interface App restart, API 21+ App restart
Change Manifest or notification resource Rebuild Rebuild
Sources: https://developer.android.com/studio/run/index.html#instant-run
Reto Meier "Instant Run: How Does it Work?!"
Oleg Selajev "Looking at JRebel for Android and Instant Run ..."
![Page 20: Effective Android Development](https://reader031.vdocuments.mx/reader031/viewer/2022021921/58ef81381a28abf9768b461f/html5/thumbnails/20.jpg)
20
TEST DEVICES
![Page 21: Effective Android Development](https://reader031.vdocuments.mx/reader031/viewer/2022021921/58ef81381a28abf9768b461f/html5/thumbnails/21.jpg)
21
TEST DEVICES – T IP 1
A lot of UI issues could be discovered if compare app on Lollipop and pre-Lollipop
devices
![Page 22: Effective Android Development](https://reader031.vdocuments.mx/reader031/viewer/2022021921/58ef81381a28abf9768b461f/html5/thumbnails/22.jpg)
22
TEST DEVICES – T IP 1
A lot of UI issues could be discovered if compare app on Lollipop and pre-Lollipop
devices
• Use at least two emulator instances or devices during dev tests
• Use both 4.* and 5+ OS versions
![Page 23: Effective Android Development](https://reader031.vdocuments.mx/reader031/viewer/2022021921/58ef81381a28abf9768b461f/html5/thumbnails/23.jpg)
23
TEST DEVICES – T IP 2
Emulators question
![Page 24: Effective Android Development](https://reader031.vdocuments.mx/reader031/viewer/2022021921/58ef81381a28abf9768b461f/html5/thumbnails/24.jpg)
24
TEST DEVICES – T IP 2
Emulators question
Genymotion
• Free only for private use & limited functionality
• Latest OS version with the delay
![Page 25: Effective Android Development](https://reader031.vdocuments.mx/reader031/viewer/2022021921/58ef81381a28abf9768b461f/html5/thumbnails/25.jpg)
25
TEST DEVICES – T IP 2
Emulators question
Genymotion
• Free only for private use & limited functionality
• Latest OS version with the delay
New Android SDK Emulator
• push apps/data 10x faster than to a device
• includes Google Play Services built-in
![Page 26: Effective Android Development](https://reader031.vdocuments.mx/reader031/viewer/2022021921/58ef81381a28abf9768b461f/html5/thumbnails/26.jpg)
26
TEST DEVICES – T IP 3
(Cloud) Test Platforms
![Page 27: Effective Android Development](https://reader031.vdocuments.mx/reader031/viewer/2022021921/58ef81381a28abf9768b461f/html5/thumbnails/27.jpg)
27
TEST DEVICES – T IP 3
(Cloud) Test Platforms
• Can execute scenarios (Espresso tests, Robotium etc.)
• Can take screenshots, measure device metrics, track logs
• Example: AWS Device Farm, TestDroid, Firebase Test Lab
![Page 28: Effective Android Development](https://reader031.vdocuments.mx/reader031/viewer/2022021921/58ef81381a28abf9768b461f/html5/thumbnails/28.jpg)
28
TEST DEVICES – T IP 3
(Cloud) Test Platforms
• Also you can create your own device farm
• Open-source tools available like Square Spoon
![Page 29: Effective Android Development](https://reader031.vdocuments.mx/reader031/viewer/2022021921/58ef81381a28abf9768b461f/html5/thumbnails/29.jpg)
29
DEV & ENVIRONMENT
![Page 30: Effective Android Development](https://reader031.vdocuments.mx/reader031/viewer/2022021921/58ef81381a28abf9768b461f/html5/thumbnails/30.jpg)
30
DEV & ENVIRONMENT – T IP 1
Measure execution time
![Page 31: Effective Android Development](https://reader031.vdocuments.mx/reader031/viewer/2022021921/58ef81381a28abf9768b461f/html5/thumbnails/31.jpg)
31
DEV & ENVIRONMENT – T IP 1
Measure execution time
• Hugo by Jake Wharton
@DebugLog
public String getName(String first, String last) {/* ... */}
V/Example: --> getName(first="Jake", last="Wharton")
V/Example: <-- getName [16ms] = "Jake Wharton"
![Page 32: Effective Android Development](https://reader031.vdocuments.mx/reader031/viewer/2022021921/58ef81381a28abf9768b461f/html5/thumbnails/32.jpg)
32
DEV & ENVIRONMENT – T IP 2
How to read logcat output from your device?
![Page 33: Effective Android Development](https://reader031.vdocuments.mx/reader031/viewer/2022021921/58ef81381a28abf9768b461f/html5/thumbnails/33.jpg)
33
DEV & ENVIRONMENT – T IP 2
How to read logcat output from your device?
• Jake Wharton’s pidcat
![Page 34: Effective Android Development](https://reader031.vdocuments.mx/reader031/viewer/2022021921/58ef81381a28abf9768b461f/html5/thumbnails/34.jpg)
34
DEV & ENVIRONMENT – T IP 3
Click on device/emulator screen every time you are testing some functionality
• BUT what if you have 5 test devices?
• AND you have a regression plan for 30 scenarios?
![Page 35: Effective Android Development](https://reader031.vdocuments.mx/reader031/viewer/2022021921/58ef81381a28abf9768b461f/html5/thumbnails/35.jpg)
35
DEV & ENVIRONMENT – T IP 3
Click on device/emulator screen every time you are testing some functionality
• Use ADB commands/scripts to replace manual interactions
adb shell input keyevent 4
![Page 36: Effective Android Development](https://reader031.vdocuments.mx/reader031/viewer/2022021921/58ef81381a28abf9768b461f/html5/thumbnails/36.jpg)
36
DEV & ENVIRONMENT – T IP 3 .5
Click on device/emulator screen every time you are testing some functionality
• Use adb-ninja script to submit your command to several devices simultaneously
https://github.com/romannurik/env/blob/master/bin/ninja-adb
![Page 37: Effective Android Development](https://reader031.vdocuments.mx/reader031/viewer/2022021921/58ef81381a28abf9768b461f/html5/thumbnails/37.jpg)
37
DEV & ENVIRONMENT – T IP 4
Think about application tracking & analytics
![Page 38: Effective Android Development](https://reader031.vdocuments.mx/reader031/viewer/2022021921/58ef81381a28abf9768b461f/html5/thumbnails/38.jpg)
38
DEV & ENVIRONMENT – T IP 4
Think about application tracking & analytics
• A lot of projects with overlapping functionality:
• Google Analytics
• Firebase Analytics
• Adjust
• Answers Events by Fabric
• Integration requires huge architecture effort
• Testing is always hard
![Page 39: Effective Android Development](https://reader031.vdocuments.mx/reader031/viewer/2022021921/58ef81381a28abf9768b461f/html5/thumbnails/39.jpg)
39
DEV & ENVIRONMENT – T IP 5
Network output logging/analyzing?
![Page 40: Effective Android Development](https://reader031.vdocuments.mx/reader031/viewer/2022021921/58ef81381a28abf9768b461f/html5/thumbnails/40.jpg)
40
DEV & ENVIRONMENT – T IP 5
Network output logging/analyzing
Use Http Monitoring & Proxy tools like Charles
• HTTP/HTTPS traffic monitoring
• Rewrite values
• Set breakpoints
![Page 41: Effective Android Development](https://reader031.vdocuments.mx/reader031/viewer/2022021921/58ef81381a28abf9768b461f/html5/thumbnails/41.jpg)
41
DEV & ENVIRONMENT – T IP 6
All-in-one inspection tool by Facebook?
![Page 42: Effective Android Development](https://reader031.vdocuments.mx/reader031/viewer/2022021921/58ef81381a28abf9768b461f/html5/thumbnails/42.jpg)
42
DEV & ENVIRONMENT – T IP 6
All-in-one inspection tool by Facebook!
• Stetho
• SQLite database
• Network proxy
• Hierarchy Viewer
• App preferences
![Page 43: Effective Android Development](https://reader031.vdocuments.mx/reader031/viewer/2022021921/58ef81381a28abf9768b461f/html5/thumbnails/43.jpg)
43
DEV & ENVIRONMENT – T IP 7
Explore your APK
• Manifest
• Method count per dependency
• Resources set properly
• and more
![Page 44: Effective Android Development](https://reader031.vdocuments.mx/reader031/viewer/2022021921/58ef81381a28abf9768b461f/html5/thumbnails/44.jpg)
44
DEV & ENVIRONMENT – T IP 7
Explore your APK:
ClassyShark
• DEX Method count by package/class
• Dependencies
• Merged Manifest
• Obfuscation check
Android Studio APK Analyzer
+ Drawables preview
![Page 45: Effective Android Development](https://reader031.vdocuments.mx/reader031/viewer/2022021921/58ef81381a28abf9768b461f/html5/thumbnails/45.jpg)
45
GRADLE HACKS
![Page 46: Effective Android Development](https://reader031.vdocuments.mx/reader031/viewer/2022021921/58ef81381a28abf9768b461f/html5/thumbnails/46.jpg)
46
GRADLE HACKS – T IP 1
Check your config
![Page 47: Effective Android Development](https://reader031.vdocuments.mx/reader031/viewer/2022021921/58ef81381a28abf9768b461f/html5/thumbnails/47.jpg)
47
GRADLE HACKS – T IP 1
Check your config
build.gradle:
• Get rid of mavenCentral, use jcenter
• Check Gradle plugin version
• DON’T specify version ranges for the dependencies
![Page 48: Effective Android Development](https://reader031.vdocuments.mx/reader031/viewer/2022021921/58ef81381a28abf9768b461f/html5/thumbnails/48.jpg)
48
GRADLE HACKS – T IP 1
Check your config
• gradle.properties:
org.gradle.daemon=true
# if multiple modules [incubating feature]
org.gradle.parallel=true
# Dex In Process. Also set in build.gradle dexOptions{ javaMaxHeapSize }
org.gradle.jvmargs=-Xmx4096m
![Page 49: Effective Android Development](https://reader031.vdocuments.mx/reader031/viewer/2022021921/58ef81381a28abf9768b461f/html5/thumbnails/49.jpg)
49
GRADLE HACKS – T IP 2
How much time spent on building the app?
![Page 50: Effective Android Development](https://reader031.vdocuments.mx/reader031/viewer/2022021921/58ef81381a28abf9768b461f/html5/thumbnails/50.jpg)
50
GRADLE HACKS – T IP 2
How much time spent on building the app?
• Track your time! https://github.com/passy/build-time-tracker-plugin
![Page 51: Effective Android Development](https://reader031.vdocuments.mx/reader031/viewer/2022021921/58ef81381a28abf9768b461f/html5/thumbnails/51.jpg)
51
GRADLE HACKS – T IP 3
Build faster using target API 21 for dev needs
![Page 52: Effective Android Development](https://reader031.vdocuments.mx/reader031/viewer/2022021921/58ef81381a28abf9768b461f/html5/thumbnails/52.jpg)
52
GRADLE HACKS – T IP 3
Build faster using target API 21 for dev needs
productFlavors {
// Define separate dev and prod flavors
dev21 { minSdkVersion 21 }
dev14 { minSdkVersion 14 }
prod {
// The actual minSdkVersion for the application
minSdkVersion 14
}
}
![Page 53: Effective Android Development](https://reader031.vdocuments.mx/reader031/viewer/2022021921/58ef81381a28abf9768b461f/html5/thumbnails/53.jpg)
53
CONCLUSION
![Page 54: Effective Android Development](https://reader031.vdocuments.mx/reader031/viewer/2022021921/58ef81381a28abf9768b461f/html5/thumbnails/54.jpg)
54
CONCLUSION
• Keep optimizing time spent on repeating things
• Keep looking for ways how to build the app faster
• It’s never too late to improve tools knowledge
![Page 55: Effective Android Development](https://reader031.vdocuments.mx/reader031/viewer/2022021921/58ef81381a28abf9768b461f/html5/thumbnails/55.jpg)
55
THANKS!
• tech.zalando.com/jobs
• @sergiizhuk
• medium.com/@sergii