Dharsam1990
Dharsam1990

Reputation: 141

Issue with non transitive R class migration

I want to run the Non transitive R class migration for my project.

As of now I can only do that from Android Studio with the action Refactor > Migrate to Non-Transitive R classes...

But we have React Native code as well which is hosted in npm repository and get added as node_modules post running npm ci command. Hence, in our CI/CD, build fails because there are R class references in React Native libraries.

For example, React Native uses an open-source library named react-native-screens where an R class is referenced in the ScreenStackHeaderConfig.kt class.

I want to know if there is a command line option available to migrate to Non-Transitive R class or can we do it only for specific modules?

Upvotes: 3

Views: 5910

Answers (2)

Mori
Mori

Reputation: 4651

For projects created with earlier versions of Android Studio, update them to use non-transitive R classes by going to Refactor > Migrate to Non-Transitive R Classes...

Then it will show you the targets, so you can change manually or auto,

Ex: com.my.moduleB.R.string.hello instead of R.string.hello.

If you changed them manually , you must

/gradle.properties -> android.nonTransitiveRClass=true 

Upvotes: 0

Huy.Vu
Huy.Vu

Reputation: 259

For anyone who is having the same problem, just:

  1. Go inside gradle.properties and add:
    android.nonTransitiveRClass=false
  2. Gradle Sync -> Rebuild

I don't know why everyone keeps telling to set android.nonTransitiveRClass=true,
because that's opposite from what we really want.

Upvotes: 5

Related Questions