Home > front end >  edit config.xml to stop camera plugin duplication during build
edit config.xml to stop camera plugin duplication during build

Time:12-25

I'm developing an app with ionic and cordova. when i'm done building and i do ionic cordova prepare android and i go to android studio to deploy on the phone i get camera duplications in Androidmanifest.xml and i have to manually clean it up to allow a successful deployment.

Android.manifest after ionic cordova prepare android

<uses-feature android:name="android.hardware.camera" />
<uses-feature android:name="android.hardware.camera.autofocus" android:required="false" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.FLASHLIGHT" />
<uses-feature android:name="android.hardware.camera" android:required="false" />
<uses-feature android:name="android.hardware.camera" android:required="true" />

What i want to achieve is to configure the config.xml so that it doesn't happen that i'd always have to clean the camera duplicate in Androidmanifest.xml

after manually cleaning which makes it work

<uses-feature android:name="android.hardware.camera" />
<uses-feature android:name="android.hardware.camera.autofocus" android:required="false" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.FLASHLIGHT" />

I tried this in config.xml but it didn't work

<edit-config file="app/src/main/AndroidManifest.xml" mode="overwrite" target="/manifest/uses-feature[@android:name='android.hardware.camera']">
    <uses-feature android:name="android.hardware.camera" />
</edit-config>

CodePudding user response:

Try using cordova-custom-config.

ionic cordova plugin add cordova-custom-config

config.xml:

<platform name="android">
  ....
    <custom-preference delete="true" name="android-manifest/uses-feature[@android:name='android.hardware.camera']" />
 </platform>

Then remove and add your android platform:

 ionic cordova platform rm android
 ionic cordova platform add android@your_version

CodePudding user response:

I think the best way to solve this is to find out why those contradicting uses-feature's are added in the first place and remove them there.
I'd also try the solution SidiBecker suggested, because it is quite elegant.

However, if that doesn't work, you can remove code from your android manifest programatically with an after_prepare hook, the same way as I suggested in this answer: use config.xml to control how plugins are installed

  • Related