Demonstrates Resources$NotFoundException with robolectric 4.7.3

Related tags

Kotlin SampleApp
Overview

SampleApp

Demonstrates font not found with robolectric 4.7.3 while targetting sdk 31.

While accessing font using ResourcesCompat.getFont(context, R.font.font_name) tests fail with Resources$NotFoundException error.

But if you annotate the test with @Config(sdk = [30]) it passes.

How to run

Clone this project and run ./gradlew :app:testDebugUnitTest --info. Or after cloning, open the project in AndroidStudio and search for MainActivityTest and run it.

StackTrace

Font resource ID #0x7f080000 could not be retrieved.
android.content.res.Resources$NotFoundException: Font resource ID #0x7f080000 could not be retrieved.
	at androidx.core.content.res.ResourcesCompat.loadFont(ResourcesCompat.java:537)
	at androidx.core.content.res.ResourcesCompat.getFont(ResourcesCompat.java:372)
	at com.example.sample_lib.CommonFont.getFont(CommonFont.kt:7)
	at com.example.sampleapp.MainActivity.updateTextView(MainActivity.kt:18)
	at com.example.sampleapp.MainActivity.onCreate(MainActivity.kt:12)
	at android.app.Activity.performCreate(Activity.java:8051)
	at android.app.Activity.performCreate(Activity.java:8031)
	at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1329)
	at org.robolectric.android.internal.RoboMonitoringInstrumentation.callActivityOnCreate(RoboMonitoringInstrumentation.java:284)
	at org.robolectric.android.controller.ActivityController.lambda$create$0(ActivityController.java:113)
	at org.robolectric.shadows.ShadowPausedLooper.runPaused(ShadowPausedLooper.java:203)
	at org.robolectric.android.controller.ActivityController.create(ActivityController.java:113)
	at org.robolectric.android.controller.ActivityController.create(ActivityController.java:118)
	at org.robolectric.android.internal.RoboMonitoringInstrumentation.startActivitySyncInternal(RoboMonitoringInstrumentation.java:103)
	at org.robolectric.android.internal.LocalActivityInvoker.startActivity(LocalActivityInvoker.java:33)
	at org.robolectric.android.internal.LocalActivityInvoker.startActivity(LocalActivityInvoker.java:38)
	at androidx.test.core.app.ActivityScenario.launchInternal(ActivityScenario.java:265)
	at androidx.test.core.app.ActivityScenario.launch(ActivityScenario.java:195)
	at com.example.sampleapp.MainActivityTest.testTextView(MainActivityTest.kt:18)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:59)
	at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
	at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:56)
	at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
	at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306)
	at org.robolectric.RobolectricTestRunner$HelperTestRunner$1.evaluate(RobolectricTestRunner.java:591)
	at org.robolectric.internal.SandboxTestRunner$2.lambda$evaluate$0(SandboxTestRunner.java:274)
	at org.robolectric.internal.bytecode.Sandbox.lambda$runOnMainThread$0(Sandbox.java:88)
	at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
	at java.base/java.lang.Thread.run(Thread.java:834)
	Suppressed: org.robolectric.android.internal.AndroidTestEnvironment$UnExecutedRunnablesException: Main looper has queued unexecuted runnables. This might be the cause of the test failure. You might need a shadowOf(Looper.getMainLooper()).idle() call.

Workaround

Annotate tests with @Config(sdk = [30]) fixes the issue

You might also like...
This is a Android Studio/ IntelliJ IDEA plugin to localize your Android app, translate your string resources automactically.
This is a Android Studio/ IntelliJ IDEA plugin to localize your Android app, translate your string resources automactically.

#Android Localizationer This is a Android Studio/ IntelliJ IDEA plugin to localize your Android app, translate your string resources automactically. T

Tinker is a hot-fix solution library for Android, it supports dex, library and resources update without reinstall apk.
Tinker is a hot-fix solution library for Android, it supports dex, library and resources update without reinstall apk.

Tinker Tinker is a hot-fix solution library for Android, it supports dex, library and resources update without reinstalling apk. Getting started Add t

Android Resource Manager application to manage and analysis your app resources with many features like image resize, Color, Dimens and code Analysis
Android Resource Manager application to manage and analysis your app resources with many features like image resize, Color, Dimens and code Analysis

Android Resource Manager application to manage and analysis your app resources with many features like image resize, Color, Dimens and code Analysis

🪁 Android Resources Wrapper Library
🪁 Android Resources Wrapper Library

Kite Android Resource Wrapper Library. TLDR Fed up with typing ContextCompat, resources and context all over your apps to access your resources? Say n

Jetpack Compose Text composable to show html text from resources
Jetpack Compose Text composable to show html text from resources

HtmlText Current Compose Version: 1.0.3 Compose HtmlText Text composable to show html text from resources Add to your project Add actual HtmlText libr

Allows usage of vCard resources with the Android contacts provider

vcard4android vcard4android is an Android library that brings together VCard and Android. It's a framework for parsing and generating VCard resources

Haven is an app to help people in need find resources.

Haven Haven is an app to help people in need find resources. Haven connects people to resources such as food pantries, homeless shelters, healthcare,

Android binary resources read/write library

Android binary resources read/write library

A command line tool that helps bulk manage resources in an Android project

Resource Mover ResourceMover is a command line tool that helps bulk manage resources in an Android project. Installation Clone project Build CLI jar u

Kotlin Multiplatform (KMP) library for reading resources in tests

kotlinx-resources Kotlin Multiplatform (KMP) plugin and library that add support for reading resources in tests. The plugin and a library work in tand

Brazilian Holidays: a Kotlin/Java library that provides resources to consult Brazilian holidays and business days

Leia esta documentação em Português. Brazilian Holidays Brazilian Holidays is a

Add IndustrialTNT like from old IC2 mod which keeps items after explosion and helps to mine resources
Add IndustrialTNT like from old IC2 mod which keeps items after explosion and helps to mine resources

IndustrialTNT Add IndustrialTNT like from old IC2 mod which keeps items after ex

An app for developers which contains more than 2.4k+ resources , with 1.2k+ free public API documentation
An app for developers which contains more than 2.4k+ resources , with 1.2k+ free public API documentation

ResourceUp We often spend a lot of time finding good resources to get started with our project right? ResourceUp aims to provide all useful resources

Loco-strings-sync - A custom Gradle Plugin useful to sync loco string resources to local projects

loco-strings-sync A custom Gradle Plugin useful to sync loco string resources to

A curated list of great Android lint custom rules and resources

Awesome Android Lint A curated list of great Android lint custom rules and resources Contents Rules Articles Other Contribute Rules Google Sample Cust

This repository demonstrates handling unauthorized tokens.

Android - sample handling unauthorized tokens This repository demonstrates handling unauthorized tokens. Refresh the access token using the refresh to

A simple app demonstrates using Jetpack compose with other Jetpack libraries.
A simple app demonstrates using Jetpack compose with other Jetpack libraries.

Android Pokemon Compose This repository is a simple app that make request to https://pokeapi.co and display them in the paginated lists. It demonstrat

YASNAC (short for Yet Another SafetyNet Attestation Checker) is an Android app that demonstrates SafetyNet Attestation API.

YASNAC YASNAC (short for Yet Another SafetyNet Attestation Checker) is an Android app that demonstrates SafetyNet Attestation API. YASNAC is written w

This repository demonstrates how Kotlin can simplify Spring Boot configuration properties file mapping

Kotlin spring-boot nested config props This repository demonstrates how Kotlin can simplify Spring Boot configuration properties file mapping @Constru

Owner
Shivam Pokhriyal
Mobile Application Developer. Currently @Walmart. Email: [email protected]
Shivam Pokhriyal
Kotlin Multiplatform (KMP) library for reading resources in tests

kotlinx-resources Kotlin Multiplatform (KMP) plugin and library that add support for reading resources in tests. The plugin and a library work in tand

Gonçalo Silva 29 Dec 27, 2022
[Deprecated] Android Studio IDE support for Android gradle unit tests. Prepared for Robolectric.

#[Deprecated] Google has finally released a proper solution for unit testing. Therefore this plugin will no longer be activlty maintained. android-stu

Evan Tatarka 236 Dec 30, 2022
A list of most useful resources for designing android apps such as all material colors and dimens, 180 Gradient background + html, social, flat, fluent, metro colors.

Timer UI Login UI Fitness UI Material-Resources-Library A list of most useful resources for designing android apps such as all material colors and dim

Next 37 Jul 24, 2022
An app that is a one-stop destination for all the CS enthusiasts, providing resources like Information scrapping techniques, best YT channels, courses available free-of-cost, etc. & knowledge about every domain and field that exists on the Internet related to Computer Science along with News, Jobs, and Internships opportunities in these domains along with valuable tips and hacks from mentors for a particular domain.

An app that is a one-stop destination for all the CS enthusiasts, providing resources like Information scrapping techniques, best YT channels, courses available free-of-cost, etc. & knowledge about every domain and field that exists on the Internet related to Computer Science along with News, Jobs, and Internships opportunities in these domains along with valuable tips and hacks from mentors for a particular domain.

CSwala 48 Nov 26, 2022
A collaborative list of awesome jetpack compose resources.

Awesome Jetpack compose A collaborative list of awesome jetpack compose resources. Featured in Content Official Documentation Conference talks Article

Naveen T P 289 Nov 15, 2022
Android Studio plugin which automatically generates drawable selectors from appropriately named resources.

SelectorChapek for Android This Android Studio plugin automatically generates drawable selectors from appropriately named Android resources. How to in

Inmite s.r.o. 1.6k Dec 29, 2022
A Gradle Plugin that removes unused resources in Android projects.

#Lint Cleaner Plugin Removes unused resources reported by Android lint including strings, colors and dimensions. Depracated As of Android Studio 2.0+

Marco RS 705 Nov 25, 2022
A collection of android security related resources

android-security-awesome A collection of android security related resources. Tools Academic/Research/Publications/Books Exploits/Vulnerabilities/Bugs

Ashish Bhatia 6.6k Jan 5, 2023
CLI tool for decompiling Android apps to Java. It does resources! It does Java! Its real easy!

Easy-as-pie Android Decompiler Why One stop shop I got pretty tired of decompiling Android apps with a bunch of steps that I had to remember all the t

Alex Davis 619 Dec 27, 2022
A simple utility to remove unused resources in your Android app to lower the size of the APK. It's based on the Android lint tool output.

android-resource-remover android-resource-remover is utility that removes unused resources reported by Android Lint from your project. The goal is to

Keepsafe 1.3k Dec 16, 2022