In my flutter project I am getting exception whenever I am trying to pickup an image either from Camera or Gallery using the image_picker
plugin of flutter.
For the very first time it asks for the permission and when I allow the camera it throws
java.lang.NullPointerException: Attempt to invoke virtual method 'android.content.res.XmlResourceParser android.content.pm.ProviderInfo.loadXmlMetaData(android.content.pm.PackageManager, java.lang.String)' on a null object reference
After that, it throws an exception for every subsequent tries
PlatformException(already_active, Image picker is already active, null)
If I try to choose the camera or gallery even after restarting the app.
var imageSource;
if (source == CAMERA_SOURCE) {
imageSource = ImageSource.camera;
} else {
imageSource = ImageSource.gallery;
}
try {
final file = await ImagePicker.pickImage(source: imageSource);
if (file == null) {
throw Exception('File is not available');
}
Below are the dependencies:
cupertino_icons: ^0.1.2
firebase_auth: ^0.8.1
cloud_firestore: ^0.9.0+1
firebase_core: ^0.3.0+1
firebase_messaging: ^3.0.1
firebase_storage: ^2.0.1
intl_translation: ^0.17.3
http: ^0.12.0+1
xml: ^3.3.1
uuid: ^2.0.0
shared_preferences: ^0.5.1+1
flutter_staggered_grid_view: ^0.2.7
google_sign_in: ^4.0.1
flutter_signin_button: ^0.2.5
image_picker: ^0.5.0+2
mlkit: ^0.9.0
path_provider: ^0.5.0+1
Thanks for your time! I also tried to upgrade my flutter to the latest version.
Anyway, I have the same issue when using Image Picker.
I have solved the trouble, it needs to provide permission to access the camera and storage memory on the release mode.
On Android:
Add lines on file src/main/AndroidManifest.xml
: inside the manifest tag
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
On IOS:
Add lines on file Info.plist
:
<key>NSPhotoLibraryUsageDescription</key>
<string>Allow access to photo library</string>
<key>NSCameraUsageDescription</key>
<string>Allow access to camera to capture photos</string>
Good luck, hope it will be useful!
If you have channel based code i.e bridge between Native Android and Flutter.. In MainActivity on Activity Result .. try adding ..
super.onActivityResult(requestCode, resultCode, data)
Finally I was able to resolve it.
I updated all my dependencies and flutter SDK and then I did Flutter clean and it started working..
Thanks all for your time and help
Change in android/build.gradle classpath 'com.android.tools.build:gradle:3.5.4'
This worked for me.
I updated package from 0.5.4+3
to ^0.6.5+2
and that solved my problem.
If you read the changelog, you will see every issue fixes: https://pub.dev/packages/image_picker#-changelog-tab-
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With