https://kotlinlang.org logo
#android
Title
# android
s

Simon Hardt

02/07/2023, 9:35 AM
I'm trying out AS flamingo and updated to AGP
8.0.0-beta01
. now I have to use the correct import for the R class when a resource is in a different module. is this intended? normally, one can use the R of the current module and get access to all other resources in all other modules automatically. it's now
com.example.text.R.string.
instead of
R.string.
(with
import com.example.ui.R
)
😶 2
you can import multiple
R
classes at the same time, as long as you give them different aliases
Copy code
import com.example.text.R as TextR
import com.example.ui.R

findViewById<TextView>(R.id.foo).text = getString(TextR.string.bar)
1
👍 1
s

Simon Hardt

02/07/2023, 9:48 AM
ah, perfect. there's a wizard for it (already did it manually across 800 files 😄) https://developer.android.com/studio/build/optimize-your-build#use-non-transitive-r-classes THX!
what if the option is grayed out?
e

ephemient

02/07/2023, 9:52 AM
I don't know, I migrated my codebase to non-transitive R classes years ago, without the wizard. but possibly it sees that the value is already set to
true
(by defaults changed in AGP 8.0) so there's nothing to migrate, maybe if it were explicitly
false
it would offer to run the wizard?
s

Simon Hardt

02/07/2023, 9:58 AM
yes, that's it. setting
android.nonTransitiveRClass=false
enables this option
25 Views