Robolectric: Couldn't find Manifest file when includeAndroidResources is true

Created on 27 Sep 2018  路  3Comments  路  Source: robolectric/robolectric

Description

Whenever I enable includeAndroidResource in my build.gradle file, manifest files can't be found on release or any non-debug buildtypes(It's ok with debug build).

Steps to Reproduce

Add includeAndroidResources to the app module:
```
android {
...
testOptions {
unitTests {
includeAndroidResources = true
}
}
...

Create a new test class and add a custom manfiest with `@Config` annotation

@RunWith(RobolectricTestRunner::class)
@Config(manifest = "src/main/AndroidManifest.xml")
class MyTest {
}

Run `test[Buildtype]UnitTest` gradle task(e.g. `testBetaUnitTest` or `testReleaseUnitTest`).

The below exception will be thrown:

Caused by:
java.lang.IllegalArgumentException: couldn't find 'src/main/AndroidManifest.xml'

```

Robolectric & Android Version

  • Android studio 3.2 with API 28
  • Robolectric 4.0-alpha-3

Most helpful comment

If I want some other manifest for test ?

All 3 comments

It can be solved by changing src/main/AndroidManifest.xml to AndroidManifest.xml, but I don't know why src/main/AndroidManifest.xml works in debug mode.

You shouldn't need to specify a manifest in your @Config() anymore. Gradle passes the location of the merged manifest.

Also, try adding

android {
  enableUnitTestBinaryResources=true
}

which should switch you over to binary resource mode, test startup time should be a lot faster and resource handling is a lot more faithful to real Android.

If I want some other manifest for test ?

Was this page helpful?
0 / 5 - 0 ratings