Skip to content
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

Cannot run tests with sdk < 21 anymore #2562

Closed
WonderCsabo opened this issue Jul 17, 2016 · 9 comments
Closed

Cannot run tests with sdk < 21 anymore #2562

WonderCsabo opened this issue Jul 17, 2016 · 9 comments
Assignees

Comments

@WonderCsabo
Copy link
Contributor

WonderCsabo commented Jul 17, 2016

If you have tests with @Config(sdk = 16) for example, you will get failures like this:

java.lang.NoClassDefFoundError: android/content/pm/PackageInstaller
        at org.robolectric.internal.ParallelUniverse.setUpApplicationState(ParallelUniverse.java:81)
        at org.robolectric.RobolectricTestRunner$2.evaluate(RobolectricTestRunner.java:237)
        at org.robolectric.RobolectricTestRunner.runChild(RobolectricTestRunner.java:174)
        at org.robolectric.RobolectricTestRunner.runChild(RobolectricTestRunner.java:63)
        at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
        at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
        at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
        at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
        at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
        at org.robolectric.RobolectricTestRunner$1.evaluate(RobolectricTestRunner.java:140)
        at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
        at org.apache.maven.surefire.junit4.JUnit4Provider.execute(JUnit4Provider.java:367)
        at org.apache.maven.surefire.junit4.JUnit4Provider.executeWithRerun(JUnit4Provider.java:274)
        at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:238)
        at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:161)
        at org.apache.maven.surefire.booter.ForkedBooter.invokeProviderInSameClassLoader(ForkedBooter.java:290)
        at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:242)
        at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:121)
Caused by: java.lang.ClassNotFoundException: android.content.pm.PackageInstaller
        at org.robolectric.internal.bytecode.InstrumentingClassLoader.getByteCode(InstrumentingClassLoader.java:192)
        at org.robolectric.internal.bytecode.InstrumentingClassLoader.findClass(InstrumentingClassLoader.java:147)
        at org.robolectric.internal.bytecode.InstrumentingClassLoader.loadClass(InstrumentingClassLoader.java:122)
        ... 18 more

This is because the new DefaultPackageManager class directly references android.content.pm.PackageInstaller, but that is only available from API 21.

Workaround for this is using SDK >= 21. But i guess Robolectric clearly supports lower SDKs.

@jongerrish
Copy link
Contributor

Hmmm, doesn't this fail for Robolectric's own unit tests that use MultiApiTestRobolectricRunner?

Is there any more stack trace?

@WonderCsabo
Copy link
Contributor Author

@jongerrish here is a project which reproduces the issue. I guess the problem is that we are compiling against API 16 which does not have the referenced android.content.pm.PackageInstaller class.

@martyglaubitz
Copy link

Are there any workarounds for this?

@jongerrish
Copy link
Contributor

jongerrish commented Nov 24, 2016 via email

@martyglaubitz
Copy link

@jongerrish of course API Level 16 - 18 (Jelly Bean) coveres still 12% of all devices

@jongerrish
Copy link
Contributor

jongerrish commented Nov 24, 2016 via email

@xian xian self-assigned this Nov 26, 2016
@xian
Copy link
Member

xian commented Nov 26, 2016

#2729 is a start at addressing this. As a temporary workaround, could you try adding a test dependency on 'org.robolectric:android-all:6.0.0_r1-robolectric-0'?

WonderCsabo added a commit to WonderCsabo/androidannotations that referenced this issue Nov 29, 2016
Add a workaround until Robolectlectric is not fixed.
robolectric/robolectric#2562 (comment)
WonderCsabo added a commit to WonderCsabo/androidannotations that referenced this issue Dec 10, 2016
Add a workaround until Robolectlectric is not fixed.
robolectric/robolectric#2562 (comment)
WonderCsabo added a commit to WonderCsabo/androidannotations that referenced this issue Dec 10, 2016
Add a workaround until Robolectlectric is not fixed.
robolectric/robolectric#2562 (comment)
WonderCsabo added a commit to WonderCsabo/androidannotations that referenced this issue Dec 10, 2016
Add a workaround until Robolectlectric is not fixed.
robolectric/robolectric#2562 (comment)
WonderCsabo added a commit to WonderCsabo/androidannotations that referenced this issue Dec 10, 2016
Add a workaround until Robolectlectric is not fixed.
robolectric/robolectric#2562 (comment)
@xian xian added this to the 3.3 milestone Jan 26, 2017
@xian xian modified the milestones: 3.3.1, 3.3 Feb 23, 2017
@xian xian modified the milestones: 3.3.1, 3.3.2 Mar 9, 2017
@jongerrish jongerrish modified the milestones: 3.3.2, to prioritize Mar 14, 2017
@ngarelimdex
Copy link

I'm using 3.3.2 and still the same problem:

java.lang.NoClassDefFoundError: android/content/pm/PackageInstaller

at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Class.java:2701)
at java.lang.Class.privateGetMethodRecursive(Class.java:3048)
at java.lang.Class.getMethod0(Class.java:3018)
at java.lang.Class.getMethod(Class.java:1784)
at org.robolectric.internal.bytecode.ShadowWrangler.classInitializing(ShadowWrangler.java:104)
at org.robolectric.internal.bytecode.RobolectricInternals.classInitializing(RobolectricInternals.java:20)
at android.app.ApplicationPackageManager.<clinit>(ApplicationPackageManager.java)
at android.app.ContextImpl.getPackageManager(ContextImpl.java:625)
at android.content.ContextWrapper.getPackageManager(ContextWrapper.java:94)
at org.acra.util.PackageManagerWrapper.hasPermission(PackageManagerWrapper.java:40)
at org.acra.ErrorReporter.setDefaultReportSenders(ErrorReporter.java:1014)
at org.acra.ACRA.init(ACRA.java:181)
at org.acra.ACRA.init(ACRA.java:136)
at org.acra.ACRA.init(ACRA.java:121)
at com.reflex.libs.common.BaseApplication.onCreate(BaseApplication.java:82)

....

Has it been pushed?

@jongerrish
Copy link
Contributor

Robolectric 4.0 is out now, please give that a try and feel free to reopen if its still an issue and we can take a look.

@xian xian removed this from the to prioritize milestone Nov 10, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants