Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Effective Android Development

Effective Android Development

Slides from my talk presented at UA Mobile and Droidcon Berlin 2016 conferences.

More Android stuff:
https://medium.com/@sergii
https://twitter.com/sergiizhuk

Sergii Zhuk

June 16, 2016
Tweet

More Decks by Sergii Zhuk

Other Decks in Programming

Transcript

  1. EFFECTIVE
    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

    View Slide

  2. 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

    View Slide

  3. 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

    View Slide

  4. 4
    AGENDA
    • Android Studio
    • Test Devices
    • Dev & Environment
    • Gradle Hacks

    View Slide

  5. 5
    ANDROID STUDIO

    View Slide

  6. 6
    ANDROID STUDIO – TIP 1
    How does your manifest really look like?

    View Slide

  7. 7
    ANDROID STUDIO – TIP 1
    How does your manifest really look like?
    • Manifest Merger
    See also: “Hey, Where Did These Permissions Come From?” on The CommonsBlog

    View Slide

  8. 8
    ANDROID STUDIO – TIP 2
    You need to use new Android APIs. Are there any examples?

    View Slide

  9. 9
    ANDROID STUDIO – TIP 2
    You need to use new Android APIs. Are there any examples?
    • Find Sample Code

    View Slide

  10. 10
    ANDROID STUDIO – TIP 3
    “I’m not gonna to commit right now…”

    View Slide

  11. 11
    ANDROID STUDIO – TIP 3
    “I’m not gonna to commit right now…”
    Local history for rescue!

    View Slide

  12. 12
    ANDROID STUDIO – TIP 4
    Support Annotations are your friends

    View Slide

  13. 13
    ANDROID STUDIO – TIP 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

    View Slide

  14. 14
    ANDROID STUDIO – TIP 5
    How to make a code review?
    Switch between branches could be slow:
    •stash your changes
    •checkout branch
    •reload gradle config

    View Slide

  15. 15
    ANDROID STUDIO – TIP 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 

    View Slide

  16. 16
    ANDROID STUDIO – TIP 6
    Apply changes fast

    View Slide

  17. 17
    ANDROID STUDIO – TIP 6
    Swap code fast
    • Instant Run
    • JRebel

    View Slide

  18. 18
    ANDROID STUDIO – TIP 6
    Swap code fast
    • How changes are handled
    • Immediately (Hot swap)
    • Activity restart (Warm swap)
    • Application restart (Cold swap)
    • Rebuild

    View Slide

  19. 19
    ANDROID STUDIO – TIP 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 ..."

    View Slide

  20. 20
    TEST DEVICES

    View Slide

  21. 21
    TEST DEVICES – TIP 1
    A lot of UI issues could be discovered if compare app on Lollipop and pre-Lollipop
    devices

    View Slide

  22. 22
    TEST DEVICES – TIP 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

    View Slide

  23. 23
    TEST DEVICES – TIP 2
    Emulators question

    View Slide

  24. 24
    TEST DEVICES – TIP 2
    Emulators question
    Genymotion
    • Free only for private use & limited functionality
    • Latest OS version with the delay

    View Slide

  25. 25
    TEST DEVICES – TIP 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

    View Slide

  26. 26
    TEST DEVICES – TIP 3
    (Cloud) Test Platforms

    View Slide

  27. 27
    TEST DEVICES – TIP 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

    View Slide

  28. 28
    TEST DEVICES – TIP 3
    (Cloud) Test Platforms
    • Also you can create your own device farm
    • Open-source tools available like Square Spoon

    View Slide

  29. 29
    DEV & ENVIRONMENT

    View Slide

  30. 30
    DEV & ENVIRONMENT – TIP 1
    Measure execution time

    View Slide

  31. 31
    DEV & ENVIRONMENT – TIP 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:

    View Slide

  32. 32
    DEV & ENVIRONMENT – TIP 2
    How to read logcat output from your device?

    View Slide

  33. 33
    DEV & ENVIRONMENT – TIP 2
    How to read logcat output from your device?
    • Jake Wharton’s pidcat

    View Slide

  34. 34
    DEV & ENVIRONMENT – TIP 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?

    View Slide

  35. 35
    DEV & ENVIRONMENT – TIP 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

    View Slide

  36. 36
    DEV & ENVIRONMENT – TIP 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

    View Slide

  37. 37
    DEV & ENVIRONMENT – TIP 4
    Think about application tracking & analytics

    View Slide

  38. 38
    DEV & ENVIRONMENT – TIP 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

    View Slide

  39. 39
    DEV & ENVIRONMENT – TIP 5
    Network output logging/analyzing?

    View Slide

  40. 40
    DEV & ENVIRONMENT – TIP 5
    Network output logging/analyzing
    Use Http Monitoring & Proxy tools like Charles
    • HTTP/HTTPS traffic monitoring
    • Rewrite values
    • Set breakpoints

    View Slide

  41. 41
    DEV & ENVIRONMENT – TIP 6
    All-in-one inspection tool by Facebook?

    View Slide

  42. 42
    DEV & ENVIRONMENT – TIP 6
    All-in-one inspection tool by Facebook!
    • Stetho
    • SQLite database
    • Network proxy
    • Hierarchy Viewer
    • App preferences

    View Slide

  43. 43
    DEV & ENVIRONMENT – TIP 7
    Explore your APK
    • Manifest
    • Method count per dependency
    • Resources set properly
    • and more

    View Slide

  44. 44
    DEV & ENVIRONMENT – TIP 7
    Explore your APK:
    ClassyShark
    • DEX Method count by package/class
    • Dependencies
    • Merged Manifest
    • Obfuscation check
    Android Studio APK Analyzer
    + Drawables preview

    View Slide

  45. 45
    GRADLE HACKS

    View Slide

  46. 46
    GRADLE HACKS – TIP 1
    Check your config

    View Slide

  47. 47
    GRADLE HACKS – TIP 1
    Check your config
    build.gradle:
    • Get rid of mavenCentral, use jcenter
    • Check Gradle plugin version
    • DON’T specify version ranges for the dependencies

    View Slide

  48. 48
    GRADLE HACKS – TIP 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

    View Slide

  49. 49
    GRADLE HACKS – TIP 2
    How much time spent on building the app?

    View Slide

  50. 50
    GRADLE HACKS – TIP 2
    How much time spent on building the app?
    • Track your time! https://github.com/passy/build-time-tracker-plugin

    View Slide

  51. 51
    GRADLE HACKS – TIP 3
    Build faster using target API 21 for dev needs

    View Slide

  52. 52
    GRADLE HACKS – TIP 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
    }
    }

    View Slide

  53. 53
    CONCLUSION

    View Slide

  54. 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

    View Slide

  55. 55
    THANKS!
    • tech.zalando.com/jobs
    • @sergiizhuk
    • medium.com/@sergii

    View Slide