Roberto Leinardi
Roberto Leinardi

Reputation: 14399

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

Upvotes: 4

Views: 1279

Answers (2)

Roberto Leinardi
Roberto Leinardi

Reputation: 14399

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.

Upvotes: 7

Martin Zeitler
Martin Zeitler

Reputation: 76779

The scope of these classes seems to be package private, compared to class SpeedDialState. Maybe take a look at other composable libraries, in order to see how they do it:
https://github.com/jetpack-compose/jetpack-compose-awesome#libraries

Upvotes: 1

Related Questions