Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

android lint unused resources from library module are used in app

My app is split up in a main app and different library modules. When I run

./gradlew lint  

each module is checked independently and for each module a lint.xml file is generated. In the lint.xml files there were tons of unused resources warnings, but that resources are used in the main app. How can I configure lint to check globally in the app if a resources is used or not?

Thanks :)

like image 938
sbo Avatar asked Sep 15 '15 09:09

sbo


People also ask

How do I find unused resources in Android?

You can easily search for unused resources from Android Studio. Just press Ctrl Alt Shift i and type "unused resources" (without quotes). That will execute lint.

What is lint what is it used for Android?

The lint tool checks your Android project source files for potential bugs and optimization improvements for correctness, security, performance, usability, accessibility, and internationalization. When using Android Studio, configured lint and IDE inspections run whenever you build your app.

How do you use lint on Android?

To utilize Lint or just run inspections in your project, add Lint inspection to the lint. xml file or manually pick the list of issues to be configured by Lint in your project using Android Studio. Configure the lint file: Add the list of issues to be configured in the lint.

How do you check for lint errors?

Module and file-specific preferences Run the lint tool on your module by right-clicking on your module folder or file in the Project View and selecting Analyze > Inspect Code. This displays the lint inspection results with a list of issues that lint detected in your module.


1 Answers

The trick is to only check your app component and the rest of the app recursively through there:

Enable recursive lint checks

android {     lintOptions {         checkDependencies true     } } 

Only check app

./gradlew :app:lintDebug 

This will not only fix the unused resources issues, but it's also faster since lint is only called once instead of once per module. This means that things like symbol resolution in the SDK are only done once.

like image 152
Cristan Avatar answered Oct 05 '22 00:10

Cristan