5

I have got manifest placeholder for service:

<service
        android:name=".MyService"
        android:process="${processName}">

In my build.gradle I replaced it.

android {  
    defaultConfig {
        manifestPlaceholders = [
                processName: ':Proc'
        ]
    }
}

But for my espresso tests (androidTest) I need empty value in the processName. How can I do this?

I have tried to do this with buildTypes, but it doesn't work (BuildType names cannot start with "androidTest")

shmakova
  • 6,076
  • 3
  • 28
  • 44

4 Answers4

2

This example works for me with Gradle plugin 3.4.1:

android {
    unitTestVariants.all {
        it.mergedFlavor.manifestPlaceholders += [
                placeHolderName: "placeHolderValue"
        ]

        it.mergedFlavor.addResValue(new ClassFieldImpl("string", "resValueName", "resValueValue"))
    }
}
HotIceCream
  • 2,271
  • 2
  • 19
  • 27
0

I think that the best approach here would be to write a second AndroidManifest just for your instrumented tests, as suggested by the documentation

../app/src/androidTest/AndroidManifest.xml

<service
   android:name=".MyService"
   android:process="">
  • It doesn't work :( In merged manifest there is the service from the main manifest, not overrided – shmakova Feb 19 '18 at 13:00
  • You must consider that there are *two* APKs generated, one for your app and the other one for testing. Inspect the one used for testing and see if service was overwritten. If you are still having problems, try giving a look at [this question](https://stackoverflow.com/questions/26244998/androidmanifest-in-androidtest-directory-being-ignored) – Nicolás Carrasco-Stevenson Feb 19 '18 at 13:06
0

Simply adding manifest will not help, because you need to provide merging strategy for it just use:

 <service
   android:name=".MyService"
   android:process="" 
   tools:node="replace">

Than in merged manifest you should get correct value.

Serge
  • 318
  • 3
  • 7
0
subprojects {
    afterEvaluate { subproject ->
        def String taskRequests = getGradle().getStartParameter().getTaskRequests().toString()
        if (taskRequests.contains("AndroidTest")) {
            android {
                defaultConfig {
                    manifestPlaceholders = [
                        placeHolderName: "placeHolderValue"
                    ]
                }
            }
        }
    }
}
lotosbin
  • 637
  • 9
  • 9