Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Quality. Android quality. ENG (Droidcon Krakow 2016)

Quality. Android quality. ENG (Droidcon Krakow 2016)

Working at multi-project company I am experiencing with boring and time-expensive project/environment configuration every time I start developing a new project. I've tried a lot of different technologies and technics and now I have a list of effective tools which may help during project development from the beginning. I have two different approaches for long term and short term projects, which can be combined depend on project goals, timelines, etc… For instance this list contains some of the core things about CI configuration, UI testing configuration, sharing rules and guidelines within a team, documentation, etc… Also some quality tools, which can be easily integrable, reusable, informative with minimum effort. Some of these tools can be added in the middle of the project development just to increase project quality, find hidden issues, analyse app performance, etc.

Oleksandr Tolstykh

December 08, 2016
Tweet

More Decks by Oleksandr Tolstykh

Other Decks in Programming

Transcript

  1. Quality. Android quality HOW TO INCREASE CODE QUALITY AND SAVE

    PLENTY OF TIME WITH PROPER INITIAL PROJECT CONFIGURATION Oleksandr Tolstykh @a_tolstykh Sharewire, The Hague
  2. AGENDA 1. Quality tools 2. Developer tools 4. Other tools

    3. Application metrics tracking #qualityMatters
  3. 1. Quality tools - Lint - Findbugs - PMD -

    Checkstyle - Copy/Paste detector
  4. - Fully configurable #qualityMatters LINT - Out of the box

    - Android specific - 200 different checks - Custom rules QUALITY TOOLS. LINT Good article from Matt Compton: https://www.bignerdranch.com/blog/building-custom-lint-checks-in-android/ - Android studio integration
  5. #qualityMatters … or put lint config to lint.xml DO NOT

    IGNORE LINT ERRORS/WARNINGS! QUALITY TOOLS. LINT GOOD PRACTICE BAD PRACTICE
  6. #qualityMatters Check examples QUALITY TOOLS. LINT - MissingSuperCall If method

    defined with @SuperCall support annotation - CommitTransaction When you forget to call commit() on fragment transaction - DuplicateIds Same ids in layout file - ResourceType Incorrect type of resource id passed (@StringRes, @DrawableRes, @ColorRes) - NewApi Calling new methods on older versions … and many others Complete set of checks: http://tools.android.com/tips/lint-checks
  7. Quality tools Findbugs - Java bytecode analysis - Requires some

    effort to configure initially #qualityMatters http://findbugs.sourceforge.net/ https://docs.gradle.org/current/dsl/org.gradle.api.plugins.quality.FindBugs.html
  8. #qualityMatters Bug description examples QUALITY TOOLS. FINDBUGS - Method concatenates

    strings using + in a loop - Comparison of String objects using == or != - Method invokes toString() method on a String - Test for floating point equality - Method may fail to close stream - Unread fields/methods … and many others Complete set of bug descriptions: http://findbugs.sourceforge.net/bugDescriptions.html
  9. #qualityMatters Quality tools. PMD - Java source code analysis -

    Requires some effort to configure initially - Similar to findbugs, but has different checks and inspection methods - Contains Android specific Ruleset (5 rules) - List of Rulesets should be defined in config file https://docs.gradle.org/current/userguide/pmd_plugin.html #qualityMatters https://pmd.github.io/
  10. #qualityMatters Rule examples QUALITY TOOLS. PMD - GodClass - DoNotHardCodeSDCard.

    Use Environment.getExternalStorageDirectory() instead of “/sdcard” - AvoidInstantiatingObjectsInLoops - LooseCoupling. Avoid using implementation types (i.e., HashSet); use the interface (i.e, Set) instead - AvoidCatchingThrowable, AvoidCatchingNPE - UseArrayListInsteadOfVector - UncommentedEmptyMethodBody, UncommentedEmptyConstructor … and many others Complete set of rules: https://pmd.github.io/pmd-5.4.1/pmd-java/rules/index.html
  11. QUALITY TOOLS. CHECKSTYLE Checkstyle is a development tool to help

    programmers write Java code that adheres to a coding standard. It automates the process of checking Java code to spare humans of this boring (but important) task. This makes it ideal for projects that want to enforce a coding standard. #qualityMatters http://checkstyle.sourceforge.net/ https://docs.gradle.org/current/userguide/checkstyle_plugin.html CAN FIND: class design problems method design problems code layout issues formatting issues
  12. #qualityMatters https://pmd.github.io/pmd-5.4.1/usage/cpd-usage.html https://github.com/aaschmid/gradle-cpd-plugin - ignores duplications in imports and copyrights

    - can be launched as a stand-alone tool without integration (.bat/.sh) - works with cpp, go, java, matlab, objective-c, php, python, ruby, scala and other. Finding duplicated code or how to find copied and pasted code QUALITY TOOLS. COPY-PASTE DETECTOR
  13. QUALITY TOOLS “With all checks on the highest level of

    severity the development process is very similar to passing a computer game on the “Nightmare” difficulty level” #qualityMatters “Do not try to fix all the warnings and errors, sometimes you can reduce the quality of the project. Use these tools wisely. Add exceptions.”
  14. - Better app quality, readability. - Your team should be

    ready for it. - Extra effort for the first time. - Run all quality checks before making a commit. - Quality tools + CI = MAXIMUM PROFIT Add quality tools to your app (lint, findbugs, checkstyle, pmd, cpd, etc) QUALITY TOOLS #qualityMatters
  15. 2. Dev tools Inspired by qualitymatters article by Artem Zinnatullin

    https://github.com/artem-zinnatullin/qualitymatters - Stetho - LeakCanary - Lynx - Timber
  16. For instance we have: - General build info. Paperwork -

    Access to logs (network + logcat) - Changeable endpoint URL (integration with Mock-Server)! - Crash reporting - Diagnostic tools Debug only, scalable, stand-alone, not embedded into layout, not embedded into a project code! DEV TOOLS #qualityMatters
  17. #qualityMatters http://facebook.github.io/stetho/ DEV TOOLS. STETHO A debug bridge for Android

    applications. Open source. Developed by Facebook developers - Network Inspection - View Hierarchy - Database Inspection - dumpapp - a powerful command-line interface to application internals
  18. https://github.com/pedrovgs/Lynx DEV TOOLS. LYNX Lynx is an Android library created

    to show a custom view with all the information logcat is printing: - Text filtering - Filtering by log level - Logs sharing - Can appear by shaking the phone #qualityMatters
  19. - Ships with embedded lint rules!!! YOU WILL NOT LOG

    IN PRODUCTION! #qualityMatters https://github.com/JakeWharton/timber “Every time you log in production, a puppy dies.” – Jake Wharton DEV TOOLS. TIMBER - No more static final TAG constants - Can be enabled/disabled/replaced with one line
  20. DEV TOOLS. CRASH-REPORTING TOOL Doesn’t matter which one, but add

    it with the initial project configuration #qualityMatters - Log error/unexpected states - Skip exceptions from debug versions (Do not give Debug versions to test, release only) - Always check Crash-reporting tool dashboard - Add descriptive error messages when logging debug exceptions
  21. #qualityMatters DEV SETTINGS. SUMMARY - Add as many tools as

    your project needs. - Extract tools into a separate library, if you have too many. - Your developer settings should be easily maintainable.
  22. #perfMatters APPLICATION METRICS. GENERAL METRICS Always keep track of -

    Build time - Launch time - Application size - Test coverage (JaCoCo) https://docs.gradle.org/current/userguide/jacoco_plugin.html
  23. A real time frames per second measuring library for Android

    - Fps of your current window - Number of dropped frames within that window https://github.com/friendlyrobotnyc/TinyDancer APPLICATION METRICS. TINY DANCER #perfMatters
  24. #perfMatters @DebugLog public String getName(String first, String last) { SystemClock.sleep(15);

    // Don't ever really do this! return first + " " + last; } V/Example: ⇢ getName(first="Jake", last="Wharton") V/Example: ⇠ getName [16ms] = "Jake Wharton" - Logs arguments and return values for method - Logs execution time APPLICATION METRICS. HUGO Annotation-triggered method call logging for your debug builds. https://github.com/JakeWharton/hugo
  25. https://github.com/frogermcs/AndroidDevMetrics APPLICATION METRICS. ANDROID DEV METRICS - Measures activity lifecycle

    callbacks - Measures Dagger 2 object initializations - Allows schedule method tracing for the next launch - Counts fps drops PERFORMANCE METRICS LIBRARY FOR ANDROID DEVELOPMENT. #perfMatters
  26. RESOURCE MANAGING Strings (translations) or colors managing: - Manage all

    string resources in one place - Operate with ids in UX, not values - Do not change these files locally - Automate strings import if possible Difficulties with color naming? -> http://chir.ag/projects/name-that-color #DCD6D5 -> Swiss Coffee #FEE56D -> Kournikova https://crowdin.com/ https://localise.biz/ ...or Shared resource file
  27. SUMMARY - All given above tools are designed to help,

    but not annoy you. - Add only tools you will really need. - No warnings != no bugs. - The first time it may take longer.