What is the correct way to exclude a selected preference file from full backup? I'm getting "is not in an included path" warning

You are getting this error because the path you are excluding is outside the path that is included in the backup. If you specify any custom include, then ONLY those things will be backed up:

<include> - Specifies a file or folder to backup. By default, Auto Backup includes almost all app files. If you specify an element, the system no longer includes any files by default and backs up only the files specified. To include multiple files, use multiple elements.

Documentation here.

In your case, the exclude at com.yocto.wenote.backup.Backuper.xml is not on the include path com.yocto.wenote_preferences.xml - hence the error.

If you examine the code of the lint rule that generates the error message, it will confirm that because your exclude path does not have the prefix of any include, you will fall through to the !hasPrefix case.

Relevant portion here:

    for (String includePath : included) {
        if (excludePath.startsWith(includePath)) {
            if (excludePath.equals(includePath)) {
                Attr pathNode = exclude.getAttributeNode(ATTR_PATH);
                assert pathNode != null;
                Location location = context.getValueLocation(pathNode);
                // Find corresponding include path so we can link to it in the
                // chained location list
                for (Element include : includes) {
                    Attr includePathNode = include.getAttributeNode(ATTR_PATH);
                    String includeDomain = include.getAttribute(ATTR_DOMAIN);
                    if (includePathNode != null
                        && excludePath.equals(includePathNode.getValue())
                        && domain.equals(includeDomain)) {
                        Location earlier = context.getLocation(includePathNode);
                        earlier.setMessage("Unnecessary/conflicting <include>");
                        location.setSecondary(earlier);
                    }
                }
                context.report(ISSUE, exclude, location,
                               String.format("Include `%1$s` is also excluded", excludePath));
            }
            hasPrefix = true;
            break;
        }
    }
    if (!hasPrefix) {
        Attr pathNode = exclude.getAttributeNode(ATTR_PATH);
        assert pathNode != null;
        context.report(ISSUE, exclude, context.getValueLocation(pathNode),
                       String.format("`%1$s` is not in an included path", excludePath));
    }

Full code listing

So, in your case, you do not need to exclude that file at all, as ONLY com.yocto.wenote_preferences.xml is included in your backup.

You can also turn on verbose logging for the backup transport and XML parsing so that you can see what's happening:

adb shell setprop log.tag.GmsBackupTransport VERBOSE
adb shell setprop log.tag.BackupXmlParserLogging VERBOSE

Tags:

Android