TOOLS OF THE TRADE
Hello! I AM ZARAH I am an Android developer for Domain.com.au
THE KEY Know available tools
THE KEY Know available tools There is no “correct” setup
CODE
FRAGMENTS
FRAGMENT LIFECYCLE FragmentManager. enableDebugLogging (true);
SERVICES
SERVICES @Override public void onCreate() { super.onCreate(); android.os.Debug. waitForDebugger (); // Do stuff in your service Log. d ("MyService", "I am inside the service!"); }
SERVICES @Override public void onCreate() { super.onCreate(); android.os.Debug. waitForDebugger (); // Do stuff in your service Log. d ("MyService", "I am inside the service!"); }
SERVICES ◦ Put a breakpoint AFTER the call to wait
SERVICES ◦ Put a breakpoint AFTER the call to wait ◦ Edit your Run Configurations
SERVICES ◦ Trigger service
SERVICES ◦ Trigger service ◦ Attach debugger <service android:name="com.myapp.MySyncService" android:exported="true" android:process=":sync" >
BUILT-IN TOOLS
DEBUGGER
DEBUGGER Say NO! to the green bug
DEBUGGER Say NO! to the green bug Create a new keyboard shortcut for Attach Debugger to Android Process
DEBUGGER Say NO! to the green bug Create a new keyboard shortcut for Attach Debugger to Android Process Preferences > Keymap > Main Menu > Run > Attach Debugger to Android Process > Right Click > Add Keyboard Shortcut
DEBUGGER Say NO! to the green bug Create a new keyboard shortcut for Attach Debugger to Android Process AIN’T NOBODY GOT TIME FOR Preferences > Keymap > Main Menu > Run > Attach Debugger to Android Process > Right Click > Add Keyboard Shortcut THAT!
DEBUGGER
DEBUGGER Run then Attach
BREAKPOINTS
BREAKPOINTS
BREAKPOINTS (AN ASIDE)
BREAKPOINTS
BREAKPOINTS Stop during interesting iterations
BREAKPOINTS Suspend on exceptions
BREAKPOINTS If you have a bunch of breakpoints related to a particular bug, GROUP THEM
DEBUG TOOL WINDOW
DEBUG TOOL WINDOW
FRAMES
VARIABLES
VARIABLES
EVALUATING EXPRESSIONS
WATCHES
WATCHES ◦ Add variables and expressions ◦ Resolved in the context of the current frame
WATCHES ◦ Add variables and expressions ◦ Resolved in the context of the current frame
WATCHES
WATCHES
WATCHES
WATCHES ◦ No need to Timber/Toast/Log
WATCHES ◦ No need to Timber/Toast/Log ◦ Like evaluated expressions, but lots of them
WATCHES ◦ No need to Timber/Toast/Log ◦ Like evaluated expressions, but lots of them ◦ Persistent across sessions
WATCHES ◦ No need to Timber/Toast/Log ◦ Like evaluated expressions, but lots of them ◦ Persistent across sessions ◦ Change expressions on the fly Do even more: IntelliJ blog
SYSTEM INFORMATION
SYSTEM INFORMATION Info dump of system state
SYSTEM INFORMATION
SYSTEM INFORMATION Activity Manager State Activity lifecycle state Config values Fragments and their states View hierarchy Choreography state Looper state
SYSTEM INFORMATION Activity Manager Package Info State Manifest information Activity lifecycle state APK info Config values User install info Fragments and their states View hierarchy Choreography state Looper state
SYSTEM INFORMATION Activity Manager Package Info Memory Usage State Manifest information Memory allocations Activity lifecycle state APK info Asset allocations Config values User install info Fragments and their states View hierarchy Choreography state Looper state
SYSTEM INFORMATION Memory Usage over Time Runtime stats Memory usages Low level info
SYSTEM INFORMATION Memory Usage Graphics State over Time How well animations are Runtime stats doing Memory usages Cache info Low level info View hierarchy
LAYOUT INSPECTOR
LAYOUT INSPECTOR
THIRD PARTY TOOLS
HUGO Annotation-based = EASY
HUGO Annotation-based = EASY Shows method calls++ 9477-9477/io.plaidapp V/DataManager: ⇢ sourceLoaded(data=[Redraw Keyboard, Saas 01, Air Traveller App, Become a driver], page=2, key="DRIBBBLE_QUERY_Material Design") 9477-9477/io.plaidapp V/DataManager: ⇠ sourceLoaded [0ms] = true https://github.com/JakeWharton/hugo
HUGO (AN ASIDE) logm live template
ADB PLUGIN App actions from within Studio
ADB PLUGIN No fussing with Settings https://github.com/pbreault/adb-idea
STETHO Wealth of options
STETHO Wealth of options ◦ DB inspection
STETHO Wealth of options ◦ DB inspection ◦ SharedPreferences
STETHO Wealth of options ◦ DB inspection ◦ SharedPreferences ◦ Network inspection
STETHO Wealth of options ◦ DB inspection ◦ SharedPreferences ◦ Network inspection ◦ View hierarchy
STETHO Wealth of options ◦ DB inspection ◦ SharedPreferences ◦ Network inspection ◦ View hierarchy ◦ dumpapp
STETHO Source: Facebook http://facebook.github.io/stetho/
PIDCAT Logcat with less pain
PIDCAT Logcat with less pain https://github.com/JakeWharton/pidcat
LEAK CANARY
LEAK CANARY Source: Square https://github.com/square/leakcanary
Some practical stuff
STUDIO IS BEING WEIRD Cannot add breakpoint
STUDIO IS BEING WEIRD Cannot add breakpoint ADB cannot see devices
STUDIO IS BEING WEIRD First aid
STUDIO IS BEING WEIRD First aid ◦ Unplug then re-plug device
STUDIO IS BEING WEIRD First aid ◦ Unplug then re-plug device ◦ Disable then re-enable ADB integration
STUDIO IS BEING WEIRD First aid ◦ Unplug then re-plug device ◦ Disable then re-enable ADB integration ◦ Invalidate caches and restart
STUDIO IS BEING WEIRD First aid ◦ Unplug then re-plug device ◦ Disable then re-enable ADB integration ◦ Invalidate caches and restart ◦ Disable the re-enable USB debugging on device
But I really don’t want to do all that...
BETTER CODING, (HOPEFULLY) LESS DEBUGGING Use support annotations
BETTER CODING, (HOPEFULLY) LESS DEBUGGING Use support annotations Listen to Lint
BETTER CODING, (HOPEFULLY) LESS DEBUGGING Use support annotations Listen to Lint Use AppCompat methods
ADDITIONAL RESOURCES Philippe Breault [Twitter] Jake Wharton [Github] Square [Github]
Thank you! ANY QUESTIONS? THANK YOU! www.zdominguez.com +ZarahDominguez @zarahjutz
APPENDIX
SUPPORT ANNOTATIONS Add the dependency** dependencies { compile 'com.android.support:support-annotations:24.2.0' }
SUPPORT ANNOTATIONS Profit private void setThingsToTextView(int res1, int res2, int res3, int res4) { // do stuff } private void setThingsToTextView(@IdRes int textView, @StringRes int introText, @DrawableRes int heroImage, @ColorRes int backgroundColour) { // do stuff }
SYSTEM INFORMATION Activity Manager State
SYSTEM INFORMATION Package Information
SYSTEM INFORMATION Memory Usage
SYSTEM INFORMATION Memory Usage over time
SYSTEM INFORMATION Graphics state
Recommend
More recommend