okreplay
okreplay copied to clipboard
WRITE_EXTERNAL_STORAGE Permission on newer devices
When trying to run the sample tests on my Nexus 6P running Android 7.1.2 I get the following RuntimeException:
We need WRITE_EXTERNAL_STORAGE permission for OkReplay. Please add
adbOptions { installOptions "-g" }
to your build.gradle file.
This option is already in the build.gradle
file of the sample.
Are you running from the command line or Android Studio?
Android Studio, from the test class.
Hmm that may be why. Does it work if you run from the command line with ./gradlew connectedAndroidCheck
?
./gradlew connectedAndroidTest
is able to run the tests; however, the tests fail. Perhaps the IdlingResource
isn't working correctly?
Well that's gonna depend on why it's failing, but that's out of the scope of this issue, it seems.
Regarding the original problem, I think it's expected that running from Android Studio doesn't respect adbOptions
unfortunately
It seems to respect the adbOptions for me, as long as you have the permission defined in the AndroidManifest
@athkalia I still see the same issue. Were you able to get the test running from Android Studio?
@felipecsl I too noticed the error: We need WRITE_EXTERNAL_STORAGE permission for OkReplay. Do you mind updating the readme if the test can be invoked only via command line and not via Android Studio?
I'll give it another bash over the weekend and update here
indeed I've tried it once more and it doesn't seem to work, sorry
Setup is here btw if you want to experiment a bit https://github.com/athkalia/Just-Another-Android-App
I've been running usually on API25 emulators with no problems. Are you running on physical devices?
Confirmed that I ran into the same problem trying to run a test against the LG v20 from A.S.
I was able to get past the permission problem by using the GrantPermissionRule.
@ClassRule
public static GrantPermissionRule grantPermissionRule = GrantPermissionRule.grant(
Manifest.permission.WRITE_EXTERNAL_STORAGE
);
I'm unable to get past the permissions issue with the GrantPermissionRule
. I couldn't use the @ClassRule
as the compiler complained about it not being static 😞
@Rule
@JvmField
public val grantPermissionRule: GrantPermissionRule = GrantPermissionRule.grant(Manifest.permission.WRITE_EXTERNAL_STORAGE)
@scottyab did you put that in a companion object?
Thanks @malachid 👍 I'd forgotten the need for companion object. The below allows me to run Espresso tests from Android Studio.
companion object {
@ClassRule
@JvmField
val grantPermissionRule: GrantPermissionRule = GrantPermissionRule.grant(Manifest.permission.WRITE_EXTERNAL_STORAGE)
}
After going in circles for the better part of a day, I've found that I need the following tools value in order for the GrantPermissionRule to work (in addition to the @ClassRule
annotation)
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" tools:remove="android:maxSdkVersion"/>
After going in circles despite above suggestions, using ClassRule in companion object worked, but this gave me a hint that it's an rules ordering issue so also this approach below works using just RuleChain and regular @Rule
annotation:
var permissionRule: GrantPermissionRule = GrantPermissionRule.grant(Manifest.permission.WRITE_EXTERNAL_STORAGE)
var activityTestRule = ActivityTestRule(ExampleActivity::class.java, false, false)
val okReplayRule: TestRule = OkReplayRuleChain(configuration, activityTestRule).get()
@Rule
@JvmField
val ruleChain: RuleChain = RuleChain.outerRule(activityTestRule).around(permissionRule).around(okReplayRule)