I had a similar issue, where to fix it I did:
- Create a folder named “
debug” next to “androidTest” folder, which corresponds to thedebugvariant of the app, - Put an
AndroidManifest.xmlfile, which contains the required permission, in said “debug” folder. - Now (re)build, and the permission works under test, since the test app uses the debug variant.
It’s not ideal because it blurs the line between test and debug, which isn’t quite the same thing.
Update; what’s happening is that:
-
There are multiple build types, like “debug” and “release”.
-
Each can have an
AndroidManifest.xmlfile, inside related folder with matching name, like “debug” and “release” folders. -
But “androidTest” is NOT a build type (at time of writing), hence Gradle’s default value for
testBuildTypeoption is “debug”
(as docs mention), like:android { // ... testBuildType "debug" } -
Said inconsistency is handled poorly by so-called Gradle-plugin
(“com.android.tools.build:gradle:7.1.3”). -
And in fact, the “
androidTest/AndroidManifest.xml” file only works for library-projects
(not Apps, at time of writting).
Note that even if we manually set path to manifest, like:
android {
sourceSets {
androidTest {
manifest.srcFile "${project.rootDir}/AndroidManifest.xml"
}
}
}
It’s silently ignored for androidTest source-set (tested with Gradle 7.5.1),
while simialr setting works for main source-set.