Is there a gradle plugin that allows adb commandline options when installing android apps? I'm looking to run robotium tests on an Android M device, while ignoring the permission dialogs that pop up that ask for camera, microphone, etc, permissions.
Asked
Active
Viewed 1,222 times
2 Answers
9
in build.gradle
task grantPermissions(type: Exec, dependsOn: 'installDebugAndroidTest') {
def permissions = ['INTERNET',
'GET_ACCOUNTS',
'WAKE_LOCK',
'VIBRATE',
'READ_CONTACTS',
'RECORD_AUDIO',
'CAMERA',
'WRITE_EXTERNAL_STORAGE',
'READ_EXTERNAL_STORAGE']
permissions.each {
commandLine "\$ANDROID_HOME/platform-tools/adb shell pm grant com.singlewire.cirrus android.permission.${it}".split(' ')
}}
tasks.whenTaskAdded { task ->
if (task.name.startsWith('connectedDebugAndroidTest')) {
task.dependsOn grantPermissions
}
}

roy zhang
- 191
- 1
- 9
-1
android.productFlavors.all { flavour ->
def applicationId = flavour.applicationId
def adb = android.getAdbExe().toString()
def grantPermissionsTask = tasks.create("grant${flavour.name.capitalize()}Permissions") << {
"${adb} shell pm grant ${applicationId} android.permission.ACCESS_FINE_LOCATION".execute()
"${adb} shell pm grant ${applicationId} android.permission.ACCESS_COARSE_LOCATION".execute()
}
grantPermissionsTask.description = "Grants permissions for Marshmallow"
tasks.whenTaskAdded { theTask ->
def assemblePattern = ~"assemble${flavour.name.capitalize()}DebugAndroidTest"
if (assemblePattern.matcher(theTask.name).matches()) {
theTask.dependsOn grantPermissionsTask.name
}
}
}
You can do it for instrumentation testing only not for unit testing. Reference

Darshan Santoki
- 121
- 2
- 9