Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Robolectric: “AndroidManifest.xml not found” and "Unable to find resource ID #0x7f09001b"

I'm running some tests with Roboletric, but I came across a issue that I can't solve. When I run the test, the following error appears with the "AndroidManifest":

WARNING: No manifest file found at .\AndroidManifest.xml.

Falling back to the Android OS resources only. To remove this warning, annotate your test class with @Config(manifest=Config.NONE).

No such manifest file: .\AndroidManifest.xml

I've tried these solutions that failed:

@Config (manifest = Config.DEFAULT_MANIFEST_NAME)

@Config(manifest = Config.NONE, constants = BuildConfig.class, sdk = 26)

@Config( constants = BuildConfig.class, manifest="src/main/AndroidManifest.xml", sdk = 26 )

And the other error during execution is:

android.content.res.Resources$NotFoundException: Unable to find resource ID #0x7f09001b in packages [android, org.robolectric.default]

...

at

com.example.robertoassad.alltestsmerge.MainActivity.onCreate(MainActivity.java:52)

This line that have the error is the following code:

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

Specifically in: setContentView(R.layout.activity_main);

For me I didn't see sense in this issue ...

DETAILS:

  • The test class is on the folder: app\src\test\java\com\example\robertoassad

  • The test is: @RunWith( RobolectricTestRunner.class) public class Roboletric { @Test public void clickingLogin_shouldStartLoginActivity() { MainActivity activity = Robolectric.setupActivity(MainActivity.class); activity.findViewById(R.id.button2).performClick();

            Intent expectedIntent = new Intent(activity, SecondActivity.class);
            Intent actual = ShadowApplication.getInstance().getNextStartedActivity();
            assertEquals(expectedIntent.getComponent(), actual.getComponent());
         }
    

    }

like image 890
Roberto Pinheiro Avatar asked Oct 23 '25 20:10

Roberto Pinheiro


1 Answers

I had a similar problem to the one you face. The post by jongerrish on the Robolectric GitHub Issue about this resolved the problem for me.

The aspect of the answer that worked for me was to add a testOptions block in my module's build.gradle file:

testOptions {
    unitTests {
        includeAndroidResources = true
    }
}

After adding this block my tests were able to run and access String resources.

like image 180
Jaween Avatar answered Oct 25 '25 09:10

Jaween



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!