[resolved] Cordova resource-file directive

As part of using the BackgroundGeolocation plugin I need to move a resource-file into the cordova project.

I am using this directive, that I have appended to the config.xml file:

 <resource-file 
         src="BackgroundGeolocationHeadlessTask.java" 
         target="app/src/main/java/com/transistorsoft/cordova/bggeo/BackgroundGeolocationHeadlessTask.java" />

BackgroundGeolocationHeadlessTask.java is in my project root directory.

Here is some --verbose build output:

%% Updating resource files at platforms/android
=> Errors executing Cordova commands:

   While adding platform Android to Cordova project:
   Error: Source path does not exist:
   BackgroundGeolocationHeadlessTask.java
   at updatePathInternal
   (/Users/brucejo/mroot/app/.meteor/local/cordova-build/platforms/android/cordova/node_modules/cordova-common/src/FileUpdater.js:145:19)
   at
   /Users/brucejo/mroot/app/.meteor/local/cordova-build/platforms/android/cordova/node_modules/cordova-common/src/FileUpdater.js:223:19
   at Array.forEach (<anonymous>)
   at Object.updatePaths
   (/Users/brucejo/mroot/app/.meteor/local/cordova-build/platforms/android/cordova/node_modules/cordova-common/src/FileUpdater.js:221:33)
   at updateFileResources
   (/Users/brucejo/mroot/app/.meteor/local/cordova-build/platforms/android/cordova/lib/prepare.js:432:17)
   at
   /Users/brucejo/mroot/app/.meteor/local/cordova-build/platforms/android/cordova/lib/prepare.js:51:9
   at _fulfilled
   ...

I had this all working and then it suddenly stopped working…

  • I believe that the meteor build system had somehow copied BackgroundGeolocationHeadlessTask.java into the <buildRoot>/android/project folder, then I believe the directive took it from there.
  • Now the file is no longer getting copied into the android/project folder and is throwing the error.

Any and all help appreciated!!

D’oh! I found the way to make this work.

This pull request added a feature that loads resource files into the project and refers to them in the config.xml file for cordova. All good.

One caveat: it only works if the resources are placed in the root of the project. See 10684.

Is cordova-build-override folder not working in this case?

Thanks @rjdavid!
Yeah, I was spooked by the documentation:

The problem with this mechanism is that it overrides complete files, so it is not a good solution for customizing config.xml . Replacing the generated version with your own file means you lose all configuration information set by the build process and by installed plugins, which will likely break your app.

If you need to customize configuration files, a workaround is to create a dummy Cordova plugin. In its plugin.xml , you can specify a config-file element to selectively change parts of configuration files, including config.xml .

We recommend using these approaches only if absolutely required and if your customizations can not be handled by standard configuration options.

So I hunted down App.addResourceFile.

But now I realize that I was modifying config.xml to do the copy via a config-file directive. So I did not need the config-file directive in config.xml if I used cordova-build-override.

So I think either way works.