title: Robolectric 3 NoClassDefFoundError on Context
body: <p>I'm running <strong>Robolectric 3 rc3</strong> and I'm <strong>unable</strong> to run the <strong>Robolectric</strong> test due to this a <code>NoClassDefFoundError</code> on <code>Context</code>.</p>
  <p>It was working well a week ago. I've found the issue listed <a href="https://code.google.com/p/android/issues/detail?id=160024" rel="nofollow noreferrer">here</a> which is posibly related but I don't want to downgrade AS.</p>
  <p>Here is my config :</p>
  <p>Module gradle :</p>
  <pre><code>// Testing dependencies
  testCompile 'org.apache.maven:maven-ant-tasks:2.1.3'
  testCompile (&quot;org.robolectric:robolectric:3.0-rc3&quot;){
      exclude module: 'commons-logging'
      exclude module: 'httpclient'
  }
  testCompile 'com.google.android.gms:play-services:7.0.0'
  testCompile (&quot;org.robolectric:shadows-play-services:3.0-rc3&quot;){
      exclude module: 'commons-logging'
      exclude module: 'httpclient'
  }
  testCompile 'org.robolectric:shadows-support-v4:3.0-rc3'
  testCompile 'org.assertj:assertj-core:1.7.0'
  testCompile 'com.squareup.okhttp:mockwebserver:1.2.1'
  </code></pre>
  <p>Sample Unit Test class :</p>
  <pre><code>@RunWith(RobolectricGradleTestRunner.class)
  @Config(constants = BuildConfig.class)
  public class AdServerClientTest {
  
      @Test(timeout = 7000)
      public void testLongTask() {
          // Fails if the method takes longer than 7 seconds
          ShadowGooglePlayServicesUtil.setIsGooglePlayServicesAvailable(ConnectionResult.SUCCESS);
  
  
          assertTrue(false);
      }
  }
  </code></pre>
  <p>Exception below :</p>
  <pre><code>Exception in thread &quot;main&quot; java.lang.NoClassDefFoundError: android/content/Context
      at java.lang.Class.getDeclaredMethods0(Native Method)
      at java.lang.Class.privateGetDeclaredMethods(Class.java:2615)
      at java.lang.Class.getMethod0(Class.java:2856)
      at java.lang.Class.getMethod(Class.java:1668)
      at org.junit.internal.builders.SuiteMethodBuilder.hasSuiteMethod(SuiteMethodBuilder.java:20)
      at com.intellij.junit4.JUnit46ClassesRequestBuilder.collectWrappedRunners(JUnit46ClassesRequestBuilder.java:79)
      at com.intellij.junit4.JUnit46ClassesRequestBuilder.getClassesRequest(JUnit46ClassesRequestBuilder.java:51)
      at com.intellij.junit4.JUnit4TestRunnerUtil.buildRequest(JUnit4TestRunnerUtil.java:92)
      at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:39)
      at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:212)
      at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:68)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.lang.reflect.Method.invoke(Method.java:606)
      at com.intellij.rt.execution.application.AppMain.main(AppMain.java:140)
  Caused by: java.lang.ClassNotFoundException: android.content.Context
      at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
      at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
      at java.security.AccessController.doPrivileged(Native Method)
      at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
      at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
      at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
      at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
      ... 16 more
  </code></pre>
  <p><strong>UPDATE :</strong></p>
  <p>I've reduced the Test Class to only one assert and the Exception change to a Parcelable error.</p>
  <pre><code>@Test(timeout = 7000)
  public void testLongTask() {
      assertTrue(false);
  }
  
  Exception in thread &quot;main&quot; java.lang.NoClassDefFoundError: android/os/Parcelable
      at java.lang.ClassLoader.defineClass1(Native Method)
      at java.lang.ClassLoader.defineClass(ClassLoader.java:800)
      at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
      at java.net.URLClassLoader.defineClass(URLClassLoader.java:449)
      at java.net.URLClassLoader.access$100(URLClassLoader.java:71)
      at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
      at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
      at java.security.AccessController.doPrivileged(Native Method)
      at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
      at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
      at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
      at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
      at java.lang.Class.getDeclaredMethods0(Native Method)
      at java.lang.Class.privateGetDeclaredMethods(Class.java:2615)
      at java.lang.Class.getMethod0(Class.java:2856)
      at java.lang.Class.getMethod(Class.java:1668)
      at org.junit.internal.builders.SuiteMethodBuilder.hasSuiteMethod(SuiteMethodBuilder.java:20)
      at com.intellij.junit4.JUnit46ClassesRequestBuilder.collectWrappedRunners(JUnit46ClassesRequestBuilder.java:79)
      at com.intellij.junit4.JUnit46ClassesRequestBuilder.getClassesRequest(JUnit46ClassesRequestBuilder.java:51)
      at com.intellij.junit4.JUnit4TestRunnerUtil.buildRequest(JUnit4TestRunnerUtil.java:92)
      at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:39)
      at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:212)
      at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:68)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.lang.reflect.Method.invoke(Method.java:606)
      at com.intellij.rt.execution.application.AppMain.main(AppMain.java:140)
  Caused by: java.lang.ClassNotFoundException: android.os.Parcelable
      at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
      at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
      at java.security.AccessController.doPrivileged(Native Method)
      at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
      at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
      at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
      at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
      ... 28 more
  </code></pre>
  <p><strong>UPDATE 2 :</strong>
  I've run <code>./gradlew clean assembleDebug testDebug</code> and the result is that <code>java.lang.UnsupportedOperationException: Robolectric does not support API level 22.</code>. Really strange because when switching to robolectric 3-RC3, emulateSdk and reportSdk has been removed : <code>@Config(emulateSdk = 21, reportSdk = 21, constants = BuildConfig.class)</code>. But have something to search for now.</p>