Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
"It's an Inside Job" - Building Debug Features
Search
Sam Edwards
April 11, 2017
Programming
7
330
"It's an Inside Job" - Building Debug Features
Droidcon Boston - April 11, 2017
DC Android - March 15, 2017
Sam Edwards
April 11, 2017
Tweet
Share
More Decks by Sam Edwards
See All by Sam Edwards
KotlinConf 24 - Dynamic Exploration of Static Analysis with Compose
handstandsam
2
40
Interception - Droidcon NYC 2023
handstandsam
1
140
KMP4FREE in 2023 @ Droidcon NYC 2022
handstandsam
2
250
Embracing commonMain for Android Development - Droidcon SF 2022
handstandsam
4
550
Why I Left Java for Kotlin
handstandsam
1
330
Kotlin Actors - No Drama Concurrency
handstandsam
6
29k
SELECT * FROM Kotlin - Droidcon NYC 2019
handstandsam
1
340
Android Summit 2019: DIY Dependency Injection with Kotlin
handstandsam
7
1.7k
DIY Dependency Injection with Kotlin @ DevFest Florida 2019
handstandsam
1
340
Other Decks in Programming
See All in Programming
nekko cloudにおけるProxmox VE利用事例
irumaru
3
430
The Efficiency Paradox and How to Save Yourself and the World
hollycummins
1
440
今年一番支援させていただいたのは認証系サービスでした
satoshi256kbyte
1
250
CSC305 Lecture 26
javiergs
PRO
0
140
42 best practices for Symfony, a decade later
tucksaun
1
180
クリエイティブコーディングとRuby学習 / Creative Coding and Learning Ruby
chobishiba
0
3.9k
これでLambdaが不要に?!Step FunctionsのJSONata対応について
iwatatomoya
2
3.6k
StarlingMonkeyを触ってみた話 - 2024冬
syumai
3
270
これが俺の”自分戦略” プロセスを楽しんでいこう! - Developers CAREER Boost 2024
niftycorp
PRO
0
190
モバイルアプリにおける自動テストの導入戦略
ostk0069
0
110
PHPUnitしか使ってこなかった 一般PHPerがPestに乗り換えた実録
mashirou1234
0
170
Fibonacci Function Gallery - Part 1
philipschwarz
PRO
0
210
Featured
See All Featured
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
44
6.9k
Visualizing Your Data: Incorporating Mongo into Loggly Infrastructure
mongodb
44
9.3k
Build The Right Thing And Hit Your Dates
maggiecrowley
33
2.4k
Building Better People: How to give real-time feedback that sticks.
wjessup
365
19k
Art, The Web, and Tiny UX
lynnandtonic
298
20k
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
28
4.4k
Thoughts on Productivity
jonyablonski
67
4.4k
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
26
1.9k
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
6
520
Producing Creativity
orderedlist
PRO
341
39k
Side Projects
sachag
452
42k
Raft: Consensus for Rubyists
vanstee
137
6.7k
Transcript
#droidconbos @HandstandSam “It’s an Inside Job” BUILDING DEBUG FEATURES Sam
Edwards @HandstandSam
#droidconbos @HandstandSam 1. WHAT IS A DEBUG FEATURE? 2. GRADLE
BUILD VARIANTS 3. EXAMPLE SCENARIOS 4. OPEN SOURCE INSPIRATION 5. DON’T SHIP TO PROD OUTLINE
#droidconbos @HandstandSam WHAT IS A DEBUG FEATURE?
#droidconbos @HandstandSam DEBUG FEATURES • HELP YOU TEST AND DEBUG
• DON’T SHIP TO PRODUCTION
#droidconbos @HandstandSam AS DEVELOPERS, WE HAVE INSIDER ACCESS TO BUILD
THEM
#droidconbos @HandstandSam DEBUG FEATURES IN YOUR APP ENABLE YOUR TEAM
TO EFFECTIVELY PERFORM TASKS THAT CAN’T BE AUTOMATED.
#droidconbos @HandstandSam DEBUG FEATURE POSSIBILITY MATRIX
#droidconbos @HandstandSam Modify Mock Monitor Capture Inspect Configurations Persistent Data
Networking Resources Views Notifications Sensors … and more.
#droidconbos @HandstandSam GRADLE BUILD VARIANTS
#droidconbos @HandstandSam “main” SOURCE FOLDER
#droidconbos @HandstandSam BuildConfig.java
#droidconbos @HandstandSam DEFAULTS = = RELEASE.APK DEBUG.APK “main”
#droidconbos @HandstandSam “debug” and “release” SOURCE FOLDERS
#droidconbos @HandstandSam “debug” & “release” SOURCE FOLDERS = = RELEASE.APK
DEBUG.APK “main” “debug” “release” +
#droidconbos @HandstandSam SOURCE STRUCTURE
#droidconbos @HandstandSam “debug”
#droidconbos @HandstandSam “release”
#droidconbos @HandstandSam GRADLE COMPILE DEPENDENCIES
#droidconbos @HandstandSam GRADLE DEPENDENCIES
#droidconbos @HandstandSam GRADLE DEPENDENCIES = = RELEASE.APK DEBUG.APK “compile” “debugCompile”
“releaseCompile” +
#droidconbos @HandstandSam GENERATED APKS
#droidconbos @HandstandSam EXAMPLE SCENARIO
#droidconbos @HandstandSam SAMPLE APP https://github.com/handstandsam/BuildingDebugFeatures
#droidconbos @HandstandSam ANDROID DEV
#droidconbos @HandstandSam ANDROID DEV DESIGN
#droidconbos @HandstandSam ANDROID DEV DESIGN BACKEND
#droidconbos @HandstandSam ANDROID DEV PRODUCT DESIGN BACKEND
#droidconbos @HandstandSam ANDROID DEV TESTING PRODUCT DESIGN BACKEND
#droidconbos @HandstandSam JOE: “CAN I HAVE A SPECIAL BUILD TO
TEST A NEW SERVER ENDPOINT?” BACKEND
#droidconbos @HandstandSam SURE, BUT IT’LL TAKE A FEW MINUTES.
#droidconbos @HandstandSam @Provides Retrofit.Builder retrofitBuilder(OkHttpClient.Builder okHttpClientBuilder) { Retrofit.Builder builder =
new Retrofit.Builder() .baseUrl("https://server") .addConverterFactory(MoshiConverterFactory.create(new Moshi.Builder().build())) .addCallAdapterFactory(RxJava2CallAdapterFactory.create()) .client(okHttpClientBuilder.build()); return builder; }
#droidconbos @HandstandSam @Provides Retrofit.Builder retrofitBuilder(OkHttpClient.Builder okHttpClientBuilder) { Retrofit.Builder builder =
new Retrofit.Builder() .baseUrl("https://temp-server") .addConverterFactory(MoshiConverterFactory.create(new Moshi.Builder().build())) .addCallAdapterFactory(RxJava2CallAdapterFactory.create()) .client(okHttpClientBuilder.build()); return builder; }
#droidconbos @HandstandSam WAIT FOR GRADLE...
#droidconbos @HandstandSam How many times have you hit ______ In
and then waited for
#droidconbos @HandstandSam This ISN’T the first time you’ve been asked
for this. BACKEND BACKEND BACKEND BACKEND BACKEND TESTING TESTING TESTING TESTING ANDROID DEV
#droidconbos @HandstandSam NOR THE LAST BACKEND BACKEND BACKEND BACKEND BACKEND
TESTING TESTING TESTING TESTING ANDROID DEV BACKEND BACKEND BACKEND BACKEND BACKEND TESTING TESTING TESTING TESTING ANDROID DEV BACKEND BACKEND BACKEND BACKEND BACKEND TESTING TESTING TESTING TESTING ANDROID DEV BACKEND BACKEND BACKEND BACKEND BACKEND TESTING TESTING TESTING TESTING ANDROID DEV
#droidconbos @HandstandSam YOU CAN ENABLE OTHERS
#droidconbos @HandstandSam CUSTOM DEBUG FEATURE “CHANGE ENDPOINT”
#droidconbos @HandstandSam WHAT WILL THIS UI LOOK LIKE?
#droidconbos @HandstandSam DEBUG DRAWER https://github.com/JakeWharton/u2020 • Requires changes to existing
UI hierarchy. • Could interfere with actions that use side-to-side swiping.
#droidconbos @HandstandSam HOVERING MENU https://github.com/google/hover • REQUIRES NO CODE CHANGES
• LOOKS COOL • REQUIRES LEARNING A NEW PARADIGM OF USING THE WINDOW MANAGER
#droidconbos @HandstandSam NEW ACTIVITY • REQUIRES NO CHANGES TO EXISTING
UI CODE • STRAIGHT FORWARD
#droidconbos @HandstandSam BUT… HOW WILL THEY ACCESS THE NEW ACTIVITY?
#droidconbos @HandstandSam OPTION 1: MULTIPLE LAUNCHER ICONS FOR A SINGLE
APP
#droidconbos @HandstandSam <activity android:name=".MainActivity" android:launchMode="singleTask"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category
android:name="android.intent.category.LAUNCHER" /> <category android:name="android.intent.category.DEFAULT" /> </intent-filter> </activity> MAIN ACTIVITY (src/main)
#droidconbos @HandstandSam <activity android:name=".DebugActivity" android:icon="@drawable/magnifying_glass" android:label="BDF - DEBUG" android:launchMode="singleTask"> <intent-filter>
<action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> <category android:name="android.intent.category.DEFAULT" /> </intent-filter> </activity> DEBUG FEATURE ACTIVITY (src/debug)
#droidconbos @HandstandSam <activity android:name=".DebugFeatureActivity" android:launchMode="singleTask"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category
android:name="android.intent.category.LAUNCHER" /> <category android:name="android.intent.category.DEFAULT" /> </intent-filter> </activity> DEBUG FEATURE ACTIVITY (src/debug)
#droidconbos @HandstandSam
#droidconbos @HandstandSam OPTION 2: PERSISTENT NOTIFICATION
#droidconbos @HandstandSam HOW WILL WE SAVE AND USE THE NEW
ENDPOINT?
#droidconbos @HandstandSam ALLOW USER TO EDIT ENDPOINT
#droidconbos @HandstandSam public class DebugPreferences { public static final String
BASE_URL = "base_url"; private final SharedPreferences sharedPreferences; public DebugPreferences(Context context) { sharedPreferences = PreferenceManager .getDefaultSharedPreferences(context.getApplicationContext()); } public void setBaseUrl(String baseUrl) { sharedPreferences.edit().putString(BASE_URL, baseUrl).apply(); } public String getBaseUrl() { return sharedPreferences.getString(BASE_URL, "https://server"); } } SAVE IN A PREFERENCE
#droidconbos @HandstandSam FORCE KILL AND RESTART APP Process Phoenix https://github.com/JakeWharton/ProcessPhoenix
#droidconbos @HandstandSam @Provides Retrofit.Builder retrofitBuilder(DebugPreferences debugPreferences, OkHttpClient.Builder okHttpClientBuilder) { Retrofit.Builder
builder = new Retrofit.Builder() .baseUrl(debugPreferences.getBaseUrl()) .addConverterFactory(MoshiConverterFactory.create(new Moshi.Builder().build())) .addCallAdapterFactory(RxJava2CallAdapterFactory.create()) .client(okHttpClientBuilder.build()); return builder; } APPLY UPON APP INITIALIZATION
#droidconbos @HandstandSam CONFIG CHANGE TOAST
#droidconbos @HandstandSam WICKED AWESOME
#droidconbos @HandstandSam ANDROID DEV TESTING PRODUCT DESIGN BACKEND
#droidconbos @HandstandSam PRODUCT JEFF: “I NEED AN EASY WAY TO
DEMO NOTIFICATIONS.”
#droidconbos @HandstandSam CUSTOM DEBUG FEATURE “NOTIFICATION TESTING”
#droidconbos @HandstandSam TRIGGER A NOTIFICATION WITHOUT GOING THROUGH GCM?
#droidconbos @HandstandSam Broadcast Receivers via ADB
#droidconbos @HandstandSam <receiver android:name=".DebugBroadcastReceiver"> <intent-filter> <action android:name="PR_NOTIFICATION" /> </intent-filter> </receiver>
BROADCAST RECEIVER (src/debug/AndroidManifest.xml)
#droidconbos @HandstandSam public class DebugBroadcastReceiver extends BroadcastReceiver { private static
final String PR_NOTIFICATION = "PR_NOTIFICATION"; @Override public void onReceive(Context context, Intent intent) { String intentAction = intent.getAction(); if (intentAction == null || !PR_NOTIFICATION.equals(intentAction)) { return; } Timber.d("processing " + PR_NOTIFICATION); Bundle extras = intent.getExtras(); if (extras == null) { return; } final String username = extras.getString("username"); Timber.d("username " + username); IntentUtils.triggerPRNotification(context, username); } } BROADCAST RECEIVER
#droidconbos @HandstandSam
#droidconbos @HandstandSam DYNAMIC HOME SCREEN SHORTCUTS
#droidconbos @HandstandSam
#droidconbos @HandstandSam Intent addShortcutIntent = new Intent(); addShortcutIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, deepLinkIntent); addShortcutIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME,
"My Shortcut"); addShortcutIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, Intent.ShortcutIconResource.fromContext(applicationContext, R.drawable.shortcut)); addShortcutIntent.setAction("com.android.launcher.action.INSTALL_SHORTCUT"); applicationContext.sendBroadcast(addShortcutIntent); DYNAMIC HOME SCREEN SHORTCUTS
#droidconbos @HandstandSam Intent addShortcutIntent = new Intent(); addShortcutIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, deepLinkIntent); addShortcutIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME,
"My Shortcut"); addShortcutIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, Intent.ShortcutIconResource.fromContext(applicationContext, R.drawable.shortcut)); addShortcutIntent.setAction("com.android.launcher.action.INSTALL_SHORTCUT"); applicationContext.sendBroadcast(addShortcutIntent); DYNAMIC HOME SCREEN SHORTCUTS
#droidconbos @HandstandSam WICKED AWESOME
#droidconbos @HandstandSam ANDROID DEV TESTING PRODUCT DESIGN BACKEND
#droidconbos @HandstandSam I WANT TO VALIDATE NETWORKING TRAFFIC IN A
VISUAL WAY. TESTING
#droidconbos @HandstandSam OPTION 1: STETHO • CHROME DEVELOPER TOOLS •
NETWORK INSPECTION • PREFERENCE INSPECTION & MODIFICATION • DB INSPECTION & MODIFICATION • VIEW HIERARCHY • JAVASCRIPT CONSOLE • DUMP APP
#droidconbos @HandstandSam
#droidconbos @HandstandSam
#droidconbos @HandstandSam
#droidconbos @HandstandSam <INSERT SCREENSHOT>
#droidconbos @HandstandSam “I’M NOT GOING TO BE CONNECTED TO A
COMPUTER.”
#droidconbos @HandstandSam OPTION 2: CHUCK https://github.com/jgilfelt/chuck
#droidconbos @HandstandSam SURE, GIVE ME A FEW MINUTES, I’LL ADD
IT TO ALL FUTURE DEBUG BUILDS.
#droidconbos @HandstandSam WICKED AWESOME
#droidconbos @HandstandSam OPEN SOURCE INSPIRATION
#droidconbos @HandstandSam DON’T RE-INVENT THE WHEEL LEVERAGE EXISTING OPEN SOURCE
LIBRARIES
#droidconbos @HandstandSam UI DESIGN & VIEW INSPECTION
#droidconbos @HandstandSam Keyline Pushing https://play.google.com/store/apps/details?id=com.faizmalkani.keylines • Overlays Material Design Keylines
#droidconbos @HandstandSam Scalpel https://github.com/JakeWharton/scalpel • A surgical debugging tool to
uncover the layers under your app.
#droidconbos @HandstandSam Madge https://github.com/JakeWharton/madge • Overlays for debugging whether assets
are drawing at their native resolution.
#droidconbos @HandstandSam Logging
#droidconbos @HandstandSam Logcat
#droidconbos @HandstandSam Timber https://github.com/JakeWharton/timber • Abstraction on top of Android
Log ◦ Log.d(TAG, message); • More concise syntax ◦ Timber.d(message); ◦ d(message); - Static Import • Ability to toggle logging on/off. • Ability to keep logs in memory.
#droidconbos @HandstandSam Hugo https://github.com/JakeWharton/hugo • Annotation-triggered method call logging for
your debug builds.
#droidconbos @HandstandSam Bug Reporting
#droidconbos @HandstandSam Telescope https://github.com/mattprecious/telescope • A simple tool to allow
easy bug report capturing within your app.
#droidconbos @HandstandSam Memory Leaks
#droidconbos @HandstandSam Leak Canary https://github.com/square/leakcanary • A memory leak detection
library for Android and Java.
#droidconbos @HandstandSam Network Inspection
#droidconbos @HandstandSam Network Debugging • Stetho • Chuck
#droidconbos @HandstandSam DON’T SHIP TO PROD
#droidconbos @HandstandSam APK ANALYZER
#droidconbos @HandstandSam APK ANALYZER - DEBUG BUILD
#droidconbos @HandstandSam APK ANALYZER - RELEASE BUILD
#droidconbos @HandstandSam CLASSY SHARK https://github.com/google/android-classyshark
#droidconbos @HandstandSam CLASSY SHARK - DEBUG BUILD
#droidconbos @HandstandSam CLASSY SHARK - RELEASE BUILD
#droidconbos @HandstandSam CLASSY SHARK - DEBUG BUILD
#droidconbos @HandstandSam CLASSY SHARK - RELEASE BUILD
#droidconbos @HandstandSam RECAP • USE GRADLE BUILD VARIANTS • USE
EXISTING LIBRARIES IF THEY WORK • START SIMPLE & BE PRAGMATIC
#droidconbos @HandstandSam IN MY OPINION: DEBUG FEATURES THAT ENABLE YOUR
TEAM IS JUST AS VALUABLE AS WHAT GETS SHIPPED TO PROD.
#droidconbos @HandstandSam THINK OUTSIDE THE BOX
#droidconbos @HandstandSam THE END