Search code examples
androidtestinggradleandroid-jetpack-composeandroid-testing

Resources$NotFoundException with multi-module Compose tests


I have a multi-module Android project which includes a core-ui module with my Compose themes, reusable composables, and resources (fonts, drawables, etc). I have another module called search that includes the core-ui module as a dependency.

When I run my Compose tests in my androidTest folder, I get android.content.res.Resources$NotFoundException on several fonts. These fonts are located in core-ui and are used by search. When I run the actual app, however, the fonts are loaded without any issue.

How can I configure my androidTest tests to have access to these font resources from a different module?


Solution

  • I just ran across this issue again and found the solution. Oddly enough the issue was caused from using the wrong resource in my Font definitions. I'm actually not sure why it worked when I was running the app rather than a UI test.

    My tests were failing with this

    val gotham = FontFamily(
        Font(R.font.gotham_300, Thin),
        ...
    )
    

    where R.font.gotham_300 is a file gotham_300.xml that defines the font-family.

    I changed it to point to gotham_light.otf instead, and it resolved the issue.

    val gotham = FontFamily(
        Font(R.font.gotham_light, Thin),
        ...
    )