androidandroid-jetpack-compose

Android Studio won't build release build because of Compose Preview functions - NonExistentClass cannot be converted to Annotation


I get the following error

error: incompatible types: NonExistentClass cannot be converted to Annotation
@error.NonExistentClass()

at

@Preview("Drawer contents")
@Preview("Drawer contents (dark)", uiMode = UI_MODE_NIGHT_YES)
@Composable
fun PreviewAppDrawer() {
    AppTheme {
        Surface {
            AppDrawer(
                currentScreen = Screen.Home,
                onTopLevelScreenNavigate = {},
                closeDrawer = { }
            )
        }
    }
}

during release gradle build

How can I fix it?

Works fine for debug build


Solution

  • Fixed by adding missing dependency:

    implementation "androidx.compose.ui:ui-tooling-preview:$composeVersion"
    

    Final:

    implementation "androidx.compose.ui:ui-tooling-preview:$composeVersion"
    debugImplementation "androidx.compose.ui:ui-tooling:$composeVersion"