Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Robolectric says "AndroidManifest.xml not found"

While trying to get Robolectric RC3 to work in Android Studio, I get

Caused by: java.lang.RuntimeException: build/intermediates/bundles/debug/AndroidManifest.xml not found or not a file; it should point to your project's AndroidManifest.xml at org.robolectric.manifest.AndroidManifest.validate(AndroidManifest.java:120) at org.robolectric.manifest.AndroidManifest.getResourcePath(AndroidManifest.java:469) at org.robolectric.manifest.AndroidManifest.getIncludedResourcePaths(AndroidManifest.java:475) at org.robolectric.RobolectricTestRunner.createAppResourceLoader(RobolectricTestRunner.java:479) at org.robolectric.RobolectricTestRunner.getAppResourceLoader(RobolectricTestRunner.java:471) at org.robolectric.internal.ParallelUniverse.setUpApplicationState(ParallelUniverse.java:73) at org.robolectric.RobolectricTestRunner.setUpApplicationState(RobolectricTestRunner.java:421) at org.robolectric.RobolectricTestRunner$2.evaluate(RobolectricTestRunner.java:234) 

I tried

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

and I tried setting the manifest location in my TestRunner, nothing worked. In the file system I see that the manifest is in

./app/build/intermediates/manifests/full/debug/AndroidManifest.xml 

not in the location Robolectric is looking for it. At one point the manifest just got ignored, then a similar issue occurred for resources, the app or Robolectric couldn't find a raw resource my app uses. This is in my build file:

   sourceSets {     main {         java.srcDirs = ['src/main/java']         resources.srcDirs = ['src/main/res']     }     test {         java.srcDirs = ['src/test/java', 'src/main/java']         resources.srcDirs = ['src/test/res', 'src/main/res']     } } 

How do I tell Robolectric where to look for a manifest, and more importantly, where to look for resources?

Edit: I have checked out Robolectric from github, I've built it, installed it in my local .m2 repo, the gradle file now refers to the local SNAPSHOT build, and I made sure Gradle doesn't get a new version from a remote repo. Then I copied the RobolectricGradleTestRunner to my project, I have changed the lines where the file locations are defined: it didn't contain the module name. Now it works.

like image 727
Christine Avatar asked Jun 18 '15 10:06

Christine


People also ask

Where can I find AndroidManifest XML file?

When you build an Android app by using Quantum Visualizer, an AndroidManifest. xml file is created in the app's corresponding dist folder. The file is located at WorkspaceName>/temp/<AppName>/build/luaandroid/dist.

What is an AndroidManifest XML file?

Every app project must have an AndroidManifest. xml file (with precisely that name) at the root of the project source set. The manifest file describes essential information about your app to the Android build tools, the Android operating system, and Google Play.

Where is the AndroidManifest XML file flutter?

Android app manifest file, AndroidManifest. xml is located in <app dir>/android/app/src/main. It contains entire details about an android application.

How do I open AndroidManifest xml on Android?

Procedure. Open your Android project and go to <AppProjectFolder>/app/src/main/. Open the app manifest file AndroidManifest. xml and add the following lines to the file as child elements of the <manifest> element.


1 Answers

I'm assuming you're trying to run the tests with JUnit. You can try two different things:

  1. Create a Custom TestRunner class, as shown here. Check the CustomTestRunner section, where you basically create a TestRunner that actually knows the right manifest to use. Specify your tests for them to run with your test runner, with the @Config annotation.
  2. (My preferred choice) Go the your JUnit configuration, Run > Edit Configurations. Notice the 'Working Directory' textbox. Append /app (for OSX and Linux) or \app (Windows), to the path written in the textbox. Try running again and it should work.
like image 108
J.C. Chaparro Avatar answered Sep 17 '22 17:09

J.C. Chaparro