Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

View inflation error #106

Closed
arturdryomov opened this issue Oct 31, 2019 · 2 comments
Closed

View inflation error #106

arturdryomov opened this issue Oct 31, 2019 · 2 comments

Comments

@arturdryomov
Copy link

I’m trying to work with the application module and Spek, so this is destined to fail, but anyways. Since #105 blocks me from using the Paparazzi Gradle plugin, I’m doing what the plugin does on my own.

view_basic.xml

<?xml version="1.0" encoding="utf-8"?>
<View
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    />

PaparazziSpec.kt

describe("paparazzi") {

    val paparazzi by memoized { Paparazzi() }

    beforeEachTest {
        val resourcesFile = File("REDACTED_MODULE_PATH/build/intermediates/paparazzi/resources.txt")
        val resources =
                """
                REDACTED_MODULE_PACKAGE_NAME
                REDACTED_MODULE_PATH/build/intermediates/res/merged/debug
                """

        resourcesFile.apply {
            parentFile?.mkdirs()
            createNewFile()
            writeText(resources.trimIndent())
        }

        paparazzi.prepare(Description.createTestDescription(PaparazziSpec::class.java, "paparazzi"))
    }

    it("should work") {
        paparazzi.snapshot(paparazzi.inflate(R.layout.view_basic), "basic")
    }

    afterEachTest {
        paparazzi.close()
    }
}

It actually compiles but fails to proceed.

kotlin.TypeCastException: null cannot be cast to non-null type V
    at app.cash.paparazzi.Paparazzi.inflate(Paparazzi.kt:128)
    at PaparazziSpec$1$1$2.invoke(PaparazziSpec.kt:42)

I’ve explored with a debugger a bit and seems like BridgeInflater#inflate returns null

  • since bridgeContext.getRenderResources().getResolvedResource(layoutInfo) returns null
  • since RenderResources#getResolvedResource returns null
  • since RenderResources#getUnresolvedResource returns null
  • since ResourceResolver#getUnresolvedResource returns null
  • since getResourceValueMap(reference.getNamespace(), reference.getResourceType()) returns empty map
@jrodbx
Copy link
Collaborator

jrodbx commented Oct 31, 2019

That's correct behavior at the moment, unfortunately. This stems from how application modules compile and merge resources vs how library modules does it. Explained here: #105

@jrodbx jrodbx closed this as completed Oct 31, 2019
@jrodbx
Copy link
Collaborator

jrodbx commented Oct 31, 2019

Tracked in #107

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants