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

Scoped Storage targetSdk 29+ without requestLegacyExternalStorage #43

Closed
kuFEAR opened this issue Jan 21, 2021 · 11 comments
Closed

Scoped Storage targetSdk 29+ without requestLegacyExternalStorage #43

kuFEAR opened this issue Jan 21, 2021 · 11 comments

Comments

@kuFEAR
Copy link

kuFEAR commented Jan 21, 2021

Do you have plan to update targetSdk in allure-android and rework file storing?

if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) return
here we should exclude requiring WRITE_EXTERNAL_STORAGE permission for projects with supported Scoped Storage
https://developer.android.com/about/versions/11/privacy/storage
https://developer.android.com/training/data-storage/use-cases

as result now we crashed with this:

E/GrantPermissionCallable: Permission: android.permission.WRITE_EXTERNAL_STORAGE cannot be granted!
 E/TestExecutor: Fatal exception when running tests
    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 io.qameta.allure.android.internal.TestUtilsKt.requestExternalStoragePermissions(TestUtils.kt:28)
        at io.qameta.allure.android.listeners.ExternalStoragePermissionsListener.testRunStarted(ExternalStoragePermissionsListener.kt:9)
@SergKhram
Copy link
Contributor

@viclovsky check this and my ticket, pls

@QAutomatron
Copy link

QAutomatron commented Mar 25, 2021

Hey there. I am using latestallure-kotlin 2.2.3 with fixes for #51 and #52 still getting io.qameta.allure.kotlin.AllureResultsWriteException: Could not create Allure results directory error on Android 11.

@SergKhram
Copy link
Contributor

Need to merge #54

@anriijmind
Copy link

anriijmind commented Apr 13, 2021

@QAutomatron #54 merge fixed your problem? Because I have the same error.

@QAutomatron
Copy link

@anriijmind it's seems fixed for this exact error but our tests still not working due to other errors within android-test packages

@anriijmind
Copy link

anriijmind commented Apr 14, 2021

@anriijmind it's seems fixed for this exact error but our tests still not working due to other errors within android-test packages

I can't fix it on 29-30 android API. At 28 it works.
I have added permissions in debug folder for manifest

    <uses-permission-sdk-23 android:name="android.permission.READ_EXTERNAL_STORAGE" />
    <uses-permission-sdk-23 android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission-sdk-23 android:name="android.permission.MANAGE_EXTERNAL_STORAGE" />
  <application
        android:requestLegacyExternalStorage="true">

And add same to the manifest in the folder with tests, doesn't work

io.qameta.allure.kotlin.AllureResultsWriteException: Could not write Allure attachment
at io.qameta.allure.kotlin.FileSystemResultsWriter.write(FileSystemResultsWriter.kt:51)
at io.qameta.allure.kotlin.AllureLifecycle.writeAttachment(AllureLifecycle.kt:497)
at io.qameta.allure.kotlin.AllureLifecycle.addAttachment(AllureLifecycle.kt:453)
at io.qameta.allure.kotlin.Allure.attachment(Allure.kt:261)
at io.qameta.allure.android.AllureScreenshotKt.allureScreenshot(AllureScreenshot.kt:34)
at org.systems.jmind.metamorph.ui.settings.SettingsFragmentTest$screenshotExample$1.invoke(SettingsFragmentTest.kt:33)
at org.systems.jmind.metamorph.ui.settings.SettingsFragmentTest$screenshotExample$1.invoke(SettingsFragmentTest.kt:32)
at io.qameta.allure.kotlin.Allure.step(Allure.kt:60)
at org.systems.jmind.metamorph.ui.settings.SettingsFragmentTest.screenshotExample(SettingsFragmentTest.kt:32)
... 34 trimmed
Caused by: java.io.FileNotFoundException: /storage/emulated/0/allure-results/05f9bf99-d19e-4002-99e6-21521c40db89-attachment.png: open failed: EACCES (Permission denied)
at libcore.io.IoBridge.open(IoBridge.java:496)
at java.io.FileOutputStream.<init>(FileOutputStream.java:235)
at java.io.FileOutputStream.<init>(FileOutputStream.java:186)
at io.qameta.allure.kotlin.FileSystemResultsWriter.write(FileSystemResultsWriter.kt:46)
... 43 more
Caused by: android.system.ErrnoException: open failed: EACCES (Permission denied)
at libcore.io.Linux.open(Native Method)
at libcore.io.ForwardingOs.open(ForwardingOs.java:167)
at libcore.io.BlockGuardOs.open(BlockGuardOs.java:252)
at libcore.io.ForwardingOs.open(ForwardingOs.java:167)
at android.app.ActivityThread$AndroidOs.open(ActivityThread.java:7255)
at libcore.io.IoBridge.open(IoBridge.java:482)
... 46 more

And adb command doesn't help

adb shell appops set --uid package WRITE_EXTERNAL_STORAGE allow
adb shell appops set --uid package.debug.test WRITE_EXTERNAL_STORAGE allow
adb shell appops set --uid package.test WRITE_EXTERNAL_STORAGE allow

@SergKhram
Copy link
Contributor

@anriijmind it's seems fixed for this exact error but our tests still not working due to other errors within android-test packages

I can't fix it on 29-30 android API. At 28 it works.

I have added permissions in debug folder for manifest


    <uses-permission-sdk-23 android:name="android.permission.READ_EXTERNAL_STORAGE" />

    <uses-permission-sdk-23 android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

    <uses-permission-sdk-23 android:name="android.permission.MANAGE_EXTERNAL_STORAGE" />


  <application

        android:requestLegacyExternalStorage="true">

And add same to the manifest in the folder with tests, doesn't work


io.qameta.allure.kotlin.AllureResultsWriteException: Could not write Allure attachment

at io.qameta.allure.kotlin.FileSystemResultsWriter.write(FileSystemResultsWriter.kt:51)

at io.qameta.allure.kotlin.AllureLifecycle.writeAttachment(AllureLifecycle.kt:497)

at io.qameta.allure.kotlin.AllureLifecycle.addAttachment(AllureLifecycle.kt:453)

at io.qameta.allure.kotlin.Allure.attachment(Allure.kt:261)

at io.qameta.allure.android.AllureScreenshotKt.allureScreenshot(AllureScreenshot.kt:34)

at org.systems.jmind.metamorph.ui.settings.SettingsFragmentTest$screenshotExample$1.invoke(SettingsFragmentTest.kt:33)

at org.systems.jmind.metamorph.ui.settings.SettingsFragmentTest$screenshotExample$1.invoke(SettingsFragmentTest.kt:32)

at io.qameta.allure.kotlin.Allure.step(Allure.kt:60)

at org.systems.jmind.metamorph.ui.settings.SettingsFragmentTest.screenshotExample(SettingsFragmentTest.kt:32)

... 34 trimmed

Caused by: java.io.FileNotFoundException: /storage/emulated/0/allure-results/05f9bf99-d19e-4002-99e6-21521c40db89-attachment.png: open failed: EACCES (Permission denied)

at libcore.io.IoBridge.open(IoBridge.java:496)

at java.io.FileOutputStream.<init>(FileOutputStream.java:235)

at java.io.FileOutputStream.<init>(FileOutputStream.java:186)

at io.qameta.allure.kotlin.FileSystemResultsWriter.write(FileSystemResultsWriter.kt:46)

... 43 more

Caused by: android.system.ErrnoException: open failed: EACCES (Permission denied)

at libcore.io.Linux.open(Native Method)

at libcore.io.ForwardingOs.open(ForwardingOs.java:167)

at libcore.io.BlockGuardOs.open(BlockGuardOs.java:252)

at libcore.io.ForwardingOs.open(ForwardingOs.java:167)

at android.app.ActivityThread$AndroidOs.open(ActivityThread.java:7255)

at libcore.io.IoBridge.open(IoBridge.java:482)

... 46 more

And adb command doesn't help


adb shell appops set --uid package WRITE_EXTERNAL_STORAGE allow

adb shell appops set --uid package.debug.test WRITE_EXTERNAL_STORAGE allow

adb shell appops set --uid package.test WRITE_EXTERNAL_STORAGE allow



@anriijmind I don't know all details of what are you doing wrong, but with 2.2.4 version it is working right now ( we have only 29 and 30 sdk devices )

@anriijmind
Copy link

@SergKhram How can I change the directory for allure reports? I set in allure.properties path
allure.results.directory=data/user/0/my_package/allure-results

but it concatenates with default folder -> /storage/emulated/0/data/user/0/my_package/allure-results

Screenshot 2021-04-13 at 19 31 35

@SergKhram
Copy link
Contributor

debug PropertiesUtils - resultsDirectoryPath
If you see something different here (depends on your expectations) -> it signs that you make something wrong with you properties file

@anriijmind
Copy link

anriijmind commented Apr 16, 2021

@SergKhram I've figured out with permission for API 29-30 but in my mind, it better adds some information for documentation.

So before tests I always clear data with

testOptions {
        execution 'ANDROIDX_TEST_ORCHESTRATOR'
    }

and
testInstrumentationRunnerArguments clearPackageData: 'true'
and all permissions off-cause lose after the test is finished. So I disabled it, granted permeations manually via ADB and the result was - all tests passed.

Early I'd found example with granting permissions via @rule but when I tried it was not working because it needed allure adb-server off-cause which I had not started.

    @get:Rule
    val runtimePermissionRule: GrantPermissionRule = GrantPermissionRule.grant(
        Manifest.permission.WRITE_EXTERNAL_STORAGE,
        Manifest.permission.READ_EXTERNAL_STORAGE
    )

@SameerYoussef
Copy link

SameerYoussef commented Dec 8, 2021

    @get:Rule
    val runtimePermissionRule: GrantPermissionRule = GrantPermissionRule.grant(
        Manifest.permission.WRITE_EXTERNAL_STORAGE,
        Manifest.permission.READ_EXTERNAL_STORAGE
    )

This did it for me (Orchestration, API 29 emulator) - perhaps you should consider adding this to the README @viclovsky

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

6 participants