title: NoClassDefFoundError: ... R$styleable when using Robolectric with Android Library (AAR)
body: <p>We are developing a library that provides an Activity, and I would like to be able to perform some functional testing on the Activity.</p>
  
  <p>My <code>build.gradle</code> includes:</p>
  
  <pre><code>dependencies {
      compile fileTree(dir: 'libs', include: ['*.jar'])
      compile 'com.android.support:appcompat-v7:22.1.1'
  
      testCompile 'org.mockito:mockito-core:1.+'
      testCompile 'junit:junit:4.12'
      testCompile('org.robolectric:robolectric:3.0-rc2') {
          exclude group: 'commons-logging', module: 'commons-logging'
          exclude group: 'org.apache.httpcomponents', module: 'httpclient'
      }
      testCompile('org.robolectric:shadows-httpclient:3.0-rc2') {
          exclude group: 'commons-logging', module: 'commons-logging'
          exclude group: 'org.apache.httpcomponents', module: 'httpclient'
      }
      testCompile('org.robolectric:shadows-support-v4:3.0-rc2') {
          exclude group: 'commons-logging', module: 'commons-logging'
          exclude group: 'org.apache.httpcomponents', module: 'httpclient'
      }
  }
  </code></pre>
  
  <p>And my <code>LibraryActivityTest</code> includes:</p>
  
  <pre><code>@RunWith(RobolectricGradleTestRunner.class)
  public class LibraryActivityTest {
  
      @Test
      public void testOnCreate() throws Exception {
          LibraryActivity libraryActivity = Robolectric.buildActivity(LibraryActivity.class).create().get();
  
  
      }
  }
  </code></pre>
  
  <p><code>MyRobolectricGradleTestRunner</code> overrides <code>getAppManifest</code> to restore the ability to specify a test-specific AndroidManifest.xml instead of using the application version.</p>
  
  <p>When I attempt to run <code>testOnCreate</code> from Android Studio or gradle command line, I get a class def not found error for <code>android/support/v7/appcompat/R$styleable</code>:</p>
  
  <pre><code>android/support/v7/appcompat/R$styleable
  java.lang.NoClassDefFoundError: android/support/v7/appcompat/R$styleable
      at android.support.v7.app.AppCompatDelegateImplBase.onCreate(AppCompatDelegateImplBase.java:109)
      at android.support.v7.app.AppCompatDelegateImplV7.onCreate(AppCompatDelegateImplV7.java:146)
      at android.support.v7.app.AppCompatActivity.onCreate(AppCompatActivity.java:59)
      at com.moxiesoft.mylibrary.LibraryActivity.onCreate(LibraryActivity.java:13)
      at android.app.Activity.performCreate(Activity.java:5133)
      at org.robolectric.util.ReflectionHelpers$3.run(ReflectionHelpers.java:144)
      at org.robolectric.util.ReflectionHelpers.traverseClassHierarchy(ReflectionHelpers.java:241)
      at org.robolectric.util.ReflectionHelpers.callInstanceMethod(ReflectionHelpers.java:138)
      at org.robolectric.util.ActivityController$1.run(ActivityController.java:122)
      at org.robolectric.shadows.ShadowLooper.runPaused(ShadowLooper.java:309)
      at org.robolectric.shadows.CoreShadowsAdapter$2.runPaused(CoreShadowsAdapter.java:47)
      at org.robolectric.util.ActivityController.create(ActivityController.java:118)
      at org.robolectric.util.ActivityController.create(ActivityController.java:129)
      at com.moxiesoft.mylibrary.LibraryActivityTest.testOnCreate(LibraryActivityTest.java:20)
      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.robolectric.RobolectricTestRunner$2.evaluate(RobolectricTestRunner.java:235)
      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.robolectric.RobolectricTestRunner$1.evaluate(RobolectricTestRunner.java:168)
      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:69)
      at org.gradle.api.internal.tasks.testing.SuiteTestClassProcessor.processTestClass(SuiteTestClassProcessor.java:48)
      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:105)
      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.DefaultExecutorFactory$StoppableExecutorImpl$1.run(DefaultExecutorFactory.java:64)
      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)
  </code></pre>
  
  <p>It's also worth noting that the installation and configuration seems reasonable, as tests that don't involve <code>ActivityController.create</code> seem to work fine.</p>
  
  <p>How can I resolve this error?</p>