Search code examples
androidkotlinresourcesbuild.gradleaar

Unresolved aar resources


I'm building a custom multi-project hierarchy of Android libraries shared in multiple apps. For example: enter image description here

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 ?


Solution

  • 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