Last active
October 3, 2017 06:46
-
-
Save fangzhzh/01e1bb59712eb2fa7d9b7a8136aeea43 to your computer and use it in GitHub Desktop.
gradle task to grant permission to device
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
android.applicationVariants.all { variant -> | |
def applicationId = variant.applicationId | |
def adb = androidadbExe. as String | |
def variantName = variant.name.capitalize() | |
def grantPermissionTask = task.create("create${variantName}Permissions") << { | |
"${adb} devices".execute().text.eachLine { | |
if(it.endsWith("device")){ | |
def device = it.split()[0] | |
println "Granting permissions on devices ${device}" | |
"${adb} -s ${devices} shell pm grant ${applicationId} android.permission.ACCESS_FINE_LOCATION".execute() | |
"${adb} -s ${devices} shell pm grant ${applicationId} android.permission.ACCESS_COARSE_LOCATION".execute() | |
"${adb} -s ${devices} shell pm grant ${applicationId} android.permission.READ_EXTERNAL_STORAGE".execute() | |
"${adb} -s ${devices} shell pm grant ${applicationId} android.permission.WRITE_EXTERNAL_STORAGE".execute() | |
} | |
} | |
} | |
} | |
@letroll thanks, fixed
There are some mistakes on line 5:
def grantPermissionTask = task.create("create${variantName}Permissions") << {
Should be:
def grantPermissionTask = tasks.create("grant${variantName}Permissions") << {
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
thank for sharing, a little mistake :
android.permission.READ_EXTERNAL_STORAGE