It took me couple of days for now but still couldn't find a solution. I got error when running robolectric tests that says font files cannot be found. The followings are the whole stack trace
android.view.InflateException: XML file build/intermediates/res/merged/debug/layout/fragment_users_list.xml line #-1 (sorry, not yet implemented): Error inflating class com. mycustom.common.views.RobotoTextView
// real issue here
Caused by: java.lang.RuntimeException: Font not found at [build/intermediates/bundles/debug/assets/Roboto-Light.ttf]
at org.robolectric.shadows.ShadowTypeface.createFromAsset(ShadowTypeface.java:73)
at android.graphics.Typeface.createFromAsset(Typeface.java)
at com.mycustom.utils.font.RobotoUtil.getRobotoTypeface(RobotoUtil.java:45)
at com.mycustom.common.views.RobotoTextView.setFontType(RobotoTextView.java:46)
at com.mycustom.common.views.RobotoTextView.<init>(RobotoTextView.java:33)
... 89 more
Basically I have xml files that use custom font file, the font file is saved in res folder, when I step up activity instance in Robolectric tests, and the activity is initialized, it will look for the font file in /build/intermediates/res/merged folder , but somehow the robolectric cannot find that font file.
Not sure why that happened. Any advice will be much appreciated!
That is known bug with the upgrade of the Android Gradle plugin to v2.2.0.
As workaround add this to your build.gradle
:
applicationVariants.all { variant ->
def productFlavor = variant.productFlavors[0] != null ? "${variant.productFlavors[0].name.capitalize()}" : ""
def buildType = "${variant.buildType.name.capitalize()}"
tasks["compile${productFlavor}${buildType}UnitTestSources"].dependsOn(tasks["merge${productFlavor}${buildType}Assets"])
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With