Reputation: 1039
I have an android library for which I created 2 linting rules. In the project there are 3 packages, the main one with a sample app, the lib package, and the linting package. The only link between the lib and the lint modules that I can find, is in the build.gradle
of the lib
lintPublish(project(':app:linter_pkg'))
All is fine and well when I try the linting rules while the lib is brought in the sample like this
implementation project(path: ':app:myLib')
But as soon as I publish the library to github packages as a .aar
, and I bring the lib in the sample app using the remote package, one of the linting rules stops working.
And this doesn't make any sense to me. When the library is brought with local linkage both rules work, so clearly the code works. It doesn't seem like I am publishing the linting rules wrongly, since one of the rules still works. So the aar
gets downloaded and linked correctly.
I also inspected the build files and .class
files of what I am published and comapred them with what Android Studio produces when I link the lint locally and they are identical.
Any idea what would cause this sort of behaviour, only half of the build to be broken?
Upvotes: 4
Views: 357
Reputation: 578
You need to add this code in your project level build.gradle
file .
repositories {
maven { url "https://example.com/repo" }
}
dependencies {
lintChecks "com.example:custom-lint-rules:1.0.0"
}
and need to add custom lint checks: like:-
android {
lintOptions {
enable 'CustomLintCheck'
}
}
it works in my case
Upvotes: 0
Reputation: 882
I have to admit I am not an Android developer, so please forgive if my answer is not helpful or even wrong, but I have an idea of what went wrong here.
Looking at Google's example of custom lint rules, you will find that they have not nested their lint rules under the app
folder, but into a separate folder named checks
with using apply plugin: 'java-library'
in its build.gradle
and no android
section. When you nest the lint rules into app
, I assume that the build information of the app's build.gradle
is taken into account, which targets the Android runtime (which is not capable of the full Java API). However the lint rules are intended to be run under a real JVM/JDK, therefor it should have a completely independent build.gradle
.
Finally they publish the lint rules together with the lib as you did:
/** Package the given lint checks library into this AAR */
dependencies {
implementation project(':checks')
lintPublish project(':checks')
}
If my answer is wrong, you still might compare your project (and especially the build.gradle
of the lint rules) with the example and might find some crucial difference.
Upvotes: 0