3

In my project I have defined many strings inside a core module. After upgrading to gradle 8 I see that I need to reference R files exactly now.

E.g. if I define a string inside my core module and want to access it from my main module (the main module includes the core module of course) I see following behaviour:

Before

I could access strings (and all other resources) from the core module inside the main module via com.my.package.main.R and com.my.package.core.R

After

Now I can only access the strings from the exact module anymore so I need to use com.my.package.core.R inside my main module to access strings from the core module...

The same happens for attributes from com.google.android.material.R and androidx.appcompat...


Did I miss a migration step? Or should this really be like that?

prom85
  • 16,896
  • 17
  • 122
  • 242

1 Answers1

10

With AGP 8 the default behaviour did change: See the option android.nonTransitiveRClass in https://developer.android.com/build/releases/gradle-plugin

android.nonTransitiveRClass

New default: true Old default: false

AGP 8.0 generates R classes for resources defined in the current module only.

Thommy
  • 5,070
  • 2
  • 28
  • 51
  • thanks. I was looking for this documentation, now everything is clear – prom85 May 11 '23 at 11:33
  • 2
    thanks a lot. that fixes my project. Went to gradle.properties and add android.nonTransitiveRClass=false to merge R from other modules or libs. – LinuxFelipe-COL Jun 15 '23 at 05:26
  • I cannot say for certain if this is related, but after doing this change, I also had to `enableBuildConfig` as outlined [here](https://stackoverflow.com/a/75450056/2480714) for some reason. After doing that, I was able to create a signed build. – PGMacDesign Jun 16 '23 at 23:36