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

Handling resources usage accros modules #441

Open
tasomaniac opened this issue Mar 10, 2022 · 3 comments
Open

Handling resources usage accros modules #441

tasomaniac opened this issue Mar 10, 2022 · 3 comments
Labels
bug Something isn't working

Comments

@tasomaniac
Copy link
Contributor

I had a lot of false positives when I tried disableAndroidResources feature. This happens especially when resources are used across modules.

Imagine a module has a String resource that is used by android module. ModuleCheck will suggest to put buildFeatures.androidResources = false in android {} block. This will actually compile fine.

But then during application's assemble task and during resource linking process, build will fail because of AAPT.

Here is an example error that happens in upstream module when resources disabled in downstream:

Execution failed for task ':app:processDebugResources'.
> A failure occurred while executing com.android.build.gradle.internal.res.LinkApplicationAndroidResourcesTask$TaskAction
   > Android resource linking failed
     ERROR:/Users/redacted/app/src/main/res/xml/xml_file.xml:79: AAPT: error: resource string/some_string_resource not found.
         
@RBusarow RBusarow added the bug Something isn't working label Mar 14, 2022
@RBusarow
Copy link
Member

Thanks for the report! I was able to reproduce this.

Auto-disabling androidResources seems to work correctly, unless the module is referencing its own R (or some other module is -- but that's a strange thing to do in this case).

In order to disable androidResources:

  1. the module can't have any res files of its own
  2. there can be no references to the R file (since it wouldn't be generated)
  3. no AndroidManifest.xml can reference any resources at all??
    a. I would have to experiment with how this works with nonTransitiveRClass
  4. no resValues defined in its Gradle config
  5. the module can't be an application module

@tasomaniac
Copy link
Contributor Author

This is a very good summary for sure. When nonTransitiveRClass is not enabled, there could be another edge case:

In parent modules, developers can accidentally use the wrong R import. It can both be the merged R class with the package name of the parent module. Or it can also be the R class from any of the dependant modules.

@RBusarow
Copy link
Member

Yeah, the most common cause I've seen for using the "wrong" R is when copy/pasting. It happened all the time when creating Espresso robots.

I hope to be able to fix this within the next couple of days.

Thanks again for the report!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants