'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.



Solution 1:[1]

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" />

Solution 2:[2]

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

Solution 3:[3]

<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.

Solution 4:[4]

for me this works:

<platform name="android">
    <preference name="android-targetSdkVersion" value="26" />
    <preference name="android-minSdkVersion" value="26" />
    <allow-intent href="market:*" />
    <preference name="ShowTitle" value="false" />
    <preference name="BackgroundColor" value="0xff2d2e2d" />
    <edit-config target="AndroidManifest.xml" parent="/manifest/application" mode="merge">
         <application android:theme="@android:style/Theme.NoTitleBar" >
         </application>
    </edit-config>
</platform>

Solution 5:[5]

The conflicting plugin, undefined, already modified the same attributes

This is a definite bug in Cordova and error stating undefined isn't helping. In my case only one plugin was using edit-config, I cleaned up android platform, emptied plugins folder, inside package.json moved the offending plugin to top of the cordova.plugins section. This made cordova add that offending plugin before all others.

Doing this did fix the issue but on top of that it should help you identify if you have second offender in that list.

Solution 6:[6]

I solved a similiar problem by installing the cordova-custom-config plugin and adding a custom-preference entry in the config.xml to change contents of the AndroidManifest.xml.

Example:

[...]
<platform name="android">
  [...]
  <custom-preference name="android-manifest/application/@android:label" value="MyAppName"/>
</platform>

Solution 7:[7]

In package.json,

change this

    "lint": "eslint .",

to this

    "lint": "eslint",

Solution 8:[8]

I found the solution on this page.

Essentially

Arrow functions are an ES6 feature, but here you have an async arrow function.

Async functions in general are an ES8 (or 2017) feature. Therefore you need to specify the following setting at the root of your config: parserOptions: { ecmaVersion: 8 // or 2017 }

So I needed to update my .eslintrc.js file to this

module.exports = {
  root: true,
  env: {
    es6: true,
    node: true
  },
  parserOptions: {
    ecmaVersion: 8
  },
  extends: ['eslint:recommended', 'google'],
  rules: {
    'comma-dangle': 'off',
    'quote-props': 'off',
    indent: ['error', 2]
  }
};

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 David
Solution 2 10 Rep
Solution 3 bestoak
Solution 4 Miguel
Solution 5 Nitin...
Solution 6 dreiekk
Solution 7 Mahi
Solution 8 magician11