Resource references break after moving to non-transitive R classes
android.nonTransitiveRClass=trueShort answer
With non-transitive R classes, a module's R holds only that module's own resources. Code that reads a library's string or layout through the app's R no longer compiles. Run Refactor, Migrate to Non-Transitive R Classes, or rewrite the references to the owning module's R. The setting is on by default since Android Gradle plugin 8.0.
Fix it fast
1Find out which cause you have
Look at the flag in gradle.properties. No line means you are on the AGP default, which is on since version 8.0.
grep -n "nonTransitiveRClass" gradle.properties2Match what you see, then jump to its fix
- 1
Compile errors start in the app module right after upgrading AGP or turning the flag on, on references to resources that live in a library moduleCode reaches a library's resources through the app's R classFix - 2
The project built before upgrading Android Gradle plugin to 8.0 or newer and has no nonTransitiveRClass lineAn upgrade to AGP 8 flipped the default while the code was written for the old behaviourFix
- 1
What does the error look like?
android.nonTransitiveRClass=trueRefactor > Migrate to Non-Transitive R Classes
Cause 1 of 2
Code reaches a library's resources through the app's R class
1Check
Each module's R class only lists resources defined in that module, not those of its dependencies. Find where the resource is declared and compare it with the module whose R you used.
grep -rn "name=\"my_title\"" --include=*.xml .2Fix
Use Android Studio's refactoring, which rewrites the references and the namespace for you, then build. It lives under Refactor in the menu bar.
# Android Studio
Refactor > Migrate to Non-Transitive R Classes
# then
./gradlew assembleDebug3Verify
The app module compiles with the flag on.
./gradlew assembleDebugConfirmed by developer.android.com
Cause 2 of 2
An upgrade to AGP 8 flipped the default while the code was written for the old behaviour
1Check
AGP 8.0 changed android.nonTransitiveRClass from false to true, so a project with no explicit line switches behaviour on upgrade.
grep -n "com.android.application\|com.android.library" build.gradle* app/build.gradle*2Fix
To get a working build today, write the old value into gradle.properties, then migrate in your own time and delete the line afterwards.
# gradle.properties
android.nonTransitiveRClass=false3Verify
Sync and build; the old references compile again.
./gradlew assembleDebugConfirmed by developer.android.com
How do I stop it coming back?
- Keep the flag at its default and fix references when a module is added, instead of switching it off.
- Reference a resource through the R class of the module that declares it.
- Run a full assemble in CI after each AGP upgrade.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine built on the same technologies:
Related fixes
Mobile apps
adb cannot start because something already holds its port
adb start-server failed
The adb server must bind local TCP port 5037, and every adb client talks to it there.
2 causes, each with a fixMobile apps
The phone shows as unauthorized and Android Studio will not run the app
adb devices lists the phone but Android Studio cannot deploy to it
An unauthorized phone means it has not trusted this computer's RSA key.
3 causes, each with a fixMobile apps
Android Studio cannot pair the phone over Wi-Fi
The Pair devices over Wi-Fi dialog lists no device
Wireless pairing needs the phone on Android 11 or higher and on the same Wi-Fi network as the computer, with current Platform-Tools.
4 causes, each with a fixMobile apps
adb cannot connect to its daemon or start the server
* daemon started successfully *
The adb server is a background process on your computer that listens on TCP port 5037.
2 causes, each with a fixMobile apps
adb prints 'server version doesn't match this client; killing...'
adb server version doesn't match this client; killing...
adb runs a background server, and every adb command is a client.
3 causes, each with a fixMobile apps
adb tcpip 5555 fails because no device is found
adb: more than one device/emulator
adb tcpip only works while the device is attached and listed by adb, because it tells the phone to start listening on port 5555.
4 causes, each with a fix