Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Studio Lint check for Unnecessary Module Dependency

Tags:

When running a Lint check on files in my project I often come across an error that looks like this (actual names of files redacted, but you'll get the idea):

Dependency from module 'name_of_my_project' on module 'some_3rd_party_library' could be probably be removed when complementary scope to 'File 'filepath_to_the_class_being_analyzed' also does not contain references on module 'some_3rd_party_library'

I get this error for every single library that isn't compiled with Gradle - i.e. libraries that have been imported whole into the project and then added as dependencies.

Facebook is a great example of a library that even if you wanted to compile it through Gradle you couldn't because they don't support it, and you need to run it as a local library - it seems like you'll then receive this "unnecessary module dependency" warning for every class that doesn't directly call Facebook.

So, the question is - what is the "proper" way of handling this error? Do I ignore it or am I supposed to change the code in some way to make it disappear?

Edit: in the preferences menu for Lint it describes the check as follows (in case this helps figure it out):

This inspection lists modules which contain redundant dependencies on other modules. These dependencies can be safely removed.

like image 347
Jon Avatar asked Feb 22 '15 12:02

Jon


People also ask

What is lintOptions?

lintOptions { abortOnError false } This means it will run lint checks but won't abort the build if any lint error found. By default, its true and stops the build if errors are found.

How do you make lint baseline?

First, create a new project. Perform a Gradle sync. Then run lint: Analyze > Inspect Code; choose the whole project. Lint should now run, the Inspections View opens up, and in the bottom right corner a bubble tells you that lint has created a baseline file with the current issues.


1 Answers

There are known issues with the Lint checkers. I do not get this error in Android Studio 2.1.1. However, if you still do and you know it to be spurious, I would recommend going to Settings --> Editor --> Inspections --> Unnecessary Module Dependency and changing the Severity type from Warning to Info. This way you get a "clean lint build" and avoid a "broken windows" type of state due to bad lint algo. In fact, I've created a special category that has Info severity called Info Due To Bad Lint Algo to which I've assigned whatever I know to be spurious. This way I can periodically review those and see if they've been fixed.

You should report this to them btw, so there is some hope of it getting fixed... Good luck!

like image 80
Creos Avatar answered Oct 07 '22 18:10

Creos