I\'m using Espresso and UIAutomator to write my test cases. I\'m testing external storage permissions when it\'s denied and when it\'s allowed. I have different test cases w
I ran into the same problem and have applied the following solution ( working great everytime for now)
Create a gradle task:
task revokeLocationPermissions(type: Exec) {
def revokeLocationPermission = ['adb', 'shell', 'pm', 'revoke', 'yourPackageNameHere' , 'android.permission.ACCESS_FINE_LOCATION']
commandLine revokeLocationPermission
outputs.upToDateWhen { false }
}
Go to Run/Debug Configurations, and select your Android Instrumented Test. Below, you will have an option "Before launch:" Click the plus sign, and add your custom gradle task
Hope it helps! I've been trying to find a scalable solution for projects with multiple flavors, and thus multiple package names, but so far nothing that really works.