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.
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" />
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
<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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With