Xamarin.Android: Adjusting legacy storage permissions for Android 13 deployments
29.4K reputation · 26 Sept 2021, 18:53 UTC
The primary objective is to guarantee that a Xamarin.Android application targeting API level 33 can successfully install and launch on Android 13 devices. The current build process preserves the legacy READ_EXTERNAL_STORAGE permission declared in the app’s manifest, yet Android 13 requires the new READ_MEDIA_IMAGES (and related media permissions) for media access. When the legacy permission is present, the OS rejects the request, causing launch failures or silent crashes, as evidenced by logcat entries such as Permission denied: android.permission.READ_MEDIA_IMAGES.
Constraints include the fact that Xamarin.Android 12.x does not automatically translate deprecated permission names, and no migration guide is published. Developers must decide whether to manually update the manifest or rely on a potential undocumented build flag. The unresolved decision is whether Xamarin should provide automatic mapping of legacy permissions to the new media permission set.
Questions for investigation:
- Does the current Xamarin.Android release automatically map
READ_EXTERNAL_STORAGEto the appropriate media permissions when targeting API level 33? - If automatic mapping is absent, what is the recommended workflow to update the manifest without breaking backward compatibility on lower API levels?
- Is there a build-time flag or configuration that can enable legacy-to-new permission mapping in future Xamarin.Android releases?
1 answer
1 question comment
Use comments to ask for clarification. Post a solution as an answer.
29,390 reputation · 26 Sept 2021, 22:36 UTC
To avoid maintaining multiple manifest files or complex Gradle flavors, a practical way to handle the transition is using the android:maxSdkVersion attribute. This allows you to keep both the legacy and granular permissions in a single manifest without causing conflicts on Android 13+ devices.
Example Manifest Configuration
<!-- For Android 12 and below -->
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" android:maxSdkVersion="32" />
<!-- For Android 13 and above -->
<uses-permission android:name="android.permission.READ_MEDIA_IMAGES" />
<uses-permission android:name="android.permission.READ_MEDIA_VIDEO" />
<uses-permission android:name="android.permission.READ_MEDIA_AUDIO" />
When targeting API 33 in Xamarin.Android, the OS will ignore the legacy permission on newer devices due to the maxSdkVersion limit, preventing the silent crashes mentioned. To verify the final result, check the merged manifest in the obj/Debug/ or obj/Release/ folder to ensure the attributes are preserved during the build process.