Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android full backup: "file.xml is not in an included path"

I've created backup rules file just like in example https://developer.android.com/guide/topics/data/autobackup:

<?xml version="1.0" encoding="utf-8"?>
<full-backup-content xmlns:android="http://schemas.android.com/apk/res/android">
    <include
        domain="sharedpref"
        path="." />
    <exclude
        domain="sharedpref"
        path="nonceStorage.xml" />
    <exclude
        domain="sharedpref"
        path="localStorage.xml" />
</full-backup-content>

and Android Studio say's that there are errors:

Error:(8, 15) `nonceStorage.xml` is not in an included path [FullBackupContent]
Error:(11, 15) `localStorage.xml` is not in an included path [FullBackupContent]

Error message is totally uninformative and not googleable (almost all words are very short). Can anyone explain,what does this *** want from me? How to fix this issue?

like image 328
babay Avatar asked Aug 05 '18 01:08

babay


2 Answers

This is definitely a bug in Android Studio, but here is a very reasonable workaround.

You need to add the following tools:ignore XML attribute to clear the errors.

<include domain="sharedpref" path="."/>
<exclude domain="sharedpref" path="nonceStorage.xml"
    tools:ignore="FullBackupContent" />
<exclude domain="sharedpref" path="localStorage.xml"
    tools:ignore="FullBackupContent" />

I've verified this results in the expected shared preferences. In other words, the XML is correct and the lint check is wrong.

When generating debug APKs, these attributes are not necessary (the build completes regardless), but they are necessary for when you do Android Studio's Generate Signed Bundle / APK, otherwise the build fails with those errors.

The other answer saying you can just remove <include domain="sharedpref" path="."/> is incorrect. This will result in none of the shared preferences being included.

The bug has been raised here.

like image 62
Mark Avatar answered Sep 18 '22 07:09

Mark


I guess this is an IDE bug because the example from doc:

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

shows the same error on device.xml.

Removing the <include> clears the error if you simply want to exclude some files because the doc says

By default, Auto Backup includes almost all app files.

like image 31
Dewey Reed Avatar answered Sep 21 '22 07:09

Dewey Reed