Slide 1

Slide 1 text

Clean Code Base With Android Lint Sinan Kozak @snnkzk @[email protected] Harnessing the Power of Android Lint and Custom Rules

Slide 2

Slide 2 text

How to transfer our learnings and experience to others as a developer?

Slide 3

Slide 3 text

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

Slide 4

Slide 4 text

Are you using Android Lint checks? Is your setup up to date?

Slide 5

Slide 5 text

Default Rules Source code

Slide 6

Slide 6 text

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.

Slide 7

Slide 7 text

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

Slide 8

Slide 8 text

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

Slide 9

Slide 9 text

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

Slide 10

Slide 10 text

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

Slide 11

Slide 11 text

Open source lint rules https://github.com/vanniktech/lint-rules https://github.com/slackhq/slack-lints https://github.com/slackhq/compose-lints https://github.com/uber/lint-checks https://github.com/kozaxinan/android-lints

Slide 12

Slide 12 text

How to start now? Baseline file Own lint rule module

Slide 13

Slide 13 text

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

Slide 14

Slide 14 text

No content

Slide 15

Slide 15 text

No content

Slide 16

Slide 16 text

Thank you Q&A Sinan Kozak @snnkzk @[email protected]