2

I'm working in an app with expo dev client to allow use native modules, right now I'm trying to implemente the package expo-media-library to save and get pictures taken with ImagePicker from expo, to the gallery.

Following the documentation, I installed the package with npx expo install expo-media-library, and import it with import * as MediaLibrary from 'expo-media-library'; but just for the import I got this error

enter image description here

I'm not even using it, just with the import the whole app crashes, and just removing the import everything works fine.

Console error message enter image description here

Lando Sotelo
  • 81
  • 1
  • 7

1 Answers1

0

I had the same issue, although i was using the package and i solved it by adding these permissions inside the app.config.js file

android: {
  permissions: [
    'READ_EXTERNAL_STORAGE',
    'WRITE_EXTERNAL_STORAGE',
    'ACCESS_MEDIA_LOCATION',
  ],
},

And adding these permissions inside the AndroidManifest.xml file

<uses-permission android:name="android.permission.ACCESS_MEDIA_LOCATION"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>

After file modification running the following commands gave me the build that had no errors.

yarn add expo-media-library
expo install expo-media-library
expo prebuild --clean
eas build profile --development --platform android
fran
  • 1
  • 1
  • 1
    My problem was that I was trying to use Expo Go instead of a dev client or build the project, and some points about what are you doing. 1. Once you add the permissions in app.config.js, isn't necessary to include them in AndroidManifest.xml, app.config.js take and includes those permissions automatically. 2. You're using prebuild to generate the android folders and eas build to generate a dev client (the --development flag). You can DELETE the android folders, avoid the expo prebuild and generate the dev client, then you download it, install it, and run expo start --dev-client – Lando Sotelo Mar 02 '23 at 15:33
  • With the dev-client you can now use native libraries like expo-media-library and others. Alternatively, you can just run the prebuild and then `expo run:android`, and the project will compile and automatically install and execute a dev-client in your emulator. If you want to test on your own smartphone, then YES, you need to generate the dev-client. Personally, I use an emulator with Android Studio, so I use `npx expo run:android`, once the feature is ready, I build an APK or Bundle with EAS. Hope it helps ;) – Lando Sotelo Mar 02 '23 at 15:38