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
320
"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
23
Interception - Droidcon NYC 2023
handstandsam
1
130
KMP4FREE in 2023 @ Droidcon NYC 2022
handstandsam
2
240
Embracing commonMain for Android Development - Droidcon SF 2022
handstandsam
4
530
Why I Left Java for Kotlin
handstandsam
1
310
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
330
Other Decks in Programming
See All in Programming
現場から考えるソフトウェアエンジニアリングの価値と実験
nomuson
1
130
2024-10-02 dev2next - Application Observability like you've never heard before
jonatan_ivanov
0
180
Cohesion in Modeling and Design
mploed
3
210
5年分のツケを一気に払った話
soogie
3
1.4k
デバッグの話 / Debugging for Beginners
kaityo256
PRO
8
580
データサイエンスのフルサイクル開発を実現する機械学習パイプライン
xcnkx
2
500
CSC509 Lecture 02
javiergs
PRO
0
160
RDBの世界をぬりかえていくモデルグラフDB〜truncus graphによるモデルファースト開発〜
jurabi
0
170
선언형 UI를 학습할 때 알아둬야하는 키워드들
l2hyunwoo
0
140
Subclassing, Composition, Python, and You
hynek
3
170
"noncopyable types" の使いどころについて考えてみた
andpad
0
160
ACES Meet におけるリリース作業改善の取り組み
fukucheee
0
130
Featured
See All Featured
The Straight Up "How To Draw Better" Workshop
denniskardys
232
130k
Fashionably flexible responsive web design (full day workshop)
malarkey
404
65k
Statistics for Hackers
jakevdp
796
220k
Web Components: a chance to create the future
zenorocha
310
42k
What's in a price? How to price your products and services
michaelherold
243
11k
Making Projects Easy
brettharned
115
5.9k
実際に使うSQLの書き方 徹底解説 / pgcon21j-tutorial
soudai
167
49k
How to Create Impact in a Changing Tech Landscape [PerfNow 2023]
tammyeverts
46
2k
VelocityConf: Rendering Performance Case Studies
addyosmani
325
23k
Typedesign – Prime Four
hannesfritz
39
2.3k
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
26
4.1k
Scaling GitHub
holman
458
140k
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