PrivateResources check for Android modules

214 views
Skip to first unread message

Bryan Herbst

unread,
Jul 16, 2020, 3:46:51 PM7/16/20
to lint-dev
I've been digging into why the PrivateResources check does not work in multi-module project (https://issuetracker.google.com/issues/78151517), because private resources are something that we would very much like to have in our very large multi-module project.

It appears as though the root cause is that Android library modules are treated differently from AARs, but are represented by the same models. Specifically, both are represented internally as AndroidLibraryImpl, but since AARs are not generated for library modules the system for finding the location of public.txt fails.

AndroidLibraryImpl's folder field for Android library modules ends up looking like /Users/androiddev/MyApplication/mylibrary/build/intermediates/library_manifest/debug/AndroidManifest.xml and thus getPublicResources() ends up being [...]/AndroidManifest.xml/public.txt, which is obviously a non-existent file.

Would this be something that the tools team would be open to getting an external contribution to fix?

Tor Norbye

unread,
Jul 29, 2020, 1:38:31 PM7/29/20
to lint-dev
Yes, but -- we're actually rewriting all of this. Lint has for a long time relied on the "builder-model" API to communicate with Gradle to find out project information like dependencies, library prefixes, and various other pieces of information (whether a given file is in a debug specific source set, whether shrinking is turned on, etc etc).

This was problematic for a number of reasons, and one very big one is build performance. 

So in 4.1 we've already removed builder-model from lint's dependencies, and in place there's a "lint-model", which initially looks very very similar to the old builder-model API, but somewhat simplified, and omitting many of the things in builder-model that lint doesn't care about (builder-model was primarily intended to communicate the project layout to the IDE, for "Gradle Sync"). In 4.2, we've continued this work, and soon (as always, no promises!) we'll switch over to AGP generating builder model via separate tasks, which should help build performance.

This feature (private resources) was initially designed to help users of libraries (especially the support library) not accidentally use resources we considered private; it wasn't really built to be used for local project filtering. And it's not a super solid foundation since there isn't actually a real notion of private resources; if two modules declare the same "private" resource of the same type and name, they will clash. A much better, real implementation of private resources is possible with our resource namespace work, but that's not ready yet.

Having said that, being able to have some private resource handling locally does make sense. This code is pretty actively being worked on (for example https://android.googlesource.com/platform/tools/base/+/2addaa857de88fe8e4beb6a9369e83d0b72a3757 ) so it's something we should look at; I'll add Yuriy to that bug.

-- Tor

Julio Cesar Bueno Cotta

unread,
Aug 2, 2021, 11:06:53 AM8/2/21
to lint-dev
Hello there, 

Tor, would you have an update on this? Should it be working on AGP 4.2.2 ? Or 7.0.0 ?

Tor Norbye

unread,
Aug 2, 2021, 11:19:00 AM8/2/21
to lint-dev
We've fully switched over to the new lint model as of 4.2 and refined it further in 7.0 but we haven't looked into this issue yet as far as I know.

-- Tor

Reply all
Reply to author
Forward
0 new messages