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.

[expo-media-library] getAssetsAsync causes the app to crash in Android (Expo Client and Standalone)

See original GitHub issue

🐛 Bug Report

Summary of Issue

Calling MediaLibrary.getAssetsAsync crashes the app on both Expo Client and standalone. There is no error logged and no indication of what could be causing the issue. This only happens in Android devices, works fine for iOS.

Environment - output of expo diagnostics & the platform(s) you’re targeting

  Expo CLI 3.28.2 environment info:
    System:
      OS: Linux 5.9 Manjaro Linux
      Shell: 5.0.18 - /bin/bash
    Binaries:
      Node: 12.18.1 - ~/.config/nvm/versions/node/v12.18.1/bin/node
      Yarn: 1.22.4 - ~/.config/nvm/versions/node/v12.18.1/bin/yarn
      npm: 6.14.5 - ~/.config/nvm/versions/node/v12.18.1/bin/npm
    npmGlobalPackages:
      expo-cli: 3.28.2
    Expo Workflow: managed

Expo SDK: 39
expo-media-library: 9.2.1

And the standalone app is running on a Pixel 4 with Android 11 (although this issue has been happening since Android 10).

Reproducible Demo

I created this snack with the code I’m currently using, however I cannot reproduce the same error in the snack for some reason.

Steps to Reproduce

        const params = {
            first: 59,
            mediaType: [
                MediaLibrary.MediaType.photo,
                MediaLibrary.MediaType.video,
            ],
            sortBy: [MediaLibrary.SortBy.modificationTime],
        };

        if (lastItemId) {
            params.after = lastItemId;
        }

        try {
            const library = await MediaLibrary.getAssetsAsync(params);

            if (library.totalCount) {
                if (lastItemId !== library.endCursor) {
                    setGallery([...gallery, ...library.assets]);
                    setLastItemId(library.endCursor);
                }
            }
        } catch(e) {
            Alert.alert(
                'Gallery failed', 'An error happened fetching the gallery'
            );

            Logger.error('Error fetching gallery', e);
        }

Nothing after const library = await MediaLibrary.getAssetsAsync(params) gets executed and the app suddenly crashes.

Expected Behavior vs Actual Behavior

This is similar to some previous issues that are currently closed (#9440, #10168, #10488) and this is still happening in SDK 39. I have tested this same code in a physical iPhone and an iPhone simulator, with and without images to load, and has never crashed. I’m not sure if it is the same bug from the above mentioned tickets that is still persisting in SDK 39 or if this is a new one.

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
maxipetruccicommented, Nov 23, 2020

Upgrade to SDK39 and MediaLibrary 9.2.1 (automatically if you upgrade via expo’s upgrade command) solves the problem.

0reactions
isotopeeecommented, Oct 20, 2021

UPDATE: as i rechecked in prod we used old version - “expo-media-library”: "^8.1.0, and with “expo-media-library”: "^9.2.1 there is no crash in Android 10, confirmed (in my case) @maxipetrucci was right 😃

Works on Android 11 as well. This thread saved my life. 🙏

Read more comments on GitHub >

github_iconTop Results From Across the Web

Expo MediaLibrary.getAssetsAsync() crashes the app on ...
getAssetsAsync () but my android crashes. Everything works on IOS. Note: when I add MediaLibrary.getAssetsAsync({ after: "" }) it does not crash ......
Read more >
Android standalone app crashes on start - Expo Forums
Open Android studio emulator or connect your device and make sure it's connected properly then run adb logcat from your terminal then run...
Read more >
CHANGELOG.md · 熊刚/Expo - Gitee.com
Changelog. This is the log of notable changes to the Expo client that are developer-facing. Package-specific changes not released in any SDK will...
Read more >
Expo app crashes when attempting to write a new record with ...
The app running in an Android emulator crashes when the code gets to these lines: ('Entry is the name of my schema)
Read more >
expo | Yarn - Package Manager
The expo package is a single package you can install in any React Native app to begin using Expo modules. includes core infrastructure...
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