-
Notifications
You must be signed in to change notification settings - Fork 66
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
AndroidManifest.xml not found when using with Android Gradle plugin 1.1.0 #142
Comments
The plugin does not work with Android Studio due to how studio runs tests. With version 1.0.1 of the plugin, you shouldn't have to use @config, Config.properties or any other configuration to run your tests on the command line. |
@erd Thanks for the clarification! Is there a chance that the plugin will work with Studio 1.2 (which is going to be based on IntelliJ 14) ? |
This plugin works for me with AS when using custom RobolectricTestRunner and provide the missing system properties.
Edit: |
@nenick Thanks, it works this way, just needed so swap build type and build flavor for build variant. Also checked your examples from https://github.com/nenick/AndroidStudioAndRobolectric, very useful. |
@nenick Thanks, I also had to swap the build type and flavor, so my variant ended up looking like this:
|
We have build flavors with different applicationIds (such like "com.example" and "com.example.development"). public class CustomRobolectricTestRunner extends RobolectricTestRunner {
public CustomRoblectricTestRunner(Class<?> testClass) throws InitializationError {
super(testClass);
String buildVariant = (BuildConfig.FLAVOR.isEmpty() ? "" : BuildConfig.FLAVOR + "/") + BuildConfig.BUILD_TYPE;
System.setProperty("android.package", BuildConfig.DEFAULT_APPLICATION_ID);
System.setProperty("android.manifest", "build/intermediates/manifests/full/" + buildVariant + "/AndroidManifest.xml");
System.setProperty("android.resources", "build/intermediates/res/" + buildVariant);
System.setProperty("android.assets", "build/intermediates/assets/" + buildVariant);
}
} build.gradle: def defaultApplicationId = "com.example"
android {
applicationId defaultApplicationId
buildConfigField "String", "DEFAULT_APPLICATION_ID", "\"${defaultApplicationId}\"" // for robolectric
...
} (EDITED: at least with android gradle plugin 1.5.0, |
Above test runner works well on both Android Studio unit test and Gradle test even without robolectric-gradle-plugin. (Also setting |
For me the problem was because my class package (com.my.class.package) was different from my applicationId (com.my.app) I fixed by adding |
I had to add my build variant "app" to the string: "app/build/.... " |
The current correct solution is to use the @RunWith(RobolectricGradleTestRunner.class)
@Config(constants=BuildConfig.class, sdk=21) // robolectric currently only supports up to API 21, sadly
public class CustomTest {
... |
I struggled with this for a while but eventually came up with a
public class RobolectricTestRunnerWithResources extends RobolectricTestRunner {
@Override
protected Config buildGlobalConfig() {
return Config.Builder.defaults()
.setPackageName("co.beeline")
.setManifest("build/intermediates/manifests/full/debug/AndroidManifest.xml")
.setResourceDir("../../../res/merged/debug") // relative to manifest
.setAssetDir("../../../assets/debug") // relative to manifest
.build();
}
public RobolectricTestRunnerWithResources(Class<?> testClass) throws InitializationError {
super(testClass);
}
} |
@chetbox How did you manage to set the manifest correctly? For me it just appends the given string to the default prefix so that the resulting path is
|
This works for us. It might be that a different version of the Android SDK or Robolectric behave differently. |
Hello,
I've been successfully using Robolectric with gradle with Android Gradle plugin 1.0.0 without robolectric plugin. However, after updating to 1.1.0 my tests are unable to find the manifest:
Interesting thing that using both
@Config
andorg.robolectric.Config.properties
seem to be ineffective in solving it.After incorporating your plugin into the project (with 1.1.0 plugin activated) the behavior of my test diverged. In the Android Studio I still get the same errors related to AndroidManifest.xml. When I run tests from console however I get
android.content.res.Resources$NotFoundException
.I have 2 build types and 2 flavors. Tests are located under
src/test
. The manifest is undersrc/main
. I have also tried to add a copy of the manifest just next to my test class, but to no avail.I know that these issues are only partly related to the robolectric plugin itself, but would still appreciate any insights.
The text was updated successfully, but these errors were encountered: