1414
1515package com .google .firebase .gradle .plugins .ci .device ;
1616
17+ import com .android .build .gradle .TestedExtension ;
1718import com .android .builder .testing .api .TestServer ;
1819import com .google .common .collect .ImmutableList ;
1920import com .google .firebase .gradle .plugins .ci .Environment ;
2021import java .io .File ;
2122import java .nio .file .Paths ;
23+ import java .util .HashMap ;
24+ import java .util .Map ;
2225import java .util .Optional ;
2326import java .util .Random ;
2427import java .util .stream .Collectors ;
@@ -29,11 +32,22 @@ public class FirebaseTestServer extends TestServer {
2932 private final Project project ;
3033 private final FirebaseTestLabExtension extension ;
3134 private final Random random ;
35+ private final Map <String , Map <String , String >> instrumentationArgs ;
3236
33- public FirebaseTestServer (Project project , FirebaseTestLabExtension extension ) {
37+ public FirebaseTestServer (
38+ Project project , FirebaseTestLabExtension extension , TestedExtension android ) {
3439 this .project = project ;
3540 this .extension = extension ;
41+ this .instrumentationArgs = new HashMap <>();
3642 this .random = new Random (System .currentTimeMillis ());
43+
44+ android
45+ .getTestVariants ()
46+ .all (
47+ variant ->
48+ instrumentationArgs .put (
49+ variant .getName (),
50+ variant .getMergedFlavor ().getTestInstrumentationRunnerArguments ()));
3751 }
3852
3953 @ Override
@@ -43,6 +57,8 @@ public String getName() {
4357
4458 @ Override
4559 public void uploadApks (String variantName , File testApk , File testedApk ) {
60+
61+ Map <String , String > currentInstrumentationArgs = instrumentationArgs .get (variantName );
4662 // test lab requires an "app" apk, so we give an empty apk to it.
4763 String testedApkPath =
4864 testedApk != null
@@ -85,6 +101,14 @@ public void uploadApks(String variantName, File testApk, File testedApk) {
85101 "--results-dir" ,
86102 Paths .get (dir , project .getPath () + "_" + random .nextLong ()).toString ()));
87103
104+ if (currentInstrumentationArgs != null ) {
105+ String variablesArg =
106+ currentInstrumentationArgs .entrySet ().stream ()
107+ .map (entry -> entry .getKey () + "=" + entry .getValue ())
108+ .collect (Collectors .joining ("," ));
109+ args .add ("--environment-variables" , variablesArg );
110+ }
111+
88112 project .exec (
89113 spec -> {
90114 spec .commandLine (args .build ());
0 commit comments