effective android development. ua mobile 2016

63
EFFECTIVE ANDROID DEVELOPMENT SERGII ZHUK 16-04-2016

Upload: ua-mobile

Post on 07-Apr-2017

358 views

Category:

Software


0 download

TRANSCRIPT

Page 1: Effective Android Development. UA Mobile 2016

EFFECTIV E

ANDROID

DEVELOPMENT

S E R G I I Z H U K

1 6 - 0 4 - 2 0 1 6

Page 2: Effective Android Development. UA Mobile 2016

2

HELLO!

My name is Sergii Zhuk

• Android Developer @ Zalando SE

• Author of DOU.ua Android Digest

• In Berlin since August 2015

• twitter.com/sergiizhuk

• medium.com/@sergii

Page 3: Effective Android Development. UA Mobile 2016

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. UA Mobile 2016

4

AGENDA

• Android Studio

• Test Devices

• Dev & Environment

• App Performance

• Gradle Hacks

Page 5: Effective Android Development. UA Mobile 2016

5

ANDROID STUDIO

Page 6: Effective Android Development. UA Mobile 2016

6

ANDROID STUDIO – T IP 0

Show line numbers, please!

Page 7: Effective Android Development. UA Mobile 2016

7

ANDROID STUDIO – T IP 1

How often to update your IDE version?

Page 8: Effective Android Development. UA Mobile 2016

8

ANDROID STUDIO – T IP 1

How often to update your IDE version?

• Use two installations: stable and canary

• Enable auto-update for the relevant channel

Page 9: Effective Android Development. UA Mobile 2016

9

ANDROID STUDIO – T IP 2

How to make a code review?

Switch between branches could be slow:

•stash your changes

•checkout branch

• reload gradle config

Page 10: Effective Android Development. UA Mobile 2016

10

ANDROID STUDIO – T IP 2

How to make a code review?

Switch between branches could be slow:

•stash your changes

•checkout branch

• reload gradle config

• Launch two IDE instances: one for the review, another one for the main work

• Yes, you will need a powerful machine

Page 11: Effective Android Development. UA Mobile 2016

11

ANDROID STUDIO – T IP 3

Use Android Studio Live Templates

Page 12: Effective Android Development. UA Mobile 2016

12

ANDROID STUDIO – T IP 3

Use Android Studio Live Templates

Page 13: Effective Android Development. UA Mobile 2016

13

ANDROID STUDIO – T IP 4

Learn how to debug

Page 14: Effective Android Development. UA Mobile 2016

14

ANDROID STUDIO – T IP 4

Learn how to debug

• Attach the debugger

Page 15: Effective Android Development. UA Mobile 2016

15

ANDROID STUDIO – T IP 4

Learn how to debug

• Use Frames Debug window

Page 16: Effective Android Development. UA Mobile 2016

16

ANDROID STUDIO – T IP 4

Learn how to debug

• Breakpoint only during interesting iterations

Page 17: Effective Android Development. UA Mobile 2016

17

ANDROID STUDIO – T IP 5

Page 18: Effective Android Development. UA Mobile 2016

18

ANDROID STUDIO – T IP 5

Fast preview & build

Page 19: Effective Android Development. UA Mobile 2016

19

ANDROID STUDIO – T IP 5

Fast preview & build

JRebel

• Multidex only in expensive “Business” version

• 21-day trial

Page 20: Effective Android Development. UA Mobile 2016

20

ANDROID STUDIO – T IP 5

Fast preview & build

JRebel

• Multidex only in expensive “Business” version

• 21-day trial

Instant Run

• minSdkVersion 15+, 21+ recommended

• Free & accepted by community

Page 21: Effective Android Development. UA Mobile 2016

21

TEST DEVICES

Page 22: Effective Android Development. UA Mobile 2016

22

TEST DEVICES – T IP 1

A lot of UI issues could be discovered if compare app on Lollipop and pre-Lollipop

devices

Page 23: Effective Android Development. UA Mobile 2016

23

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 24: Effective Android Development. UA Mobile 2016

24

TEST DEVICES – T IP 2

Emulators question

Page 25: Effective Android Development. UA Mobile 2016

25

TEST DEVICES – T IP 2

Emulators question

Genymotion

• Free only for private use & limited functionality

• Latest OS version with the delay

Page 26: Effective Android Development. UA Mobile 2016

26

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 27: Effective Android Development. UA Mobile 2016

27

TEST DEVICES – T IP 3

(Cloud) Test Platforms

Page 28: Effective Android Development. UA Mobile 2016

28

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, Cloud Test Lab

Page 29: Effective Android Development. UA Mobile 2016

29

TEST DEVICES – T IP 3

(Cloud) Test Platforms

• Also you can create your own device farm

• Open-source tools available like Square Spoon

Page 30: Effective Android Development. UA Mobile 2016

30

APP PERFORMANCE

Page 31: Effective Android Development. UA Mobile 2016

31

APP PERFORMANCE – T IP 1

Follow Android Performance Patterns

• https://www.youtube.com/playlist?list=PLWz5rJ2EKKc9CBxr3BVjPTPoDPLdPIFCE

Page 32: Effective Android Development. UA Mobile 2016

32

APP PERFORMANCE – T IP 2

Measure execution time

Page 33: Effective Android Development. UA Mobile 2016

33

APP PERFORMANCE – T IP 2

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 34: Effective Android Development. UA Mobile 2016

34

APP PERFORMANCE – T IP 3

Check the frame rate (FPS)

Page 35: Effective Android Development. UA Mobile 2016

35

APP PERFORMANCE – T IP 3

Check the frame rate (FPS)

• TinyDancer library (API 16+)

• Takt library (API 16+)

Page 36: Effective Android Development. UA Mobile 2016

36

APP PERFORMANCE – T IP 4

Which options has Developer?

Page 37: Effective Android Development. UA Mobile 2016

37

APP PERFORMANCE – T IP 4

Know your

Developer Options!

Page 38: Effective Android Development. UA Mobile 2016

38

DEV & ENVIRONMENT

Page 39: Effective Android Development. UA Mobile 2016

39

DEV & ENVIRONMENT – T IP 1

Support Annotations are your friends

Page 40: Effective Android Development. UA Mobile 2016

40

DEV & ENVIRONMENT – T IP 1

Support Annotations are your friends

• Metadata annotations you can decorate your code with, to help catch bugs

• Dependency 'com.android.support:support-annotations:23.3.0‘

• Integrated with Android Studio & Lint

Page 41: Effective Android Development. UA Mobile 2016

41

DEV & ENVIRONMENT – T IP 2

How to read logcat output from your device?

Page 42: Effective Android Development. UA Mobile 2016

42

DEV & ENVIRONMENT – T IP 2

How to read logcat output from your device?

• Jake Wharton’s pidcat

Page 43: Effective Android Development. UA Mobile 2016

43

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 44: Effective Android Development. UA Mobile 2016

44

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 45: Effective Android Development. UA Mobile 2016

45

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 46: Effective Android Development. UA Mobile 2016

46

DEV & ENVIRONMENT – T IP 4

Think about application tracking

Page 47: Effective Android Development. UA Mobile 2016

47

DEV & ENVIRONMENT – T IP 4

Think about application tracking

• A lot of projects with overlapping functionality:

• Google Analytics

• Adjust

• Answers Events by Fabric

• Integration requires huge architecture effort

• Testing is always hard

Page 48: Effective Android Development. UA Mobile 2016

48

DEV & ENVIRONMENT – T IP 5

Network output logging/analyzing?

Page 49: Effective Android Development. UA Mobile 2016

49

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 50: Effective Android Development. UA Mobile 2016

50

DEV & ENVIRONMENT – T IP 6

All-in-one inspection tool by Facebook?

Page 51: Effective Android Development. UA Mobile 2016

51

DEV & ENVIRONMENT – T IP 6

All-in-one inspection tool by Facebook!

• Stetho

• SQLite database

• Network proxy

• Hierarchy Viewer

• App preferences

Page 52: Effective Android Development. UA Mobile 2016

52

GRADLE HACKS

Page 53: Effective Android Development. UA Mobile 2016

53

GRADLE HACKS – T IP 1

Check your config

Page 54: Effective Android Development. UA Mobile 2016

54

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 55: Effective Android Development. UA Mobile 2016

55

GRADLE HACKS – T IP 1

Check your config

gradle.properties:

• org.gradle.daemon=true

• # if multiple modules:

org.gradle.parallel=true

Page 56: Effective Android Development. UA Mobile 2016

56

GRADLE HACKS – T IP 2

How much time spent on building the app?

Page 57: Effective Android Development. UA Mobile 2016

57

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 58: Effective Android Development. UA Mobile 2016

58

GRADLE HACKS – T IP 2

How much time spent on building the app?

• Track your time!

Page 59: Effective Android Development. UA Mobile 2016

59

GRADLE HACKS – T IP 3

Build faster using target API 21 for debug

Page 60: Effective Android Development. UA Mobile 2016

60

GRADLE HACKS – T IP 3

Build faster using target API 21 for dev needs

productFlavors {

// Define separate dev and prod product flavors

dev21 { minSdkVersion 21 }

dev14 { minSdkVersion 14 }

prod {

// The actual minSdkVersion for the application.

minSdkVersion 14

}

}

Page 61: Effective Android Development. UA Mobile 2016

61

CONCLUSION

Page 62: Effective Android Development. UA Mobile 2016

62

CONCLUSION

• Keep optimizing time spent on repeating things

• Keep looking for ways how to build app faster

• It’s never too late to improve tools knowledge