Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android JUnit don't compile if objects are parcelable

Tags:

I have a very simple class, and I have writen a very simple Junit test which is successfull.

Now I add implements Parcelable to my class. My code compliles well and the app works well, but my Junit test don't compile anymore, because of NoClassDefFoundError: android/os/Parcelable

I am not trying to test the parcelable properties, I just need my test to compile.

I guess there is a configuration problem but I can't find what to change to fix this.

I work on Android Studio 2.3. I have already tried to restart android studio / rebuild / clean...

Help would be apreciated.

java.lang.NoClassDefFoundError: android/os/Parcelable      at java.lang.ClassLoader.defineClass1(Native Method)     at java.lang.ClassLoader.defineClass(ClassLoader.java:763)     at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)     at java.net.URLClassLoader.defineClass(URLClassLoader.java:467)     at java.net.URLClassLoader.access$100(URLClassLoader.java:73)     at java.net.URLClassLoader$1.run(URLClassLoader.java:368)     at java.net.URLClassLoader$1.run(URLClassLoader.java:362)     at java.security.AccessController.doPrivileged(Native Method)     at java.net.URLClassLoader.findClass(URLClassLoader.java:361)     at java.lang.ClassLoader.loadClass(ClassLoader.java:424)     at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)     at java.lang.ClassLoader.loadClass(ClassLoader.java:357)     at com.example.me.myapp.PropositionUnitTest.isDeltaCPositiveOrNullIsCorrect1(PropositionUnitTest.java:53)     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:498)     at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)     at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)     at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)     at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)     at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)     at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)     at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)     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.junit.runners.ParentRunner.run(ParentRunner.java:363)     at org.mockito.internal.runners.JUnit45AndHigherRunnerImpl.run(JUnit45AndHigherRunnerImpl.java:37)     at org.mockito.runners.MockitoJUnitRunner.run(MockitoJUnitRunner.java:62)     at org.junit.runner.JUnitCore.run(JUnitCore.java:137)     at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:117)     at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:42)     at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:262)     at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:84)     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:498)     at com.intellij.rt.execution.application.AppMain.main(AppMain.java:147) Caused by: java.lang.ClassNotFoundException: android.os.Parcelable     at java.net.URLClassLoader.findClass(URLClassLoader.java:381)     at java.lang.ClassLoader.loadClass(ClassLoader.java:424)     at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)     at java.lang.ClassLoader.loadClass(ClassLoader.java:357)     ... 42 more 
like image 932
Nathalie Avatar asked Mar 15 '17 09:03

Nathalie


1 Answers

All of sudden, I started facing the same problem and unlike other's I don't have the option of copy n paste the test files into new project. What i did is just delete the .gradle and .idea folder from the root directory and build the project. It works for me.

like image 61
Arpit Avatar answered Oct 11 '22 08:10

Arpit