Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add android:allowBackup="false" via cordova plugin

I am now developing a Cordova Plugin, I wanna add

  android:allowBackup="true"

into AndroidManifest.xml, but I do not know how to specify it in plugin.xml.

like image 384
poordeveloper Avatar asked May 29 '15 10:05

poordeveloper


3 Answers

The configuration edit that has worked for me was:

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

EDIT Feb-2020: Please refer to answer from @Shashank Agrawal below for cordova-android >= 7

like image 24
Muhammad Omar ElShourbagy Avatar answered Oct 22 '22 08:10

Muhammad Omar ElShourbagy


Answer shared by @Muhammad Omar works for cordova-android < 7. But things changed for cordova-android >= 7

https://cordova.apache.org/announcements/2017/12/04/cordova-android-7.0.0.html

So you need to change it a bit for

cordova-android >= 7

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

cordova-android < 7

The configuration edit that has worked for me was:

<platform name="android">
    <edit-config file="AndroidManifest.xml" target="/manifest/application" mode="merge">
        <application android:allowBackup="false"/>
    </edit-config>
</platform>
like image 59
Shashank Agrawal Avatar answered Oct 22 '22 10:10

Shashank Agrawal


To avoid android app from restoring backup on install, following config added to config.xml.

Ensure xml namespace is defined. Cordova build failed without this for me.

Solved by adding below.

<platform name="android">
    <edit-config file="AndroidManifest.xml" mode="merge" target="/manifest/application" xmlns:android="http://schemas.android.com/apk/res/android">
        <application android:allowBackup="false" />
    </edit-config>
</platform>
like image 10
Venkat Kotra Avatar answered Oct 22 '22 08:10

Venkat Kotra