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

Android_Makers_Lint_-_Google_Developer_Experts_...

 Android_Makers_Lint_-_Google_Developer_Experts_2022____Presentation_Slides_template.pdf

Sinan Kozak

April 27, 2023
Tweet

More Decks by Sinan Kozak

Other Decks in Programming

Transcript

  1. Clean Code Base With Android Lint Sinan Kozak @snnkzk @[email protected]

    Harnessing the Power of Android Lint and Custom Rules
  2. Android Lint Improve your code with lint checks The lint

    tool helps find poorly structured code that can impact the reliability and efficiency of your Android apps and make your code harder to maintain. Categories: Correctness Security Compliance Performance Usability Productivity Accessibility Internationalization Icons Typography Files: Java Kotlin Layout Manifest Gradle Proguard Property TOML Test Other
  3. Prevents runtime errors Some examples StringFormatDetector Check which looks for

    problems with formatting strings such as inconsistencies between translations or between string declaration and string usage. TranslucentViewDetector Specifying a fixed screen orientation with a translucent theme isn't supported on apps with `targetSdkVersion` O or greater since there can be an another activity visible behind your activity with a conflicting request.
  4. Checks for target sdk IntentFilterExportedReceiver Any intent with filters should

    be exported explicitly on Android 12 and higher Otherwise, installation will fail. IntentFilterExportedReceiver checks all intents in final manifest. https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/li bs/lint-checks/src/main/java/com/android/tools/lint/checks/ExportedFlagDetector.kt
  5. NotificationTrampoline Activities should not be launched indirectly Launching activity from

    Broadcast or service is not allowed after Android 12. Lint helps you during migration Do not ignore new lint errors https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/li bs/lint-checks/src/main/java/com/android/tools/lint/checks/NotificationTrampolineDetector.kt
  6. MutatingSharedPrefs What is wrong with SharedPreferences.getStringSet "Note that you must

    not modify the set instance returned by this call. The consistency of the stored data is not guaranteed if you do, nor is your ability to modify the instance at all." Lint prevents you to write not working code https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-stu dio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/Shar edPrefsDetector.kt
  7. Performance checks? JavaPerformanceDetector Lint does not now anything about runtime

    performance but there are obvious APIs that are faster than others. • DrawAllocation • UseSparseArrays https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/l ibs/lint-checks/src/main/java/com/android/tools/lint/checks/JavaPerformanceDetector.java
  8. Template repo https://github.com/googlesamples/android-custom-lint-rules • Google sample repo • Prevent calling

    unwanted methods and constructors • Teach better APIs • Documentation? • TDD during development