Using Custom Lint Rules for non gradle project

141 views
Skip to first unread message

Sparsh Agrawal

unread,
Mar 25, 2021, 4:23:43 PM3/25/21
to lint-dev
The current project that we are working on will be migrated to BAZEL after some time. Hence, we won't be able to use the gradle build system. Now, In order to use lint without gradle, I am planning to run it by using lint from the android SDK tools. 

I wanted to know how to add a custom lint rule in this scenario. Because after the migration of the build system, we won't be able to use the build.gradle files anymore. So how can I make the lint tool present in the android sdk tools to use our custom lint rules, because earlier we use to specify that in the project build.gradle files, but now it won't be possible anymore. 

Please let me know how shall I approach this, or if there's any workaround for this situation.

Tor Norbye

unread,
Mar 25, 2021, 4:31:27 PM3/25/21
to Sparsh Agrawal, lint-dev
In the latest version (AGP7/Arctic Fox) you can use --lint-rule-jars <paths> to the lint command. In older versions (and still supported in the latest) you can set an environment variable before running lint; such as export ANDROID_LINT_JARS=/path/to/first.jar:/path/to/second.jar

--
You received this message because you are subscribed to the Google Groups "lint-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to lint-dev+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/lint-dev/05e6dabf-040a-4dd1-aeae-93d958cff679n%40googlegroups.com.

Sparsh Agrawal

unread,
Mar 25, 2021, 4:46:46 PM3/25/21
to Tor Norbye, lint-dev
Thankyou very much for the information.

Also, one more help needed.
Is there a way to run the custom lint rules on Github Actions CI given that we can't use gradle at any step. 

Here's my approach to do this:
I am thinking of adding the custom jar file to our project repository and then using that jar file when running lint from the android sdk tools. Is this the correct way? 

Tor Norbye

unread,
Mar 25, 2021, 5:23:41 PM3/25/21
to Sparsh Agrawal, lint-dev
I think Github actions lets you run whatever build scripts you want so I think you have a lot of flexibility in how you set this up -- it seems plausible to first run a build to generate the jar files from the check-sources, and then run lint with those jars on the product-sources. 

I don't know much about github actions though so either somebody else can chime in here or you might have more luck over on a github forum.

-- Tor

Sparsh Agrawal

unread,
Mar 26, 2021, 4:15:13 PM3/26/21
to lint-dev
Thanks for the quick response

Also, is there a way to build the jar file of the custom lint rule without using gradle? I searched on the web but was unable to find it. If you can provide any resource then please do. It'll be of much help to me.
Thanks once again.

Tor Norbye

unread,
Mar 29, 2021, 11:54:13 AM3/29/21
to lint-dev
Sorry, no -- that will depend on the build system you're using and we only support Gradle, though maybe somebody else can chime in if they've done this. 

The Gradle lint check example (documented here: http://googlesamples.github.io/android-custom-lint-rules/book.html#example:samplelintcheckgithubproject ) shows you the dependencies you have to include somehow; if you're not using a build system that can download Maven dependencies you'll need to download the maven dependencies manually (if you go to maven.google.com you can search for libraries and download the artifacts directly).

Reply all
Reply to author
Forward
0 new messages