How can I run AndroidStudio code inspection in the terminal

Viewed 600

I'm developing Android app with kotlin. I wonder how can I run the AndroidStudio code inspection in the terminal. I know android lint. But many of the inspection are not check by running ./gradlew lint. For example, if I wrote

var name = "chris"
Log.d("mytag", name)

AndroidStudio code inspection would remind my that name is never changed and could be change to val name = "chris". But when I run ./gradlew lint, this improvement option is not in the result report.

How can I run the inspection in the terminal? That way, I can make a gradle task to check the code and gradually introduce some good practice to my team.

1 Answers

Just as what said in official doc,

You can manually run configured lint and other IDE inspections by selecting Analyze > Inspect Code.

the warning "var could be changed to val" comes from so-called other IDE inspections.
There is not many documents about running IDE inspections from command line, but I found this which helped me a lot.
If you are using Android Studio instead of IntelliJ IDEA, the shell script is named not idea.sh but studio.sh, which can be found in the bin folder locates in where you install your Android Studio.
Actually, in the bin folder there is a shell script named inspect.sh you can use directly instead of studio.sh inspect.

Related