The Java Jar build.gradle module:
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" This Jar is supposed to be a library used as an utility library for unit testing android projects:
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) } This include:
testCompile project(':test-utils') fails with:
Error:Module 'my-android-app:test-utils:unspecified' depends on one or more Android Libraries but is a jar
Which is because RxAndroid is an Android .aar library.
I need RxAndroid in my test utility module because one of the things the module provide is a junit MethodRule for setting up Rx Schedulers through the @Rule annotation and other custom annotations in @Test methods.
This is needed because RxAndroid AndroidScheduler use Android Handler / Looper class, which are part of the Android framework and are not available in unit tests. The Android Scheduler can be replaced using RxAndroidPlugins.
Which means I only need the JAR part of the RxAndroid AAR (classes.jar inside rxandroid artifact).
Is there a way to tell gradle I only need the Java part of the AAR as dependency?
I do not consider a solution manually extracting the classes.jar from the AAR and including it as a dependency. That's a workaround.
This Java test library is supposed to be shared among my projects and I'm currently copying the MethodRule class in every of my projects which is far from ideal.
classes.jarinside it (aka = the java part)