项目的Gradle任务取决于其他项目的任务

Joa*_*ade 6 android gradle

我有一个带有两个不同应用程序的android项目.

这是我目前的结构:

appA/
  buid.gradle
  ...
appB/
  buid.gradle
  ...
settings.gradle
gradlew
Run Code Online (Sandbox Code Playgroud)

settings.gradle如下:

include ':appA'
include ':appB'
Run Code Online (Sandbox Code Playgroud)

要测试appA,需要在模拟器上安装appB.

现在一切正常,如果我先安装两个应用程序,然后运行appA测试

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

我如何能明确地说,connecedInstrumentTest的appA上dependes installDebugappB的

dit*_*kin 11

从父build.gradle文件中,您可以声明:

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

或者在appA的build.gradle中,您可以添加以下行:

connectedInstrumentTest.dependsOn(':appB:installDebug')
Run Code Online (Sandbox Code Playgroud)

或者在appA的build.gradle中用同样的方式说同样的事情:

connectedInstrumentTest {
   dependsOn: ':appB:installDebug'
}
Run Code Online (Sandbox Code Playgroud)