Android multi module test dependency

这一生的挚爱 提交于 2020-03-18 03:28:06

问题


With Android Studio 3.0 / android_gradle_version = '3.0.1' / gradle-4.5

Let's say I have two android modules

module-base
module-a

When I want to access sources from module-base in module-a , I just need to write this in my module-a.gradle

dependencies {
implementation project(path: ':module-base')
}

But, what if I want to access test sources from module-base in test of module-a? Here does not work approach like above

dependencies {
testImplementation project(path: ':module-base')
}

I found lot of advices (few years old) which says something like

    compileTestJava.dependsOn tasks.getByPath(':module-base:testClasses')
    testCompile files(project(':module-base').sourceSets.test.output.classesDir)

or testCompile project(':module-base).sourceSets.test.classes

But no one from mentioned works. There is always something wrong from the compiler point of view :-/

Can you someone help me how to create Android test code dependency between two modules?


回答1:


Actually I find just workaround for this. Don't use test sources from module-base but use sources from test related module module-testutils which is defined like this

dependencies{
   testImplementation project(':module-testutils')
}

Thus you can share common test code which will be excluded for non-testable apk.



来源:https://stackoverflow.com/questions/49436559/android-multi-module-test-dependency

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!