Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WRITE_EXTERNAL_STORAGE Permission on newer devices #39

Open
christopherperry opened this issue Jun 23, 2017 · 19 comments
Open

WRITE_EXTERNAL_STORAGE Permission on newer devices #39

christopherperry opened this issue Jun 23, 2017 · 19 comments

Comments

@christopherperry
Copy link

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.

@felipecsl
Copy link
Collaborator

Are you running from the command line or Android Studio?

@christopherperry
Copy link
Author

Android Studio, from the test class.

@felipecsl
Copy link
Collaborator

Hmm that may be why. Does it work if you run from the command line with ./gradlew connectedAndroidCheck?

@christopherperry
Copy link
Author

./gradlew connectedAndroidTest is able to run the tests; however, the tests fail. Perhaps the IdlingResource isn't working correctly?

@felipecsl
Copy link
Collaborator

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

@athkalia
Copy link

athkalia commented Jul 9, 2017

It seems to respect the adbOptions for me, as long as you have the permission defined in the AndroidManifest

@niranjani23
Copy link

@athkalia I still see the same issue. Were you able to get the test running from Android Studio?

@niranjani23
Copy link

niranjani23 commented Jul 31, 2017

@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?

@athkalia
Copy link

I'll give it another bash over the weekend and update here

@athkalia
Copy link

indeed I've tried it once more and it doesn't seem to work, sorry

@athkalia
Copy link

Setup is here btw if you want to experiment a bit
https://github.com/athkalia/Just-Another-Android-App

@felipecsl
Copy link
Collaborator

I've been running usually on API25 emulators with no problems. Are you running on physical devices?

@malachid
Copy link

Confirmed that I ran into the same problem trying to run a test against the LG v20 from A.S.

@malachid
Copy link

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
    );

@scottyab
Copy link

scottyab commented Feb 19, 2018

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)

@malachid
Copy link

@scottyab did you put that in a companion object?

@scottyab
Copy link

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)
    }

@cbuche
Copy link

cbuche commented Jun 28, 2018

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"/>

@ddudek
Copy link

ddudek commented Oct 11, 2021

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants