java.lang.NoClassDefFoundError: ...InstrumentingClassLoader

317 views
Skip to first unread message

Christine

unread,
Jun 16, 2015, 9:39:47 AM6/16/15
to robol...@googlegroups.com
I recently switched from Eclipse to Android Studio, I have trouble getting robolectric to work in AS. I checked out Robolectric-3.0-SNAPSHOT, put the jars on my classpath, added a few dependencies that robolectric seems to need, now I get this error in all my tests. I use gradle 2.4. 




java.lang.NoClassDefFoundError: Could not initialize class org.robolectric.internal.bytecode.InstrumentingClassLoader
	at org.robolectric.internal.InstrumentingClassLoaderFactory.getSdkEnvironment(InstrumentingClassLoaderFactory.java:40)
	at org.robolectric.RobolectricTestRunner.runChild(RobolectricTestRunner.java:187)
	at org.robolectric.RobolectricTestRunner.runChild(RobolectricTestRunner.java:54)
	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:152)
	at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
	at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassExecuter.runTestClass(JUnitTestClassExecuter.java:86)
	at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassExecuter.execute(JUnitTestClassExecuter.java:49)
	at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassProcessor.processTestClass(JUnitTestClassProcessor.java:64)
	at org.gradle.api.internal.tasks.testing.SuiteTestClassProcessor.processTestClass(SuiteTestClassProcessor.java:50)
	at sun.reflect.GeneratedMethodAccessor11.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:483)
	at org.gradle.messaging.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:35)
	at org.gradle.messaging.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24)
	at org.gradle.messaging.dispatch.ContextClassLoaderDispatch.dispatch(ContextClassLoaderDispatch.java:32)
	at org.gradle.messaging.dispatch.ProxyDispatchAdapter$DispatchingInvocationHandler.invoke(ProxyDispatchAdapter.java:93)
	at com.sun.proxy.$Proxy2.processTestClass(Unknown Source)
	at org.gradle.api.internal.tasks.testing.worker.TestWorker.processTestClass(TestWorker.java:106)
	at sun.reflect.GeneratedMethodAccessor10.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:483)
	at org.gradle.messaging.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:35)
	at org.gradle.messaging.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24)
	at org.gradle.messaging.remote.internal.hub.MessageHub$Handler.run(MessageHub.java:360)
	at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:54)
	at org.gradle.internal.concurrent.StoppableExecutorImpl$1.run(StoppableExecutorImpl.java:40)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
	at java.lang.Thread.run(Thread.java:745)

Csaba Kozák

unread,
Jun 16, 2015, 11:04:59 AM6/16/15
to robol...@googlegroups.com
I am afraid you put the wrong jars. Actually you should not add any jars, just declare the org.robolectric:robolectric:3.0-rc3 dependency and you are good to go.

Michael Grafton

unread,
Jun 16, 2015, 11:09:09 AM6/16/15
to robol...@googlegroups.com
Yes, what Csaba said.  Gradle should resolve any dependencies; you shouldn't have to managed the classpath by hand (in fact I didn't think Android Studio even allowed that ;)

If you get stuck again, consider cloning deckard-gradle and see if you can import that into AS.  It's a bare-minimum project and a good place to start (and see if your environment is working).

Mike

On Tue, Jun 16, 2015 at 8:04 AM, Csaba Kozák <kozak...@gmail.com> wrote:
I am afraid you put the wrong jars. Actually you should not add any jars, just declare the org.robolectric:robolectric:3.0-rc3 dependency and you are good to go.

--
You received this message because you are subscribed to the Google Groups "Robolectric" group.
To unsubscribe from this group and stop receiving emails from it, send an email to robolectric...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Christine

unread,
Jun 17, 2015, 2:49:31 PM6/17/15
to robol...@googlegroups.com
I checked out robolectric from github and built the jars. If RC3 works, why wouldn't the jar I built work? Last week I got an error with RC3, I found a post that recommended I use RC2. 

My problem is that everything worked fine for years in Eclipse, but now Google made me switch to Android Studio, and I haven't gotten robolectric to work since. 

Christine

unread,
Jun 17, 2015, 2:54:44 PM6/17/15
to robol...@googlegroups.com
using RC3 gives me different errors, so I suppose "it worked". Which makes me wonder, how can I use the version of Robolectric that I built from source?

Csaba Kozák

unread,
Jun 17, 2015, 2:55:50 PM6/17/15
to robol...@googlegroups.com
Actually the "jar" thing is not strithly related to Robolectric.

Proper dependency managament is lots of advantages over providing the jars yourself.

You do not have to build the jars.
You do not have to store the jars in VCS.
You can easily check for updates.
There is a central repository where you can search for any artifact.
You do not have to bother with transitive dependencies, build tool will pick them up.
Etc.

Csaba Kozák

unread,
Jun 17, 2015, 2:56:53 PM6/17/15
to robol...@googlegroups.com
You can build Robolectric with mvn install. Add mavenLocal() repository to your buildscript, and depend on the RC3 you just built.
Message has been deleted

Christine

unread,
Jun 25, 2015, 5:33:37 AM6/25/15
to robol...@googlegroups.com
I tweaked the gradle build file but I don't know which tweak made the thing work. I built my own copy of robolectric, installed it in my local repository. I copied the source of RobolectricGradleTestRunner into my own project so I can easily change the strings for access to resources, manifest, etc. In these, the build variant was missing. I made changes required for robolectric 3.0, like replacing Robolectric.application with RuntimeEnvironment.application and Robolectric.runUiThreadTasksIncludingDelayedTasks() with ShadowLooper.runUiThreadTasksIncludingDelayedTasks(). Now it works. 

The primary reason I use Robolectric is that it gives me a proper Android context in tests that don't involve an Activity. The context is needed for Roboguice to work. 


On Tuesday, June 16, 2015 at 3:39:47 PM UTC+2, Christine wrote:
Reply all
Reply to author
Forward
0 new messages