Skip to content

R8 build failure with StreamPreviewDataUtils classes referenced from ComposableSingletons #1448

@matteinn

Description

@matteinn

Describe the bug
When building with R8 enabled, I encounter build failures due to missing preview data utilities. The library includes stream-video-android-previewdata as compileOnly, but Compose generates ComposableSingletons classes that reference these preview utilities in production code.

ERROR: R8: Missing class io.getstream.video.android.mock.StreamPreviewDataUtils (referenced from: void io.getstream.video.android.compose.ui.components.call.renderer.internal.ComposableSingletons$ScreenShareVideoRendererKt$lambda-2$1.invoke(androidx.compose.runtime.Composer, int))

Missing class io.getstream.video.android.mock.StreamPreviewDataUtilsKt (referenced from: void io.getstream.video.android.compose.ui.components.call.ComposableSingletons$CallAppBarKt$lambda-7$1.invoke(androidx.compose.runtime.Composer, int) and 35 other contexts)

The automatically generated missing_rules.txt file doesn't work:

# Please add these rules to your existing keep rules in order to suppress warnings.
# This is generated automatically by the Android Gradle plugin.
-dontwarn io.getstream.video.android.mock.StreamPreviewDataUtils
-dontwarn io.getstream.video.android.mock.StreamPreviewDataUtilsKt

The only workaround I've found so far is including the preview module in runtime dependencies of the consumer app, even though it adds unnecessary code:

implementation("io.getstream:stream-video-android-previewdata:same-version")

Kotlin generates ComposableSingletons classes that contain lambda references to all Composable functions in a file, including those marked with @Preview. Even though preview functions like ScreenShareVideoRendererPreview() are marked private, the compiler still generates references to them that are accessible from production code.

Suggested Solutions

  1. Move all preview-specific code to dedicated files in a preview source set that can be excluded from release builds
  2. Change compileOnly dependency on stream-video-android-previewdata to api to ensure it's available in production
  3. Modify the library to avoid using Preview Data Utils directly in Compose Previews, or provide comprehensive ProGuard rules

👉 The first approach is recommended to avoid shipping unnecessary code in production apps.

SDK version

  • 1.6.3

To Reproduce
Steps to reproduce the behavior:

  1. Include the Stream Video Compose UI library in an Android app
  2. Enable R8
  3. Try to build the app

Expected behavior
App builds fine.

Device:
Any

Screenshots
None

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions