Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refer to main gradle.properties for lint configuration #335

Merged
merged 1 commit into from
Mar 18, 2019

Conversation

ShaishavGandhi
Copy link
Collaborator

Description: This changes the lint check to look for app level gradle.properties file instead of every library's. Relevant lint thread. This would require that you app level build.gradle has checkDependencies=true in it's lintOptions. Only then will lint be able to figure out that the library is part of the main project.

Related issue(s): Resolves #333

@@ -36,6 +36,10 @@ android {
sourceSets {
main.java.srcDirs += 'src/main/kotlin'
}

lintOptions {
checkDependencies true
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does this do exactly?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For Lint to detect the mainProject, you'd need your :app module to have checkDependencies = true. This basically means that when you do ./gradlew :app:lint, it goes down and runs lint on its dependencies also.

From Tor's message


Only analyze app/leaf modules

If you have divided your project into many smaller modules - a number of libraries and just a couple of app modules, it's much better to (a) turn on checkDependencies mode and (b) only run lint on the app modules, instead of recursively running lint on each module.

To do this, first add this to your app module's build.gradle file:

android {
    ...
    lintOptions {
        ...
        checkDependencies true
        ...
    }
}         

Then instead of running ./gradlew lintDebug, run ./gradlew :app:lintDebug.

Since you've turned on check-dependencies-mode, running lint on the app module will also run it on all the dependent modules the app depends on -- e.g. all the libraries. But this should also make things run a lot faster, since it's a single lint invocation, where lint shares a lot more computation (such as symbol resolution in the SDK and various shared libraries, etc).

This isn't just a good idea from a performance perspective; you'll also get more accurate results. For example, the unused resource analysis will now correctly know whether a resource defined in a library is consumed by the app module; that doesn't happen when you run lint first on the library, and later on just the app, which is what happens when you run ./gradlew lintDebug. As a bonus you'll also get a single HTML report containing all the results from your codebase, instead of having to hunt around the tree for all the various reports and look at each one separately.

For AutoDispose, this is required since mainProject will only refer to the parent project when you have checkDependencies=true. If you run lint individually on a library module, mainProject = project and there's no way to get access to parent project.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting. I always thought this would be slower for some reason

@ShaishavGandhi ShaishavGandhi merged commit f5f0d64 into master Mar 18, 2019
@ShaishavGandhi ShaishavGandhi deleted the sg/library-lint-project branch March 18, 2019 22:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants