Should full backup content xml file be empty or not added at all to include all?

Viewed 28554

So I was adding some stuff to my application manifest and I saw that I had a warning on my application tag:

On SDK version 23 and up, your app data will be automatically backed up and restored on app install. Consider adding the attribute android:fullBackupContent to specify an @xml resource which configures which files to backup.

And then I searched up for that. Apparently there are only 2 tags for that: <include> and <exclude>. I don't want to exclude any files from the backup as I don't have any local-depending files, and I don't need any <include> tags as

<include>: Specifies a set of resources to back up, instead of having the system back up all data in your app by default.

When I saw that if I don't put any <include> tags, then the system will back up all data in your app by default, which is exactly what I want.

Now I have this question: should I add the backup_content.xml file, but empty as the default settings are good, or not add the file at all? (in which case Android Studio will complain)

8 Answers

Correct solution:

The warning is because is missing <full-backup-content> resource.

For this we have android:fullBackupContent in the application tag, which points to a XML file that contains full backup rules for Auto Backup. These rules determine what files get backed up.

Example:

<application ...
    android:fullBackupContent="@xml/my_backup_rules">
</application>

Create an XML file called my_backup_rules.xml in the res/xml/ directory. Inside the file, add rules with the <include> and <exclude> elements. The following sample backs up all shared preferences except device.xml:

<?xml version="1.0" encoding="utf-8"?>
<full-backup-content>
    <include domain="sharedpref" path="."/>
    <exclude domain="sharedpref" path="device.xml"/>
</full-backup-content>

References for more information:

https://developer.android.com/guide/topics/data/autobackup https://betterprogramming.pub/androids-attribute-android-allowbackup-demystified-114b88087e3b

I also struggled the same question and couldn't find an answer. So for backup all, I tried making a backup.xml file like that:

<?xml version="1.0" encoding="utf-8"?>
   <full-backup-content>

   </full-backup-content>

and it works fine.

EDIT 06/04/21

Just got an official answer from Google IssueTracker:

The answer to your question appears at the beginning of the section titled Include and exclude files: "By default, the system backs up almost all app data". In order to back up all supported data, don't include android:fullBackupContent in your manifest file.

<application
        android:allowBackup="true"
        android:fullBackupOnly="true">
</application>
Related