Reputation: 285
I'm building a custom multi-project hierarchy of Android libraries shared in multiple apps. For example:
In my APPs I can correctly use both Kotlin Class and xml resouces of implemented aars.
In my second-level libraries (e.g. Library D) I can correctly use Kotlin Class of compileOnly first-level aars (e.g. Library A). I can also correctly use xml resources from first-level aars only in seconds level xml resources. For example:
<TextView
android:layout_height="wrap_content"
android:textColor="@color/MY-COLOR-FROM-1-LEVEL-AAR"
android:layout_width="0dp" />
It works.
But I cannot use the same resource in Kotlin classes. Example:
someView.setCardBackgroundColor(ContextCompat.getColor(context,R.color.MY-COLOR-FROM-1-LEVEL-AAR))
give me "Unresolved reference".
In the second-level libraries (e.g. Library D) build.gradle I import first-level libraries (e.g. Library A) using:
compileOnly files('libs/LibraryA.aar')
What's the problem ?
Upvotes: 1
Views: 1056
Reputation: 131
Enables namespacing of each library's R class so that its R class includes only the resources declared in the library itself and none from the library's dependencies, thereby reducing the size of the R class for that library
change value of this flag
android.nonTransitiveRClass=true
to
android.nonTransitiveRClass=false
Upvotes: 1
Reputation: 285
After several test I found the solution. In gradle.properties file of second-level project (in this example case Library D) simply change
android.nonTransitiveRClass=true
to
android.nonTransitiveRClass=false
Upvotes: 2