Search code examples
androidandroid-gradle-pluginandroid-jetpack-composeaar

Unresolved reference when using a generated AAR with Composables


I'm in the process of porting my FloatingActionButtonSpeedDial library to Compose and I've reached the step where I should publish the new Compose library to maven central but, when I generate the AAR, all the composable classes throw an Unresolved reference.

enter image description here

The crazy thing is that the the enum on the same package is perfectly fine and so is the AAR of the classic view library. So, the issue seems to affect only functions annotated with @Composable.

The issue happens with both a debug and release AAR so should not depend on minimization on release.

And of course the issue does not happen if I import the gradle module directly instead of using the AAR.

Do I need to do something special to generate an AAR with Composable?

This is build.gradle of the library module


Solution

  • The issue is caused by the packagingOptions:

        packagingOptions {
            resources {
                exclude '.readme'
                exclude 'LICENSE.txt'
                exclude 'fabric/*.properties'
                // Exclude the Firebase/Fabric/other random properties files
                exclude '/*.properties'
                // Exclude AndroidX version files
                exclude 'META-INF/*.version'
                // Exclude consumer proguard files
                exclude 'META-INF/proguard/*'
                exclude 'META-INF/*.properties'
                exclude 'META-INF/LICENSE.txt'
                exclude 'META-INF/MANIFEST.MF'
                exclude 'META-INF/NOTICE.txt'
                exclude "META-INF/AL2.0"
                exclude "META-INF/LGPL2.1"
                exclude 'META-INF/maven/com.google.guava/guava/pom.properties'
                exclude 'META-INF/maven/com.google.guava/guava/pom.xml'
                exclude 'META-INF/*.kotlin_module'
                // for byte-buddy
                exclude "META-INF/licenses/ASM"
                pickFirst "win32-x86-64/attach_hotspot_windows.dll"
                pickFirst "win32-x86/attach_hotspot_windows.dll"
            }
        }
    

    And, in particular by the exclude 'META-INF/*.kotlin_module': this file is needed to access top-level members, so don't exclude it.

    It would be better clear this exclusion list and only add what's necessary to get the project to build.