Slide 1

Slide 1 text

Android From The Trenches Lessons learned from having two apps in the top free category on Google play for over 3 years.

Slide 2

Slide 2 text

@donnfelker donnfelker.com

Slide 3

Slide 3 text

No content

Slide 4

Slide 4 text

Two Apps In The Top 100

Slide 5

Slide 5 text

No content

Slide 6

Slide 6 text

What happens when your app gets into the top free category on Google Play?

Slide 7

Slide 7 text

Quite a few things ...

Slide 8

Slide 8 text

Here’s what should happen.

Slide 9

Slide 9 text

Excitement!

Slide 10

Slide 10 text

Joy!

Slide 11

Slide 11 text

Got Monetization?

Slide 12

Slide 12 text

Then let it rain.

Slide 13

Slide 13 text

No content

Slide 14

Slide 14 text

No content

Slide 15

Slide 15 text

Kinda. Sometimes. Maybe Not.

Slide 16

Slide 16 text

Here’s what really happens.

Slide 17

Slide 17 text

Excitement!

Slide 18

Slide 18 text

Joy!

Slide 19

Slide 19 text

No content

Slide 20

Slide 20 text

No content

Slide 21

Slide 21 text

BUT THEN ...

Slide 22

Slide 22 text

All Hell Breaks Loose

Slide 23

Slide 23 text

Tons of Email Complaints, Crashes, Support Emails, Oh My!

Slide 24

Slide 24 text

What are these crashes? Huh? These never happened in dev. java.io.IOException: Attempted read from closed stream. com.android.music.sync.common.SoftSyncException: java.io.IOException: Attempted read from closed stream. at com.android.music.sync.google.MusicSyncAdapter.getChangesFromServerAsDom(MusicSyncAdapter.java:545) at com.android.music.sync.google.MusicSyncAdapter.fetchDataFromServer(MusicSyncAdapter.java:488) at com.android.music.sync.common.AbstractSyncAdapter.download(AbstractSyncAdapter.java:417) at com.android.music.sync.common.AbstractSyncAdapter.innerPerformSync(AbstractSyncAdapter.java:313) at com.android.music.sync.common.AbstractSyncAdapter.onPerformLoggedSync(AbstractSyncAdapter.java:243) at com.google.android.common.LoggingThreadedSyncAdapter.onPerformSync(LoggingThreadedSyncAdapter.java:33) at android.content.AbstractThreadedSyncAdapter$SyncThread.run(AbstractThreadedSyncAdapter.java:164) Caused by: java.io.IOException: Attempted read from closed stream. at org.apache.http.impl.io.ChunkedInputStream.read(ChunkedInputStream.java:148) at org.apache.http.conn.EofSensorInputStream.read(EofSensorInputStream.java:159) at java.util.zip.GZIPInputStream.readFully(GZIPInputStream.java:212) at java.util.zip.GZIPInputStream.(GZIPInputStream.java:81) at java.util.zip.GZIPInputStream.(GZIPInputStream.java:64) at android.net.http.AndroidHttpClient.getUngzippedContent(AndroidHttpClient.java:218) at com.android.music.sync.api.MusicApiClientImpl.createAndExecuteMethod(MusicApiClientImpl.java:312) at com.android.music.sync.api.MusicApiClientImpl.getItems(MusicApiClientImpl.java:588) at com.android.music.sync.api.MusicApiClientImpl.getTracks(MusicApiClientImpl.java:638) at com.android.music.sync.google.MusicSyncAdapter.getChangesFromServerAsDom(MusicSyncAdapter.java:512) ... 6 more

Slide 25

Slide 25 text

How to mitigate? Be proactive.

Slide 26

Slide 26 text

Unit Testing With JUNit, Robolectric & Mockito

Slide 27

Slide 27 text

Whoa Whoa Whoa I didnt say it was perfect

Slide 28

Slide 28 text

Example @RunWith(RobolectricTestRunner.class) public class SomeValueServiceImplTest { UserValueService uvs; UserService user; @Before public void setup() { user = mock(UserService.class); // An interface when(user.getGoals()).thenReturn(mock(UserGoals.class)); // Mock another interface uvs = new UserValueService(user); } @Test public void shouldBeAbleToGetBasicWeightHeightInfo() { when(user.getGoals().getHeight()).thenReturn(1223.0012f); when(user.getGoals().getWeight()).thenReturn("1,223g"); assertThat(uvs.getHeightGoal()).isEqualTo(1223.0012f); assertThat(uvs.getWeightGoal()).isEqualTo("1,223g"); } }

Slide 29

Slide 29 text

What Is this? assertThat(something) .isEqualTo(someOtherValue); Fest for Assertions & Fest For Android More Info: github.com/square/fest-android

Slide 30

Slide 30 text

Espresso Googles Testing tools for Android

Slide 31

Slide 31 text

Click on a spinner to open the item selection onView(withId(R.id.spinner_simple)).perform(click()); Click on the item 'Americano' onData(allOf(is(instanceOf(String.class)), is("Americano"))) .perform(click()); Verify that the TextView contains the String "Americano" onView(withId(R.id.spinnertext_simple)) .check(matches(withText(containsString("Americano"))));

Slide 32

Slide 32 text

Automate It

Slide 33

Slide 33 text

! For Android Run Monkey against your App & Devices

Slide 34

Slide 34 text

adb -d shell monkey -p com.instagram.android -v 2000

Slide 35

Slide 35 text

No content

Slide 36

Slide 36 text

Automated Acceptance Testing

Slide 37

Slide 37 text

I GOT 99 Devices and the problem is every single one

Slide 38

Slide 38 text

Testing on Multiple Devices Sucks

Slide 39

Slide 39 text

You Know Your Android Dev If your Desk Looks Like This

Slide 40

Slide 40 text

Device Lab devicelab.vanamco.com

Slide 41

Slide 41 text

Device Lab Yeah buddy

Slide 42

Slide 42 text

Device Lab Makes it Better But Testing on Multiple Devices Still Sucks

Slide 43

Slide 43 text

ADB and Spoon To The Rescue

Slide 44

Slide 44 text

Automated Distributed Instrumentation Testing

Slide 45

Slide 45 text

No content

Slide 46

Slide 46 text

No content

Slide 47

Slide 47 text

Cant Catch Everything Even Parachutes Have Holes

Slide 48

Slide 48 text

This Still Happens

Slide 49

Slide 49 text

No content

Slide 50

Slide 50 text

Log uncaught & caught exceptions

Slide 51

Slide 51 text

No content

Slide 52

Slide 52 text

No content

Slide 53

Slide 53 text

No content

Slide 54

Slide 54 text

What about development vs production crashes and getting them confused?

Slide 55

Slide 55 text

Use build variants in gradle

Slide 56

Slide 56 text

build.gradle buildTypes { debug { packageNameSuffix '.debug' } release { proguardFile plugin.getDefaultDexGuardFile('dexguard-release.pro') proguardFile 'dexguard-project.txt' } }

Slide 57

Slide 57 text

No content

Slide 58

Slide 58 text

NO This was not a commercial or Ad for Crashlytics

Slide 59

Slide 59 text

Lesson Watch Your Crashes

Slide 60

Slide 60 text

In App Monitoring Made Easy

Slide 61

Slide 61 text

No content

Slide 62

Slide 62 text

Tons of Email

Slide 63

Slide 63 text

Managing Email Load

Slide 64

Slide 64 text

Case Management Auto Assignment Email Workflow and more

Slide 65

Slide 65 text

No content

Slide 66

Slide 66 text

No content

Slide 67

Slide 67 text

TOOLS ZenDesk Desk.com Freshdesk UserVoice ...

Slide 68

Slide 68 text

Defensive Coding

Slide 69

Slide 69 text

Trying To Prevent

Slide 70

Slide 70 text

Null Pointer Exception AKA - NPE

Slide 71

Slide 71 text

NPE is your new BFF

Slide 72

Slide 72 text

What Shouldn't be null, will be. Thanks, Murph

Slide 73

Slide 73 text

SIMPLE EXAMPLE @Override public void onListItemClick(final ListView l, final View v, final int position, final long id) { super.onListItemClick(l, v, position, id); Toast.makeText(getActivity(), "Seems Legit!", Toast.LENGTH_SHORT).show(); } Seems Legit?

Slide 74

Slide 74 text

PFFT, I WISH

Slide 75

Slide 75 text

In Fragments We Have getActivity() Make sure you always assume its null

Slide 76

Slide 76 text

Easy to fix NPE crashes occur in Every Production Android Application

Slide 77

Slide 77 text

Lesson Always Check For Null Because at scale, it will be null Even when it should NEVER be null

Slide 78

Slide 78 text

Software Patterns Keeping you sane and healthy

Slide 79

Slide 79 text

Boss Man Says The app has to have the feature this release. I know you just heard about it and we're shipping this afternoon.

Slide 80

Slide 80 text

Making a quick & easy update Done! Commit!

Slide 81

Slide 81 text

No content

Slide 82

Slide 82 text

Boss Man: Happy Your Teammates though?

Slide 83

Slide 83 text

Seriously?

Slide 84

Slide 84 text

Spaghetti Mmmmmmmm tasty

Slide 85

Slide 85 text

Why?

Slide 86

Slide 86 text

A house built upon a cardboard foundation is bound to eventually fall

Slide 87

Slide 87 text

App Architecture Matters

Slide 88

Slide 88 text

Software Patterns

Slide 89

Slide 89 text

Dependency Injection

Slide 90

Slide 90 text

Break Dependencies

Slide 91

Slide 91 text

No content

Slide 92

Slide 92 text

Use Dagger

Slide 93

Slide 93 text

Compile Time Code Generation Limited Reflection

Slide 94

Slide 94 text

Using Dagger

Slide 95

Slide 95 text

Android Field Injection

Slide 96

Slide 96 text

Example Android Injection From Android Bootstrap public class NewsListFragment extends ItemListFragment { @Inject protected BootstrapServiceProvider serviceProvider; @Inject protected LogoutService logoutService; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Injector.inject(this); } }

Slide 97

Slide 97 text

POJO Constructor Injection GOOD

Slide 98

Slide 98 text

Example Pojo CTOR Injection From Android Bootstrap public class LogoutService { protected final Context context; protected final AccountManager accountManager; @Inject public LogoutService(final Context context, final AccountManager accountManager) { this.context = context; this.accountManager = accountManager; } }

Slide 99

Slide 99 text

Start This Today Instant Reward Flexibiity, composition, testing

Slide 100

Slide 100 text

Dagger Deep Dive https://speakerdeck.com/jakewharton/android-apps-with-dagger

Slide 101

Slide 101 text

How Do You Perform In App Communication?

Slide 102

Slide 102 text

I Sure hope its not statics

Slide 103

Slide 103 text

Pub Sub

Slide 104

Slide 104 text

For Goodness Sake Use an Event Bus

Slide 105

Slide 105 text

No content

Slide 106

Slide 106 text

No content

Slide 107

Slide 107 text

No content

Slide 108

Slide 108 text

Easily communicate inside of an app Can over complicate the app though Tooling Helps

Slide 109

Slide 109 text

Popular Frameworks Otto Green Robot Event Bus RxJava

Slide 110

Slide 110 text

Well This Looks Like Fun 04-19 10:15:14.164 464-477/system_process D/BluetoothManagerService Stored bluetooth Name=,Address=22:22:67:56:65:B2 04-19 10:15:14.164 464-477/system_process I/InputManager Starting input manager 04-19 10:15:14.164 464-477/system_process I/SystemServer Bluetooth Manager Service 04-19 10:15:14.172 464-477/system_process I/SystemServer Input Method Service 04-19 10:15:14.172 464-477/system_process W/InputMethodManagerService Couldnt create dir.: /data/system/inputmethod 04-19 10:15:14.184 464-477/system_process W/ResourceType Failure getting entry for 0x7f060000 (t=5 e=0) in package 0 (error -75) 04-19 10:15:14.188 464-477/system_process E/Trace error opening trace file: No such file or directory (2) 04-19 10:15:14.188 464-477/system_process I/SystemServer Accessibility Manager 04-19 10:15:14.192 484-486/? D/SurfaceFlinger setOrientation, mFbdev=0xb8969e90, mFbDev->setOrientation=0xb6774e20, orientation=0 04-19 10:15:14.192 484-486/? I/gralloc_vbox86 setOrientation: orientation=0 04-19 10:15:14.192 464-477/system_process I/SystemServer Mount Servic 04-19 10:15:14.196 485-485/? E/WVMExtractor Failed to open libwvm.so 04-19 10:15:14.196 464-477/system_process I/SystemServer LockSettingsService 04-19 10:15:14.196 464-477/system_process I/SystemServer Device Policy 04-19 10:15:14.196 464-477/system_process I/SystemServer Status Bar 04-19 10:15:14.196 464-477/system_process I/SystemServer Clipboard Service 04-19 10:15:14.196 464-477/system_process I/SystemServer NetworkManagement Service 04-19 10:15:14.196 464-477/system_process I/SystemServer Text Service Manager Service 04-19 10:15:14.204 464-477/system_process I/SystemServer NetworkStats Service 04-19 10:15:14.204 464-477/system_process I/SystemServer NetworkPolicy Service 04-19 10:15:14.208 464-524/system_process E/EventHub could not get driver version for /dev/input/mouse3, Not a typewriter 04-19 10:15:14.208 464-537/system_process I/PackageManager No secure containers on sdcard 04-19 10:15:14.208 464-537/system_process E/MountService Error processing initial volume state java.lang.NullPointerException at com.android.server.MountService.updatePublicVolumeState(MountService.java:630) at com.android.server.MountService.access$1400(MountService.java:103) at com.android.server.MountService$3.run(MountService.java:723) 04-19 10:15:14.208 464-477/system_process I/SystemServer Wi-Fi P2pService

Slide 111

Slide 111 text

Android Logs Are Terrible

Slide 112

Slide 112 text

Log.wtf No, seriously, this really exists in Android

Slide 113

Slide 113 text

Yup, Here It Is

Slide 114

Slide 114 text

But Really, Here's the Issue Log.e(tag, ...) Log.d(tag, ...) Log.i(tag, ...) Log.v(tag, ...)

Slide 115

Slide 115 text

I Like Line #s

Slide 116

Slide 116 text

Like This 04-19 10:21:13.527 1152-1152/ com.myfitnesspal.android D/ COM.MYFITNESSPAL.ANDROID/ AbstractNavigationHelper.java:370 MFP main starting activity normally: Intent { act=android.intent.action.MAIN flg=0x16000000 cmp=com.myfitnesspal.android/ com.myfitnesspal.activity.Welcome2 }

Slide 117

Slide 117 text

The Ln Logger From RoboGuice/ Android Bootstrap

Slide 118

Slide 118 text

Forget the tags ! Ln.d("Hi") Ln.e(err, "Oh No!") Ln.i("Yo") Ln.v("Foo")

Slide 119

Slide 119 text

Ln.java Provides » File Names » Line Numbers » Package Name » Default Verbose logging for debug builds » Built in String formatting

Slide 120

Slide 120 text

Hugo Annotation-Triggered method call logging for your debug builds @DebugLog public String getName(String first, String last) { SystemClock.sleep(15); // Don't ever really do this! return first + " " + last; } Result D/Example: ⇢ getName(first="Bill", last="Cosby") D/Example: ⇠ getName [16ms] = "Bill Cosby"

Slide 121

Slide 121 text

Hugo https://github.com/JakeWharton/hugo

Slide 122

Slide 122 text

Deep Links

Slide 123

Slide 123 text

Deep Links Built Properly Open up Business opportunities and growth

Slide 124

Slide 124 text

What is a Deep Link? A URI your app intercepts and responds to I'm sure you've seen this happen with Twitter, YouTube, GooglePlus, Groupon and more

Slide 125

Slide 125 text

What does one look like? URL BASED http://www.donnfelker.com/some/path CUSTOM donnfelker://path/to/something

Slide 126

Slide 126 text

Defined in the AndroidManifest.xml

Slide 127

Slide 127 text

Deep Links Drive Engagement

Slide 128

Slide 128 text

Lets Talk About Fragments For a Minute

Slide 129

Slide 129 text

FRAGMENTS You need them, even if you think you dont.

Slide 130

Slide 130 text

Fragments are Good For » Responsive Layout » Screen and UX Composition » Hosting Fragments in Fragments » View Pagers » Sliding Drawer/etc

Slide 131

Slide 131 text

Start with Fragments or Migrate Now. Waiting until later is expensive

Slide 132

Slide 132 text

Do you even Build, Bro?

Slide 133

Slide 133 text

Continuous Integration

Slide 134

Slide 134 text

A core component For any team

Slide 135

Slide 135 text

Options » Jenkins » TeamCity » Travis » and a bunch more ...

Slide 136

Slide 136 text

Most Common Jenkins In House Travis Open Source

Slide 137

Slide 137 text

What gets Measured Gets Managed

Slide 138

Slide 138 text

Analytics & A/B Testing

Slide 139

Slide 139 text

Google Analytics Localytics MixPanel Custom

Slide 140

Slide 140 text

A/B Testing on Mobile?

Slide 141

Slide 141 text

Very Similar to Other A/B Test Frameworks { "abtests": [ { name: "201404-loginButtonColor", variants : [ { name: "orange", data: { color: "#FF9900" } }, { name: "yellow", data: { color: "#FEFEDF" } } ] } ] }

Slide 142

Slide 142 text

Yeah, its custom

Slide 143

Slide 143 text

Commercial Solutions - Apptimize.com - Arise.io - LeanPlum.com - AppIterate.com - SplitForce.com - Vessel - and more ...

Slide 144

Slide 144 text

Community

Slide 145

Slide 145 text

Embrace Open Source

Slide 146

Slide 146 text

Libraries - Dagger - Otto - Picasso - OkHttp - Retrofit - Spoon - Http-Request - RxJava - Gson - Jackson - Guava - Butterknife - Hugo

Slide 147

Slide 147 text

Libraries Continued - Timber - Madge - Scapel - StaggeredGrid

Slide 148

Slide 148 text

Bootstrap An App & Learning

Slide 149

Slide 149 text

Three Great Options Android Bootstrap Android Kickstartr Jake Wharton's u2020

Slide 150

Slide 150 text

Android Bootstrap

Slide 151

Slide 151 text

Android Kickstartr

Slide 152

Slide 152 text

Jake Wharton's u2020

Slide 153

Slide 153 text

Read Great Code One of the best ways to learn

Slide 154

Slide 154 text

Thats a Wrap

Slide 155

Slide 155 text

Lessons Learned

Slide 156

Slide 156 text

1. Prepare for Things to break

Slide 157

Slide 157 text

2. Prepare to Support Your Customers

Slide 158

Slide 158 text

3. Remind yourself to Stay Foolish and Stay Hungry

Slide 159

Slide 159 text

Thank You Reach me at @donnfelker