Gradle task of project depend on task of other project

I have an android project with two different apps.

This is my current structure:

appA/
  buid.gradle
  ...
appB/
  buid.gradle
  ...
settings.gradle
gradlew

settings.gradle is the following:

include ':appA'
include ':appB'

To test appA, appB needs to be installed on the emulator.

Right now everything works if I first install both apps and then run appA tests

./gradlew installDebug              # install both apps apks
./gradlew connectedInstrumentTest   # runs tests on both apps (appB does not have any)

How can I explicitly say that connecedInstrumentTest of appA dependes on installDebug of appB?


Solution 1:

From the parent build.gradle file you can state:

tasks.getByPath(':appA:connectedInstrumentTest').dependsOn(':appB:installDebug')

Or within appA's build.gradle you can add this line:

connectedInstrumentTest.dependsOn(':appB:installDebug')

Or an equivalent way to say the same thing in appA's build.gradle:

connectedInstrumentTest {
   dependsOn: ':appB:installDebug'
}