Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Run lint when building android studio projects

I would like to be able to run the lint task when I'm building projects with the android studio to ensure the lint rules are being followed.

I have tried using task dependencies but with no luck. My TeamCity build server uses the build task which runs the lint task so that works great. However, the android studio appears to use generateDebugSources and compileDebugJava tasks interchangeably when I have selected the debug build variant.

Here is what I have tried in my build.gradle:

assemble.dependsOn lint 
like image 683
Robert Avatar asked Apr 03 '14 22:04

Robert


People also ask

How do I run lint on android?

Run lint using the standalone tool If you're not using Android Studio or Gradle, you can use the standalone lint tool after you install the Android SDK Command-Line Tools from the SDK Manager. You can then locate the lint tool at android_sdk /cmdline-tools/ version /bin/lint .

What is lint command?

Description. The lint command checks C and C++ language source code for coding and syntax errors and for inefficient or non-portable code. You can use this program to: Identify source code and library incompatibility. Enforce type-checking rules more strictly than does the compiler.


2 Answers

If you just want to configure your Android Studio project to run the lint check before the default run configuration without affecting how your gradle tasks are configured, you can follow these steps.

  1. Open the run configurations drop down and choose edit

enter image description here

  1. Select your app run configuration

enter image description here

  1. Press the '+' to add a new step

enter image description here

  1. Choose "Gradle-aware Make"

enter image description here

  1. Type 'check' and choose the option with your app module name and check. (Mine is :app:check)

enter image description here

  1. Press the up arrow to move the new check step before the existing Gradle-aware make step

enter image description here

Now, Android Studio will run the lint check and fail the build if any lint errors occur.

like image 89
Ross Hambrick Avatar answered Oct 01 '22 16:10

Ross Hambrick


To runt lint and analyze your project, simply select Analyze > Inspect Code.

You should get a nice window with all issues.

enter image description here

Also check Run lint in Android Studio for more information.


I did a little more research, try adding this to your build.gradle.

lintOptions {       abortOnError true   }  

There are many options that you can apply to the build.gradle

like image 42
Andrew Gable Avatar answered Oct 01 '22 17:10

Andrew Gable