android / nowinandroid

A fully functional Android app built entirely with Kotlin and Jetpack Compose
Apache License 2.0
17.37k stars 3.17k forks source link

[Bug]: Permission: android.permission.WRITE_EXTERNAL_STORAGE cannot be granted! while running Macrobenchmark #796

Open JyotimoyKashyap opened 1 year ago

JyotimoyKashyap commented 1 year ago

Is there an existing issue for this?

Is there a StackOverflow question about this issue?

What happened?

Brief

While trying to build and test the benchmark module. I wanted to run the sample benchmark WarmStartupBenchmark. I just cloned the repo and did basic setup of the repository and installed the app that ran successfully after which I decided to run the benchmark.

Issue

The build runs successfully but the test cases fails with an error message shown bellow.

Permission: android.permission.WRITE_EXTERNAL_STORAGE cannot be granted!

This says that it cannot grant permissions for storage, which certainly should not be the case. I have seen this issue with every benchmarking repository that I tried from google. Recently, I tried the codelab for benchmarking in android which has the same issue.

I have also researched about it and found an open issue in (IssueTracker)[https://issuetracker.google.com/issues/235344525].

Device Details

Android Studio Version : Flamingo Android Version : 11 (Physical Device) Device Name : Redmi Note 8 Pro.

Relevant logcat output

Requesting permission: pm grant com.google.samples.apps.nowinandroid.benchmarks android.permission.WRITE_EXTERNAL_STORAGE
2023-06-13 14:37:06.458 30426-30476 UiAutomation            com....apps.nowinandroid.benchmarks  W  UiAutomation.grantRuntimePermission() is more robust and should be used instead of 'pm grant'
2023-06-13 14:37:07.476 30426-30476 GrantPermissionCallable com....apps.nowinandroid.benchmarks  E  Permission: android.permission.WRITE_EXTERNAL_STORAGE cannot be granted!
2023-06-13 14:37:07.476 30426-30476 TestRunner              com....apps.nowinandroid.benchmarks  E  failed: startupBaselineProfileDisabled(com.google.samples.apps.nowinandroid.startup.WarmStartupBenchmark)
2023-06-13 14:37:07.476 30426-30476 TestRunner              com....apps.nowinandroid.benchmarks  E  ----- begin exception -----
2023-06-13 14:37:07.478 30426-30476 TestRunner              com....apps.nowinandroid.benchmarks  E  junit.framework.AssertionFailedError: Failed to grant permissions, see logcat for details
                                                                                                        at junit.framework.Assert.fail(Assert.java:50)
                                                                                                        at androidx.test.runner.permission.PermissionRequester.requestPermissions(PermissionRequester.java:111)
                                                                                                        at androidx.test.rule.GrantPermissionRule$RequestPermissionStatement.evaluate(GrantPermissionRule.java:135)
                                                                                                        at org.junit.rules.RunRules.evaluate(RunRules.java:20)
                                                                                                        at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306)
                                                                                                        at org.junit.runners.BlockJUnit4ClassRunner$1.evaluate(BlockJUnit4ClassRunner.java:100)
                                                                                                        at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:366)
                                                                                                        at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:103)
                                                                                                        at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:63)
                                                                                                        at org.junit.runners.ParentRunner$4.run(ParentRunner.java:331)
                                                                                                        at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:79)
                                                                                                        at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:329)
                                                                                                        at org.junit.runners.ParentRunner.access$100(ParentRunner.java:66)
                                                                                                        at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:293)
                                                                                                        at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306)
                                                                                                        at org.junit.runners.ParentRunner.run(ParentRunner.java:413)
                                                                                                        at org.junit.runners.Suite.runChild(Suite.java:128)
                                                                                                        at org.junit.runners.Suite.runChild(Suite.java:27)
                                                                                                        at org.junit.runners.ParentRunner$4.run(ParentRunner.java:331)
                                                                                                        at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:79)
                                                                                                        at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:329)
                                                                                                        at org.junit.runners.ParentRunner.access$100(ParentRunner.java:66)
                                                                                                        at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:293)
                                                                                                        at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306)
                                                                                                        at org.junit.runners.ParentRunner.run(ParentRunner.java:413)
                                                                                                        at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
                                                                                                        at org.junit.runner.JUnitCore.run(JUnitCore.java:115)
                                                                                                        at androidx.test.internal.runner.TestExecutor.execute(TestExecutor.java:67)
                                                                                                        at androidx.test.internal.runner.TestExecutor.execute(TestExecutor.java:58)
                                                                                                        at androidx.test.runner.AndroidJUnitRunner.onStart(AndroidJUnitRunner.java:446)
                                                                                                        at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:2207)
2023-06-13 14:37:07.478 30426-30476 TestRunner              com....apps.nowinandroid.benchmarks  E  ----- end exception -----

Code of Conduct

BreakZero commented 11 months ago

Some devices keep monitoring permission, and benchmark need modify and delete the contents of your shared storage, so it need to grant the permission android.permission.WRITE_EXTERNAL_STORAGE. You can turn on Disable permission monitoring under Developer Options will fix.

ambushwork commented 10 months ago

@BreakZero unfortunately some phones don't have this option to disable this. is there any other workaround about this?

BreakZero commented 10 months ago

@ambushwork how about the accepted answer in https://stackoverflow.com/questions/53903976/grantpermissionrule-failed-to-grant-permissions