My team and I develop Android apps and have decided on coding guidelines that all should follow. I therefore started implementing custom lint rules as per the following links:
The problem that I'm having is actually implementing these lint rules on a project basis. When I run ./gradlew clean build test install
, as specified the rules apply and all is well. However when I build the aar library with ./gradlew aarWrapper:assemble
and add it to my libs
folder the linting does not work.
I added the following to my build.gradle
file to add the library
repositories { flatDir { dirs 'libs' } } dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) compile(name: 'aarWrapper-debug', ext: 'aar') }
I'm not sure what I'm missing but when I run ./gradlew lint
it runs the linter but not with my custom rules... Any help, tips or advice is greatly appreciated.
EDIT 1
Here is the terminal output when running gradle.
:app:preBuild UP-TO-DATE :app:preDebugBuild UP-TO-DATE :app:checkDebugManifest :app:preReleaseBuild UP-TO-DATE :app:prepareAarWrapperDebugLibrary UP-TO-DATE :app:prepareComAndroidSupportAnimatedVectorDrawable2421Library UP-TO-DATE :app:prepareComAndroidSupportAppcompatV72421Library UP-TO-DATE :app:prepareComAndroidSupportDesign2421Library UP-TO-DATE :app:prepareComAndroidSupportRecyclerviewV72421Library UP-TO-DATE :app:prepareComAndroidSupportSupportCompat2421Library UP-TO-DATE :app:prepareComAndroidSupportSupportCoreUi2421Library UP-TO-DATE :app:prepareComAndroidSupportSupportCoreUtils2421Library UP-TO-DATE :app:prepareComAndroidSupportSupportFragment2421Library UP-TO-DATE :app:prepareComAndroidSupportSupportMediaCompat2421Library UP-TO-DATE :app:prepareComAndroidSupportSupportV42421Library UP-TO-DATE :app:prepareComAndroidSupportSupportVectorDrawable2421Library UP-TO-DATE :app:prepareComAndroidVolleyVolley100Library UP-TO-DATE :app:prepareComCrashlyticsSdkAndroidAnswers138Library UP-TO-DATE :app:prepareComCrashlyticsSdkAndroidBeta121Library UP-TO-DATE :app:prepareComCrashlyticsSdkAndroidCrashlytics261Library UP-TO-DATE :app:prepareComCrashlyticsSdkAndroidCrashlyticsCore2310Library UP-TO-DATE :app:prepareComGoogleAndroidGmsPlayServicesBase961Library UP-TO-DATE :app:prepareComGoogleAndroidGmsPlayServicesBasement961Library UP-TO-DATE :app:prepareComGoogleAndroidGmsPlayServicesLocation961Library UP-TO-DATE :app:prepareComGoogleAndroidGmsPlayServicesMaps961Library UP-TO-DATE :app:prepareComGoogleAndroidGmsPlayServicesTasks961Library UP-TO-DATE :app:prepareIoFabricSdkAndroidFabric1312Library UP-TO-DATE :app:prepareDebugDependencies :app:compileDebugAidl UP-TO-DATE :app:compileDebugRenderscript UP-TO-DATE :app:generateDebugBuildConfig UP-TO-DATE :app:generateDebugResValues UP-TO-DATE :app:generateDebugResources UP-TO-DATE :app:mergeDebugResources UP-TO-DATE :app:processDebugManifest UP-TO-DATE :app:processDebugResources UP-TO-DATE :app:generateDebugSources UP-TO-DATE :app:incrementalDebugJavaCompilationSafeguard UP-TO-DATE :app:compileDebugJavaWithJavac UP-TO-DATE :app:compileDebugNdk UP-TO-DATE :app:compileDebugSources UP-TO-DATE :app:mergeDebugShaders UP-TO-DATE :app:compileDebugShaders UP-TO-DATE :app:generateDebugAssets UP-TO-DATE :app:mergeDebugAssets UP-TO-DATE :app:transformClassesWithDexForDebug UP-TO-DATE :app:mergeDebugJniLibFolders UP-TO-DATE :app:transformNative_libsWithMergeJniLibsForDebug UP-TO-DATE :app:processDebugJavaRes UP-TO-DATE :app:transformResourcesWithMergeJavaResForDebug UP-TO-DATE :app:validateSigningDebug :app:packageDebug :app:assembleDebug BUILD SUCCESSFUL Total time: 7.881 secs
EDIT 2
Forked project: https://github.com/apertomove/linette
build.gradle: https://github.com/apertomove/linette/blob/apertomove-linette/build.gradle
EDIT 3 In addition to the links above I found this post written by Jason Atwood. We too have a CI server running jenkins in which we can run our checks and inform developers of errors based off of our lint rules. This works great, however, it is one step to far. It would be much more valuable and time save to run lint checks from the library when running our projects out of Android Studio, instead of committing our code only to find out that our project breaks rules.
The lint tool checks your Android project source files for potential bugs and optimization improvements for correctness, security, performance, usability, accessibility, and internationalization. When using Android Studio, configured lint and IDE inspections run whenever you build your app.
In many cases, lint warns you about incorrect, error-prone, or nonstandard code that the compiler does not necessarily flag. The lint program issues every error and warning message produced by the C compiler. It also issues warnings about potential bugs and portability problems.
I have written a post on how to add and integrate custom lint rules to your android app, you can have a look. It also has links to github repos showing how its done in an android project. Link to post
The easiest way for me was to set ANDROID_LINT_JARS path in the gradlew file and point it to the custom lint jar which is checked in to VCS system, so that you can run it locally as well before pushing the code. Hope it helps.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With