I am trying to enable `nonTransitiveRClass` in my...
# android
j
I am trying to enable
nonTransitiveRClass
in my project, but to avoid a bunch of import alias I thought I could encapsulate the R classes from library modules and avoid the class name conflict... How to encapsulate the
R
or
R.string
class in my class ? I tried this
Copy code
object MyR {
    val string: R.string = R.string
}
but I get this
e
doesn't work,
R.string
is a class not an object
j
I know, I posted the code to illustrate what I tried...
and what I am trying to archive
e
you can
Copy code
import my.R as MyR
but will have to do so in every file that uses it
j
that is what I am trying to avoid... and I can't do that in my java files
e
that isn't a Kotlin question then… but for Java, no way around it unless you create a wrapper for each constant, which breaks lint checks
j
it is a kotlin question as I am asking the correct syntax to do it in Kotlin. I want to keep a reference to the R class in my own class and access it.
e
the answer is you can't
j
Ok, thanks
t
Would be nice if
typealias
allowed referencing subclasses like this:
Copy code
typealias MyR = com.my.package.R
val description = MyR.string.some_description
But it doesn't work. You could however define a typealias for each of
R.string
,
R.drawable
... but that's quite verbose.