Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

edit-config is not working in config.xml in cordova

I am working on an Ionic app and i want to add android@autoBackup="false" in AndroidManifest.xml file through config.xml. As per the cordova documentation, cordova version 6.4 supports edit-config tag in config.xml through which i can achieve this similar to plugin.xml.

This is what i have written in config.xml file.

<platform name="android">
  <edit-config file="AndroidManifest.xml" target="/manifest/application" mode="merge">
    <application android:autoBackup="false" />
  </edit-config>
  <icon src="resources/android/icon/drawable-ldpi-icon.png" density="ldpi"/>
  <icon src="resources/android/icon/drawable-mdpi-icon.png" density="mdpi"/>
  <splash src="resources/android/splash/drawable-port-ldpi-screen.png" density="port-ldpi"/>
  <splash src="resources/android/splash/drawable-port-mdpi-screen.png" density="port-mdpi"/>
  <splash src="resources/android/splash/drawable-port-xxxhdpi-screen.png" density="port-xxxhdpi"/>
</platform>

And it changes my AndroidManifest.xml file like this

<application android:autoBackup="false" android:hardwareAccelerated="true" android:icon="@drawable/icon" android:label="@string/app_name" android:supportsRtl="true">
  <activity android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale" android:label="@string/activity_name" android:launchMode="singleTop" android:name="MainActivity" android:screenOrientation="portrait" android:theme="@android:style/Theme.Black.NoTitleBar" android:windowSoftInputMode="adjustResize">
    <intent-filter android:label="@string/launcher_name">
      <action android:name="android.intent.action.MAIN" />
      <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
  </activity>
  <application android:autoBackup="false" />
  <activity android:exported="true" android:launchMode="singleTop" android:name="com.gae.scaffolder.plugin.FCMPluginActivity">
    <intent-filter>
      <action android:name="FCM_PLUGIN_ACTIVITY" />
      <category android:name="android.intent.category.DEFAULT" />
    </intent-filter>
  </activity>
  <service android:name="com.gae.scaffolder.plugin.MyFirebaseMessagingService">
    <intent-filter>
      <action android:name="com.google.firebase.MESSAGING_EVENT" />
    </intent-filter>
  </service>
  <service android:name="com.gae.scaffolder.plugin.MyFirebaseInstanceIDService">
    <intent-filter>
      <action android:name="com.google.firebase.INSTANCE_ID_EVENT" />
    </intent-filter>
  </service>
</application>

In above code of AndroidManifest.xml, you can easily find application tag has been updated with android@autoBackup="false" but also added application tag as child of first one with autoBackup attribute. I don't want application tag as child tag, i tried a lot but couldn't find the root cause of this issue. Can anyone suggest me what am i doing wrong here? Thanks in advance.

like image 840
kulbhushan rajput Avatar asked Aug 07 '17 19:08

kulbhushan rajput


3 Answers

Try changing the "target" property of the edit-config tag like this:

<edit-config file="AndroidManifest.xml" target="application" mode="merge">

This tells cordova you want to modify a node named "application". See XPath for more details on XPath selectors.

If this should not work out for you can have a look at cordova-plugin-custom-config. With this plugin you can simply add a preference tag to the android section of config.xml like this:

<preference name="android-manifest/@android:allowBackup" value="false" />
like image 167
David Avatar answered Oct 18 '22 03:10

David


In my case I needed to add this to the widget tag: xmlns:android="http://schemas.android.com/apk/res/android"

Fix thanks to https://github.com/dpa99c/cordova-custom-config/issues/24#issuecomment-172981002

like image 40
Scott Avatar answered Oct 18 '22 03:10

Scott


<edit-config file="app/src/main/AndroidManifest.xml" mode="merge" target="/manifest/application">
    <application android:allowBackup="false" />
</edit-config>

Try this one which works for me.

like image 32
bestoak Avatar answered Oct 18 '22 01:10

bestoak