Ian Coetzee
Ian Coetzee

Reputation: 37

Cordova - Config.xml - resource-file directive not working

I have a backup.xml file located in my Cordova root directory. This file is used the regulate the auto-backup feature of Android6+ and is defined in my AndroidManifest.xml file as

android:fullBackupContent="@xml/backup"

in my config.xml file, I set up the file using the resource directive (Expecting it to copy the file to the target directory).

<resource-file src="backup.xml" target="platforms/android/app/src/main/res/xml/backup.xml" />

but my build fails with the following error.

  /work/Quasar_Projects/eSentry/src-cordova/platforms/android/app/build/intermediates/merged_manifests/release/AndroidManifest.xml:49: AAPT: error: resource xml/backup (aka za.co.securesa.esentry:xml/backup) not found.

  error: failed processing manifest.

Manually copying backup.xml from my project root to platforms/android/app/src/main/res/xml/backup.xml solves the issue and my build completes. I do however want to find the right way to copy my backup.xml from the root (Where it can be tracked by GIT) instead of using this copy "hack".

cordova --version - 9.0.0 ([email protected])

PS: I am trying to change the autobackup rules as suggested by the cordova.plugins.diagnostic plugin. from https://www.npmjs.com/package/cordova.plugins.diagnostic - To exclude this plugin's data, add the following rule to your XML backup rules: <exclude domain="sharedpref" path="Diagnostic.xml"/> but no further information as to how to do this is given by the documentation (So if I am on the wrong path, please correct me).

Upvotes: 0

Views: 1109

Answers (1)

leeroyc
leeroyc

Reputation: 41

I had a similar issue, after long debugging I found that the tag **only copies if the backup file is of a different size OR if the modification date of the source backup file is newer than the one in the target destination.

Checkout an excerpt from the code I found:

// Copy if the source has been modified since it was copied to the target, or if
// the file sizes are different. (The latter catches most cases in which something
// was done to the file after copying.) Comparison is >= rather than > to allow
// for timestamps lacking sub-second precision in some filesystems.
if (sourceStats.mtime.getTime() >= targetStats.mtime.getTime() ||
    sourceStats.size !== targetStats.size) {
  log('copy  ' + sourcePath + ' ' + targetPath + ' (updated file)');
  fs.copySync(sourceFullPath, targetFullPath);
  updated = true;
}

If your source backup file is the same size and older then you have to update the modification date. That can be done with a command like (on a mac)

touch -m backup.xml

And the you run cordova prepare and then the file should be copied.

I know it is not ideal and strange. The documentation also doesn't state such a requirement. So that is definitely that needs to be fixed. Oh by the way this already present in previous versions

Upvotes: 1

Related Questions