Android robolectric tests manifest merge issue (android beacon library)

允我心安 提交于 2019-12-12 05:38:50

问题


I have the simple Test Case

@Config(constants = BuildConfig.class)
@RunWith(RobolectricGradleTestRunner.class)
public class BaseTest  {

   @Test
   public void startEverTestSugarAppAsFirst() {
       BeaconManager.setsManifestCheckingDisabled(true);
   }

}

Unfortunately the runner hits manifestmerger issue

java.lang.RuntimeException: org.altbeacon.beacon.BeaconManager$ServiceNotDeclaredException: The BeaconService is not properly declared in AndroidManifest.xml. If using Eclipse, please verify that your project.properties has manifestmerger.enabled=true

at org.robolectric.RobolectricTestRunner$2.evaluate(RobolectricTestRunner.java:256) at org.robolectric.RobolectricTestRunner.runChild(RobolectricTestRunner.java:193) at org.robolectric.RobolectricTestRunner.runChild(RobolectricTestRunner.java:56) at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290) at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71) at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288) at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58) at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268) at org.robolectric.RobolectricTestRunner$1.evaluate(RobolectricTestRunner.java:159) at org.junit.runners.ParentRunner.run(ParentRunner.java:363) at org.junit.runner.JUnitCore.run(JUnitCore.java:137) at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:69) at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:234) at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:74) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:497) at com.intellij.rt.execution.application.AppMain.main(AppMain.java:144) Caused by: org.altbeacon.beacon.BeaconManager$ServiceNotDeclaredException: The BeaconService is not properly declared in AndroidManifest.xml. If using Eclipse, please verify that your project.properties has manifestmerger.enabled=true at org.altbeacon.beacon.BeaconManager.verifyServiceDeclaration(BeaconManager.java:786) at org.altbeacon.beacon.BeaconManager.(BeaconManager.java:252) at org.altbeacon.beacon.BeaconManager.getInstanceForApplication(BeaconManager.java:244) at com.lucyapp.client.Client.onCreate(Client.java:67) at org.robolectric.internal.ParallelUniverse.setUpApplicationState(ParallelUniverse.java:164) at org.robolectric.RobolectricTestRunner.setUpApplicationState(RobolectricTestRunner.java:421) at org.robolectric.RobolectricTestRunner$2.evaluate(RobolectricTestRunner.java:252) ... 18 more

I wonder if there is any simple work around. I've been going through android beacon library test folder and

BeaconManager.setsManifestCheckingDisabled(true);

doesn't help


回答1:


Somehow the BeaconManager is being constructed before the call to BeaconManager.setsManifestCheckingDisabled(true); The trick is to figure out where to put that line so it does get executed first.

Looking at the stack trace, I see that the BeaconManager gets constructed from com.lucyapp.client.Client.onCreate on line 67:

...
org.altbeacon.beacon.BeaconManager.getInstanceForApplication(BeaconManager.java:244) at 
com.lucyapp.client.Client.onCreate(Client.java:67)
...

Knowing that, perhaps you can figure out where you can put the BeaconManager.setsManifestCheckingDisabled(true); line such that it gets called before com.lucyapp.client.Client.onCreate(Client.java:67)



来源:https://stackoverflow.com/questions/37308583/android-robolectric-tests-manifest-merge-issue-android-beacon-library

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!