question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

On Android API 30, failing to open files

See original GitHub issue

When attempting to build and run on Android 30 emulators, I’m receiving multiple types of errors.

Build script configuration…

        buildToolsVersion = "30.0.3"
        minSdkVersion = 24
        compileSdkVersion = 30
        targetSdkVersion = 30
        playServicesVersion = "17.0.0"
        kotlinVersion = "1.3.72"

When running on an Android 29 emulator, files and docs open fine. When running on an Android 30 emulator, error displayed…

Opening an image…

File reference used file:///data/user/0/com.myapp/files/app/appcore/files/cloud/files/9/1237/temp778200586557997840rn_image_picker_lib_temp_5fed3c4d-0df1-4c4.jpg

Error: No app associated with this mime type
    at index.js:25
    at RCTDeviceEventEmitter.emit (EventEmitter.js:189)
    at MessageQueue.__callFunction (MessageQueue.js:436)
    at MessageQueue.js:111
    at MessageQueue.__guard (MessageQueue.js:384)
    at MessageQueue.callFunctionReturnFlushedQueue (MessageQueue.js:110)
    at debuggerWorker.js:69

File reference used… file:///data/user/0/com.myapp/files/app/appcore/files/cloud/files/9/1236/temp8153285029360235510IMG_20201228_150952.jpg

Error: Failed to find configured root that contains /
    at index.js:25
    at RCTDeviceEventEmitter.emit (EventEmitter.js:189)
    at MessageQueue.__callFunction (MessageQueue.js:436)
    at MessageQueue.js:111
    at MessageQueue.__guard (MessageQueue.js:384)
    at MessageQueue.callFunctionReturnFlushedQueue (MessageQueue.js:110)
    at debuggerWorker.js:69 

While investigating the code it seems to break on showStoreSuggestions returning {NativeMap:{}} resulting in the first error listed.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

23reactions
StuartCallancommented, Jan 26, 2021

So I did some more digging, and it appears that from Android 11 (API level 30) they have introduced stricter policy on what packages an app can view on the users device.

It is all explained on the developer documentation here.

All previous versions of Android allowed an app to query all installed packages so this is why we don’t see this issue on lower version. If you would like to mimic that functionality then you can add the QUERY_ALL_PACKAGES permission to your manifest.

It’s more likely that for this library we’d like to use the <queries> approach in the manifest, as we only want to view files. To do this we can add the following in the manifest:

<manifest package="com.example.app">
<queries>
    <intent>
        <action android:name="android.intent.action.VIEW" />
        <data android:mimeType="*/*" />
    </intent>
</queries>
...
</manifest>

If you’re using the queries approach and get an error during building, then you’ll probably need to update your version of gradle as mentioned here.

I’ve tested with the queries approach above and the library here is working for my use case of opening a pdf.

The longer term fix would be to add this fix to the Android manifest of this library. I may create a PR if I get around to it.

Hope this helps people!

1reaction
snicrocommented, Nov 9, 2021

I see the proposed change was merged on May 27th. If it works, could have a new release that includes it?

Read more comments on GitHub >

github_iconTop Results From Across the Web

requestLegacyExternalStorage is not working in Android 11
Android 11 (API 30+) requestLegacyExternalStorage=true does nothing and you can no longer "opt-out". It was available in Android 10 to give ...
Read more >
Troubleshoot known issues with Android Emulator
This page lists known issues, workarounds, and troubleshooting tips for the Android Emulator. If you encounter an issue not listed here or ...
Read more >
Known issues with Android Studio and Android Gradle Plugin
Known Issues with Android Studio · Frozen keyboard input - "iBus" problems on Linux · Gradle Sync Failed: Broken Pipe · "peer not...
Read more >
Storage updates in Android 11 - Android Developers
Android 9 (API level 28) started to restrict which apps could make the files in their data directories on internal storage world-accessible to...
Read more >
Access media files from shared storage | Android Developers
The recordings directory isn't available on Android 11 (API level 30) and ... It's recommended, however, that you use the MediaStore APIs to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found