Sub topic 2
Configuring Android and iOS
This chapter assumes you can add a package to pubspec.yaml, and that you know where the android/ and ios/ folders sit in a Flutter project. Both plugins call native platform APIs, so a correct Dart call can still fail if the native project is not set up. Most "the camera does nothing" and "the app crashed when I tapped the button" reports come from missing configuration, not from Dart code.
What each plugin needs
image_picker hands the work to the system gallery or camera app. The operating system shows its own screens, so your app needs very little. The camera plugin opens the camera hardware inside your own app, so the OS requires explicit permission declarations and runtime consent.
| Requirement | image_picker (gallery) | image_picker (camera source) | camera plugin |
|---|---|---|---|
| iOS `NSPhotoLibraryUsageDescription` | Recommended, needed on older iOS versions | Not needed | Not needed |
| iOS `NSCameraUsageDescription` | Not needed | Required | Required |
| iOS `NSMicrophoneUsageDescription` | Not needed | Only for video | Required when audio is enabled |
| Android manifest entries | None | None, unless you declare `CAMERA` yourself | `CAMERA`, plus `RECORD_AUDIO` for audio |
| Android runtime permission prompt | None | None, unless you declared `CAMERA` | Requested when you initialize the controller |
| Raised minimum OS version | Rarely | Rarely | Yes, check the README |
The exact rules change between plugin versions. Treat the README of the version you install as the final authority.
Adding the packages
Add the packages from the project root. This writes the current versions into pubspec.yaml and fetches them.
flutter pub add image_picker cameraThe resulting dependencies look like this. The version numbers will differ on your machine.
dependencies:
flutter:
sdk: flutter
image_picker: ^1.1.2
camera: ^0.11.0Install only the plugin you use. A gallery-only feature does not need camera, and leaving it out avoids the extra permissions and the higher minimum SDK.
Configuring iOS
iOS refuses to show any permission prompt unless Info.plist contains a usage description for that resource. The description is the text the user reads in the system dialog. If the key is missing when your app touches the resource, iOS terminates the app.
Open ios/Runner/Info.plist and add the keys inside the top-level <dict>:
<!-- ios/Runner/Info.plist -->
<key>NSCameraUsageDescription</key>
<string>This app uses the camera to take photos.</string>
<key>NSPhotoLibraryUsageDescription</key>
<string>This app lets you choose photos from your library.</string>
<key>NSMicrophoneUsageDescription</key>
<string>This app records audio with video.</string>Each key covers one resource:
NSCameraUsageDescriptionis needed by thecameraplugin, and byimage_pickerwhen you useImageSource.camera.NSPhotoLibraryUsageDescriptionis needed on older iOS versions. On iOS 14 and later,image_pickeruses the system photo picker, which runs outside your app and does not require library permission. Keeping the key is still a safe default.NSMicrophoneUsageDescriptionis needed whenever audio is captured. Thecameraplugin enables audio by default, and its README asks for this key.
Write descriptions that say why your app needs access. Vague text such as "needs camera" can get an app rejected in App Store review.
Podfile and simulator limits
Open ios/Podfile and check the platform line near the top. It must be at least the iOS version the plugin README requires:
platform :ios, '13.0'If it is lower than a plugin requires, pod install fails with a deployment target error. After raising it, run flutter clean and build again.
The iOS simulator has no camera. availableCameras() returns an empty list there, and ImageSource.camera cannot produce a photo. The gallery works in the simulator, but you need a physical iPhone to test anything that uses the camera.
Configuring Android
For gallery picking with image_picker, Android needs no manifest changes. On Android 13 and later the plugin uses the system photo picker, which grants access to only the files the user selects.
The camera plugin needs the camera permission, and audio recording needs the microphone permission. The plugin requests them at runtime when you initialize a controller. Declaring them in your own manifest makes the requirement visible and keeps the build predictable:
<!-- android/app/src/main/AndroidManifest.xml -->
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-feature
android:name="android.hardware.camera"
android:required="false" />
<application
android:label="my_app"
android:icon="@mipmap/ic_launcher">
<!-- activity entries stay as generated -->
</application>
</manifest>The uses-permission lines go directly under <manifest>, before <application>. The uses-feature line with required="false" matters for distribution. Google Play hides apps from devices that lack a declared required feature. Without required="false", a tablet with no camera could not install your app, even though camera use is optional.
Minimum SDK
The camera plugin on Android needs a minimum SDK of 21 or higher. Check the defaultConfig block in android/app/build.gradle or build.gradle.kts:
// android/app/build.gradle.kts
android {
defaultConfig {
minSdk = 21
}
}Many Flutter templates set minSdk = flutter.minSdkVersion. That value is usually enough, so change it only if the build reports a conflict with the plugin.
Applying and checking the changes
Native files are compiled into the app, so hot reload and hot restart do not pick up edits to Info.plist, AndroidManifest.xml, or Gradle files. Stop the app and run it again with a full build. If a change seems to be ignored, run flutter clean followed by flutter pub get, then rebuild.
Common configuration errors
| Symptom | Likely cause | Fix |
|---|---|---|
| iOS app closes the moment the camera opens | Missing `NSCameraUsageDescription` or `NSMicrophoneUsageDescription` | Add the key and rebuild fully |
| `availableCameras()` returns an empty list on iOS | Running on the simulator | Use a physical device |
| No permission prompt appears, and access stays denied | The user denied it earlier | On iOS, change it in Settings. On Android, clear app permissions or reinstall |
| Gradle error mentioning `minSdkVersion` | Plugin needs a higher minimum SDK | Raise `minSdk` in the app Gradle file |
| `pod install` fails with a deployment target error | Podfile platform is too low | Raise `platform :ios` and run `flutter clean` |
| Camera launch fails on Android with a security error | `CAMERA` declared but not granted | Request the permission first, or remove the declaration |
| Edit to the manifest or plist has no effect | Hot reload was used | Stop and rebuild the app |
Exercise
Your app lets users choose a profile picture only from the gallery, using image_picker. A teammate adds the camera plugin "just in case", declares CAMERA in the Android manifest, and adds all three iOS usage keys. Which of these changes are unnecessary, and which new risk did they add?
Show answer
The camera plugin, the CAMERA declaration, the microphone key, and the camera key are all unnecessary for gallery-only picking. The photo library key is optional on iOS 14 and later. The new risks are a higher minimum SDK and iOS version from the camera plugin, extra permissions shown to users and reviewers, and the Android rule that a declared CAMERA permission must be granted before an image_picker camera launch. For a gallery-only feature, remove the camera plugin and the extra declarations.
Exercise
You added NSCameraUsageDescription to Info.plist while the app was running, pressed hot reload, and the app still crashes when opening the camera. Why, and what should you do?
Show answer
Info.plist is bundled into the app at build time, and hot reload only updates Dart code. Stop the app and run it again with a full build, and use flutter clean first if the crash continues.