jeudi 17 décembre 2015

How to reference a library drawable from a layout inside a test package?


my goal is quite simple: reference a libary drawable resource from an androidTest xml

MyApplication is the app. It relies on a lib: MyLib. I am building a test project on top of it using the androidTest sourceSet.

Here are the MyApplication gradle file:

...
dependencies {
    compile(project(':MyLib')) //{
//        transitive=true              TRANSITIVE DOES NOT SOLVED MY ISSUE
//    }
   androidTestCompile 'com.android.support.test:runner:0.4'
   androidTestCompile 'com.android.support.test:rules:0.4'
   androidTestCompile 'com.android.support.test.uiautomator:uiautomator-v18:2.1.2'
  androidTestCompile 'com.google.guava:guava:19.0'
}...

NB: there is no other specific androidTest configuration

I have a test layout in the res folder of my test package. I would like this layout to use a drawable of MyLib: "@drawable/mylibresource".

It ends up with the error : Error:(...) No resource found that matches the given name (at 'src' with value '@drawable/mylibresource').

Looking at the gradle-android-plugin test doc, it says:

By default, the application and its own dependencies are added to the test app classpath, but this can be extended with the snippet below:
dependencies {
androidTestCompile 'com.google.guava:guava:11.0.2'
}

This is correct for the app MyApplication package, but not for its dependency.

A workaround is to explicitly add the lib as a dependency of the AndroidTest sourceset. This is not very satisfying if all application dependencies must be duplicated.
(NB: I have also restarted and clean/build the project multiple times)

How can I make the dependency transitivity to work as documented? I suppose something is wrong with my setup, but I can't find what. Any ideas? Thx.

Aucun commentaire:

Enregistrer un commentaire