apache / cordova-plugin-camera

Apache Cordova Plugin camera
https://cordova.apache.org/
Apache License 2.0
960 stars 1.52k forks source link

Error occurs with WRITE_EXTERNAL_STORAGE permission when installing alongside other plugins that utilize this permission. #879

Closed GusLAN closed 3 months ago

GusLAN commented 3 months ago

Bug Report

Problem

What is expected to happen?

Compile on Android without issues when other plugins use the WRITE_EXTERNAL_STORAGE permission, for example cordova-plugin-camera-preview.

What does actually happen?

In version 7.0.0 of cordova-plugin-camera, this permission is included as follows:

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" android:maxSdkVersion="32" /> This leads to duplication in the AndroidManifest.xml due to android:maxSdkVersion="32".

Information

Captura de pantalla 2024-01-19 a las 11 35 56

Environment, Platform, Device

Android

Version information

Cordova CLI : 12.0.0 (cordova-lib@12.0.1) Cordova Platforms : android 12.0.1

Ionic CLI: 7.2.0 Ionic Framework: @ionic/angular 7.6.5 @angular-devkit/build-angular: 16.2.2 @angular-devkit/schematics: 16.2.2 @angular/cli: 16.2.2

cordova-plugin-camera-preview: 0.12.3 cordova-plugin-camera: 7.0.0

Checklist

JacoboSegovia commented 3 months ago

Same issue in my project, following this thread

jomarti commented 3 months ago

Same problem in one of my projects.

wifisher commented 3 months ago

Please see: https://github.com/apache/cordova-plugin-camera/issues/854

breautek commented 3 months ago

Conflicts will inevitably occur if you have 2 plugins defining the same permission (or any other directive) with different settings.

You can use https://gist.github.com/breautek/bd157b8598f9a816f2ec0d45e3d932c8 as a after_prepare hook which will correct the manifest by stripping out the duplicates. It looks for specific pattern so if you have multiples you may need to add to it or modify it.

The rationale of this plugin including maxSdkVersion=32 is because the permission is completely obsolete in API 331, so this omits the permission from the final manifest that is built in the APKs distributed to API 33+ devices.

1The permission was actually obsolete in API 29 with scoped storage, providing no extra behaviour. However, requesting that permission still implicitly granted the READ_EXTERNAL_STORAGE which until API 33 where both read and write permissions are now obsolete. Cordova relied on this behaviour up to API 32 devices.

Closing this issue because it's not a bug with the camera plugin, it's more of a problem with the edit-config/config-file system which is already known that it needs some work. The gist above should be sufficient as a workaround.