3

I am trying to modularize my application and I have a shared module where I put my shared resources and strings. In my module I have a dependency to the shared module as following:

implementation(project(Modules.shared))

Let's say I am working in Onboarding Module. When I want to call R.string.mystring, mystring is not found. But when I write packageNameOfSharedModule.R.string.mystring, it works.

In another projects, I can access any resource from the current modul's package.

What I am missing ? Thanks in advance!

1 Answers1

5

That would be "non-transitive R files"

https://blog.blundellapps.co.uk/speed-up-your-build-non-transitive-r-files/

Check if you have this in your gradle.properties file:

android.nonTransitiveRClass=true
Blundell
  • 75,855
  • 30
  • 208
  • 233
  • 1
    I had it in my gradle.properties. Once I removed it, it worked properly. Thanks! You saved my day ! But I think it's recommended to have non transitive R class to have a smaller APK size. – Othmane_lam Jun 24 '22 at 13:37
  • NP. Yes Id recommend having it turned on and prefixing the resources with the correct packages. If you did scale your project to multiple developers, you'd find that having one module for all resources is not a practical solution (and becomes a bottle neck) but if its only ever going to be just you, its fine :-) – Blundell Jun 24 '22 at 13:48