Reputation: 51
Robolectric throws errors on every test I start with the logs:
java.lang.RuntimeException: java.lang.RuntimeException: Invalid environment
at org.robolectric.RobolectricTestRunner$2.evaluate(RobolectricTestRunner.java:240)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
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:177)
at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
Caused by: java.lang.RuntimeException: Invalid environment
at com.android.vending.licensing.AESObfuscator.<init>(AESObfuscator.java:68)
at com.myproject.ApplicationClass.onCreate(ApplicationClass.java:65)
at org.robolectric.internal.ParallelUniverse.setUpApplicationState(ParallelUniverse.java:164)
at org.robolectric.RobolectricTestRunner.setUpApplicationState(RobolectricTestRunner.java:430)
at org.robolectric.RobolectricTestRunner$2.evaluate(RobolectricTestRunner.java:236)
... 16 more
Caused by: java.security.NoSuchAlgorithmException: PBEWITHSHAAND256BITAES-CBC-BC SecretKeyFactory not available
at javax.crypto.SecretKeyFactory.<init>(DashoA13*..)
at javax.crypto.SecretKeyFactory.getInstance(DashoA13*..)
at com.android.vending.licensing.AESObfuscator.<init>(AESObfuscator.java:57)
... 20 more
It fails at line:
SecretKeyFactory factory = SecretKeyFactory.getInstance("PBEWITHSHAAND256BITAES-CBC-BC");
I will appreciate any suggestions. The Java SDK is 1.6 (for test an android project). android.jar for the test project is from 18 android version.
Upvotes: 2
Views: 637
Reputation: 5151
The issue is that when you run the test, you don't seem to have an implementation for that algorithm. I'm guessing from your question that this code works ok on the Android device and only fails on tests. If that's the case, it might be that Android includes some implementation, but when you run the Robolectric tests (which run on the JVM, not on the Android device) you don't have one anymore.
Try getting bouncy castle, and make sure to get the correct release for the JDK version you have (which could be different from 6, as Robo tests will happily build and run with newer version of Java as well, even if Android lives in Java 6 times). Add that to your classpath for the robolectric tests only, as there doesn't seem to be any need to distribute it with the app and then try again.
Upvotes: 2