title: Use an Android Library (AAR) as dependency for a Java (Jar) Project with Gradle
body: <p>The Java Jar <code>build.gradle</code> module:</p>
  
  <pre><code>apply plugin: 'java'
  
  dependencies {
      compile fileTree(dir: 'libs', include: ['*.jar'])
      compile 'junit:junit:4.12'
  
      // rx
      compile "io.reactivex.rxjava2:rxjava:2.0.4"
      compile "io.reactivex.rxjava2:rxandroid:2.0.1"
  }
  
  sourceCompatibility = "1.8"
  targetCompatibility = "1.8"
  </code></pre>
  
  <p>This Jar is supposed to be a library used as an utility library for unit testing android projects:</p>
  
  <pre><code>apply plugin: 'com.android.application'
  
  android {
      // ...
  }
  
  dependencies {
      compile fileTree(dir: 'libs', include: ['*.jar'])
      // test
      testCompile 'junit:junit:4.12'
      testCompile project(':test-utils')
  
      // ... other non-test dependencies here (including rx)
  }
  </code></pre>
  
  <p>This include:</p>
  
  <pre><code>    testCompile project(':test-utils')
  </code></pre>
  
  <p>fails with:</p>
  
  <blockquote>
    <p>Error:Module 'my-android-app:test-utils:unspecified' depends on one or
    more Android Libraries but is a jar</p>
  </blockquote>
  
  <p>Which is because <code>RxAndroid</code> is an Android .aar library.</p>
  
  <p>I need RxAndroid in my test utility module because one of the things the module provide is a junit <code>MethodRule</code> for setting up Rx Schedulers through the <code>@Rule</code> annotation and other custom annotations in <code>@Test</code> methods.</p>
  
  <p>This is needed because RxAndroid AndroidScheduler use Android <code>Handler</code> / <code>Looper</code> class, which are part of the Android framework and are not available in unit tests. The Android Scheduler can be replaced using <code>RxAndroidPlugins</code>.</p>
  
  <p>Which means I only need the JAR part of the RxAndroid AAR (<code>classes.jar</code> inside rxandroid artifact).</p>
  
  <p>Is there a way to tell gradle I only need the Java part of the AAR as dependency?</p>
  
  <p>I do not consider a solution manually extracting the <code>classes.jar</code> from the AAR and including it as a dependency. That's a workaround.</p>
  
  <p>This Java test library is supposed to be shared among my projects and I'm currently copying the <code>MethodRule</code> class in every of my projects which is far from ideal.</p>