Lint checks across modules in the same project

2,995 views
Skip to first unread message

Emmanuel Boudrant

unread,
Feb 21, 2018, 2:47:55 PM2/21/18
to lint-dev


Hi,

I have a project that include module A and module B. Module A have a set of strings resources. Module B is using strings from module A. Some strings are using formatter (like %s)

- Module A : <string name="my_string">my_string missing percent s</string>
- Module B : res.getString(R.string.my_string, myStringParam) // will crash

The warning show up if the string and string usage are in the same module but if they are in different modules it do not warn. I would expect to see :



Is it possible to have lint do resource usage checks across multiple modules.

Thanks !
-emmanuel

Tor Norbye

unread,
Mar 12, 2018, 11:33:58 AM3/12/18
to lint-dev
Try 
android.lintOptions.checkDependencies true

That way, lint will include the resources from all of its upstream modules in its analysis. It's the only way to get accurate unused resource checks etc. But it does mean that lint is slower since shared modules are analyzed many many times -- so I switched it from default true to default false back in 3.0.

-- Tor

t-harli...@traveloka.com

unread,
Apr 18, 2018, 9:16:19 AM4/18/18
to lint-dev
Hi Tor,

I also have same problem about checking cross module resources. These resources are vector drawables instead of strings.
I have a project with minimum sdk 16. To support vector image, the project use android support library. The vector drawable must be referred using app:srcCompat in xml instead of android:src. If I use android:src, lint shows VectorDrawableCompat issue as an error only for vector inside the same module. It doesn't show any error for vector drawables from another module. 
I have tried to set android.lintOptions.checkDependencies true, but it doesn't work.
Is there another solution to this?

Thanks,
Harlie

Tor Norbye

unread,
Apr 19, 2018, 12:13:18 PM4/19/18
to lint-dev
Can you file a bug with more specifics?

One thing I'm looking into to solving these dependency-resources-issues once and for all is to implement resource repository lookup as mandatory; right now it's only available in the IDE, not from the command line, which means that in batch mode lint has to accumulate resources on its own, which won't happen in checkDependencies is false. With the resource repository I'd populate it from the merged resource output in each library, and that should solve a lot of these difficulties.

-- Tor

t-harli...@traveloka.com

unread,
Apr 20, 2018, 2:30:17 AM4/20/18
to lint-dev

I have tried to reproduce it on a sample project that has 2 modules: app and core. App module depends on core module.


There are 2 vector drawables: 

- ic_home_black_24dp.xml in app

- ic_help_black_24dp.xml in core.


Those images are included in activity_main.xml inside app module like this:

I have configured build.gradle with lintOptions.checkDependencies true.

If I run lint from command line: gradlew app:lintGeneralDebug (General is a product flavor), only ImageView with source ic_home_black_24dp.xml is detected as error by lint.



I also have tried to run Analyze -> Inspect code with module app as inspection scope. It produces similar result:


I hope these details can explain the problem.

I'm looking forward to your solution.

Thank you,
Harlie
Reply all
Reply to author
Forward
0 new messages