Running lint from command line lint not analysing java/kotlin files

778 views
Skip to first unread message

kiran puppala

unread,
Jul 12, 2021, 10:04:19 AM7/12/21
to lint-dev
We are trying to run lint with the command lint tool available at ~/Library/Android/sdk/cmdline-tools/latest/bin/lint. 

1. We placed our custom lint rules at ~/.android/lint/lint.jar

2. While running with the following command
 lint myProject,
we are getting this error,
build.gradle.kts: Error: "app" is a Gradle project. To correctly analyze Gradle projects, you should run "gradlew lint" instead. [LintError]
1 errors, 0 warnings
we had no working solution other than deleting all the build.gradle.kts files in our project.

3. After deleting project level and app-level build.gradle.kts files, we tried to again execute the command. 
lint myProject --xml ~/Desktop/report.xml
But surprisingly, it checks issues only in XML files and ignores all kotlin/java based files. 

Is this the expected behavior? Because, if we run the same rules using Gradle, all of those rules work perfectly.

Tor Norbye

unread,
Jul 14, 2021, 7:59:21 PM7/14/21
to lint-dev
The reason that warning tells you that it's a Gradle project and to use gradle instead is precisely because of this. Lint can't interpret the Groovy or Kotlin files in Gradle's build files, as well as any logic performed by third party Gradle plugins applied by the script, which can do things like add new source folders into project. If it's a Gradle project, you really should run Gradle's integration of lint which uses Gradle to figure out where the sources are, where the bytecode outputs are, what language levels to apply, and more.

If you remove the build.gradle files to trick it, it will assume that the directory layout is one of the old Android project layouts (which had AndroidManifest.xml at the root, Java sources in src/ and resources in res/ and will do some simple searches. It will not find src/main/java, src/test/java, etc. There are additional flags (see lint --help) to point it to other locations for manifest files, java source files, class files, etc. But that will flatten the world; lint won't know metadata like whether a manifest is in a library file, etc.

-- Tor

kiran puppala

unread,
Sep 7, 2021, 10:06:26 AM9/7/21
to lint-dev
Got it. Thanks for the reply, Tor.
Reply all
Reply to author
Forward
0 new messages