Skip to content

Compose Preview Screenshot Testing Library does not work with Anvil enabled #1132

Open
@sromanuk

Description

@sromanuk

DESCRIBE THE ISSUE IN DETAIL:

Our project uses Anvil as a wrapper around Dagger for dependency injection. Currently we are stuck with version 2.5.0-beta11, although the issue reproduces on 2.5.0 as well.

When Compose Preview Screenshot Testing library/Gradle plugin is added to the module alongside with Anvil, the latter fails the build because of platform type being different with no way to recover from it.

When screenshot testing is enabled in a module without Anvil, the problem does not occur.

STEPS TO REPRODUCE:

  1. Create a new module
  2. Enable Anvil in it
  3. Add Preview Screenshot Testing version 0.0.1-alpha09 (or any of the previous versions) to the module as described in the official documentation
  4. Sync Gradle files in Android Studio

ATTACH LOG FILES

As a result of the previously described steps, Gradle Sync fails with the following message:

Caused by: java.lang.IllegalArgumentException: The KotlinCompilation is KotlinJvmAndroidCompilation, but the platform type is different.
	at com.squareup.anvil.plugin.Variant$Companion.invoke(AnvilPlugin.kt:486)
	at com.squareup.anvil.plugin.AnvilPlugin$getVariant$1.invoke(AnvilPlugin.kt:362)
	at com.squareup.anvil.plugin.AnvilPlugin$getVariant$1.invoke(AnvilPlugin.kt:361)
	at com.squareup.anvil.plugin.AnvilPlugin.getVariant$lambda$16(AnvilPlugin.kt:361)
	at com.squareup.anvil.plugin.AnvilPlugin.getVariant(AnvilPlugin.kt:361)
	at com.squareup.anvil.plugin.AnvilPlugin.isApplicable(AnvilPlugin.kt:108)
	at com.android.build.gradle.internal.TaskManager.addSubpluginOptionsForBuiltInKotlin(TaskManager.kt:1065)
	at com.android.build.gradle.internal.TaskManager.maybeCreateKotlinTasks(TaskManager.kt:1014)
	at com.android.build.gradle.internal.TaskManager.createJavacTask(TaskManager.kt:939)
	at com.android.build.gradle.internal.HostTestTaskManager.setupJavaCompilationTasks(HostTestTaskManager.kt:243)
	at com.android.build.gradle.internal.ScreenshotTestTaskManager.createTasks(ScreenshotTestTaskManager.kt:56)
	at com.android.build.gradle.internal.VariantTaskManager.createTasksForTest(VariantTaskManager.kt:333)
	at com.android.build.gradle.internal.VariantTaskManager.createTasks(VariantTaskManager.kt:139)
	at com.android.build.gradle.internal.plugins.BasePlugin.createAndroidTasks(BasePlugin.kt:750)
	at com.android.build.gradle.internal.plugins.BasePlugin$createTasks$2$1.call(BasePlugin.kt:594)
	at com.android.builder.profile.ThreadRecorder.record(ThreadRecorder.java:69)
	... 208 more

The check, referenced in the stack trace, is this one:

require(
  kotlinCompilation.platformType != androidJvm ||
    kotlinCompilation is KotlinJvmAndroidCompilation,
) {
  "The KotlinCompilation is KotlinJvmAndroidCompilation, but the platform type " +
    "is different."
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions