ant2009 ant2009 - 3 years ago 282
Android Question

Robolectric: Resources$NotFoundException: String resource ID with Android Gradle Plugin 3

Android Studio 3.0 Beta2
classpath ''
testCompile 'org.robolectric:robolectric:3.4.2'

Test class that I am using that fails to run:

@Config(constants = BuildConfig.class, sdk = Build.VERSION_CODES.LOLLIPOP)
public class RecipeAdapterTest {
private MainActivity activity;

public void setup() {

activity = Robolectric.setupActivity(MainActivity.class);

/* Also tried this same Error
activity = Robolectric.buildActivity(MainActivity)

public void testActivityShouldNotBeNull() {
assertThat(activity, is(notNullValue()));

This is the stack trace of the error:

android.content.res.Resources$NotFoundException: String resource ID #0x7f0c0020

at android.content.res.Resources.getText(
at android.content.res.Resources.getString(
at android.content.Context.getString(
at org.robolectric.shadows.ShadowActivity.getActivityTitle(
at org.robolectric.shadows.ShadowActivity.callAttach(
at org.robolectric.Robolectric.buildActivity(
at org.robolectric.Robolectric.buildActivity(
at org.robolectric.Robolectric.setupActivity(
at me.androidbox.busbybaking.adapters.RecipeAdapterTest.setup(

In the
Edit Configurations
I have set the
Working Directory

Many thanks for any suggestion.

Answer Source

Add following line into file:


As mentioned by an engineer from Google team (most possibly Xavier Ducrohet), Robolectric has issues with AAPT2:

Robolectric is not compatible with aapt2.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download