Slide 1

Slide 1 text

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

Slide 2

Slide 2 text

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

Slide 3

Slide 3 text

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

Slide 4

Slide 4 text

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

Slide 5

Slide 5 text

5 ANDROID STUDIO

Slide 6

Slide 6 text

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

Slide 7

Slide 7 text

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

Slide 8

Slide 8 text

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

Slide 9

Slide 9 text

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

Slide 10

Slide 10 text

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

Slide 11

Slide 11 text

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

Slide 12

Slide 12 text

12 ANDROID STUDIO – TIP 4 Support Annotations are your friends

Slide 13

Slide 13 text

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

Slide 14

Slide 14 text

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

Slide 15

Slide 15 text

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 

Slide 16

Slide 16 text

16 ANDROID STUDIO – TIP 6 Apply changes fast

Slide 17

Slide 17 text

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

Slide 18

Slide 18 text

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

Slide 19

Slide 19 text

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

Slide 20

Slide 20 text

20 TEST DEVICES

Slide 21

Slide 21 text

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

Slide 22

Slide 22 text

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

Slide 23

Slide 23 text

23 TEST DEVICES – TIP 2 Emulators question

Slide 24

Slide 24 text

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

Slide 25

Slide 25 text

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

Slide 26

Slide 26 text

26 TEST DEVICES – TIP 3 (Cloud) Test Platforms

Slide 27

Slide 27 text

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

Slide 28

Slide 28 text

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

Slide 29

Slide 29 text

29 DEV & ENVIRONMENT

Slide 30

Slide 30 text

30 DEV & ENVIRONMENT – TIP 1 Measure execution time

Slide 31

Slide 31 text

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: <-- getName [16ms] = "Jake Wharton"

Slide 32

Slide 32 text

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

Slide 33

Slide 33 text

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

Slide 34

Slide 34 text

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?

Slide 35

Slide 35 text

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

Slide 36

Slide 36 text

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

Slide 37

Slide 37 text

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

Slide 38

Slide 38 text

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

Slide 39

Slide 39 text

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

Slide 40

Slide 40 text

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

Slide 41

Slide 41 text

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

Slide 42

Slide 42 text

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

Slide 43

Slide 43 text

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

Slide 44

Slide 44 text

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

Slide 45

Slide 45 text

45 GRADLE HACKS

Slide 46

Slide 46 text

46 GRADLE HACKS – TIP 1 Check your config

Slide 47

Slide 47 text

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

Slide 48

Slide 48 text

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

Slide 49

Slide 49 text

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

Slide 50

Slide 50 text

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

Slide 51

Slide 51 text

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

Slide 52

Slide 52 text

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 } }

Slide 53

Slide 53 text

53 CONCLUSION

Slide 54

Slide 54 text

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

Slide 55

Slide 55 text

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