Hardik Trivedi
Hardik Trivedi

Reputation: 6102

Multi projects androidTest dependencies

I am facing below problem. I have three projects. I call them projects A,B and lib

Project Lib
-> androidTest
   -> utilityfile.kt

Project A
-> androidTest
   -> <use utilityfile.kt here>

Project B
-> androidTest
   -> <use utilityfile.kt here>

Now I have one utility inside lib project which is obviously a library project. I can put my utility file only inside androidTest and not under main or test directory. (This is something I can't change)

Now I want to access that test utility which is inside lib module, into projects A and B. But gradle is giving me errors at runtime.

The error is 'compilation error' when I try to run android test case in project A or B.

I searched so much and found using old gradle version there was a way e.g

https://stackoverflow.com/a/32083131/1166926

testCompile project(':libProject').sourceSets.test.output

and also https://stackoverflow.com/a/5648565/1166926

But these are not working for me now, as newer gradle doesn't support this now.

What can be done to access the androidTest class files into another project's androidTest directory?

Upvotes: 0

Views: 819

Answers (1)

Kevin Coppock
Kevin Coppock

Reputation: 134714

You should extract that test utility into its own separate library module, and then add that as an androidTestImplementation on projects A, B, and Lib.

For example:

TestUtils Lib
-> src/main/java
   -> UtilityFile.kt

Project A
-> androidTestImplementation project(":testUtils")

Project B
-> androidTestImplementation project(":testUtils")

Project Lib
-> androidTestImplementation project(":testUtils")

Upvotes: 1

Related Questions