Skip to content

Instantly share code, notes, and snippets.

@up1
Last active February 29, 2016 10:27
Show Gist options
  • Select an option

  • Save up1/9a26521e31f246afb849 to your computer and use it in GitHub Desktop.

Select an option

Save up1/9a26521e31f246afb849 to your computer and use it in GitHub Desktop.
Espresso with Android M
task grantPermissions(type: Exec, dependsOn: 'installDevDebug') {
def adb = android.getAdbExe().toString()
commandLine "sh grant_permissions.sh $adb demo.up1.dev".split(" ")
}
afterEvaluate {
tasks.each { task ->
if (task.name.startsWith('connectedDevDebugAndroidTest')) {
task.dependsOn grantPermissions
}
}
}
#!/bin/bash
#
# argument: apk adb package
# ex: sh grant_permissions.sh <path_to_adb> <package>
adb=$1
package=$2
if [ "$#" = 0 ]; then
echo "No parameters found, run with sh grant_permissions.sh <path_to_adb> <package>"
exit 0
fi
# get all the devices
devices=$($adb devices | grep -v 'List of devices' | cut -f1 | grep '.')
for device in $devices; do
echo "Setting permissions to device" $device "for package" $package
$adb -s $device shell pm grant $package android.permission.READ_PHONE_STATE
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment