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

Viewed 20267

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.

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

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>

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.

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