Cordova hook file not found

Based on this, Hooks | VoltBuilder

I have this in my config:

<hook type="after_prepare" src="scripts/forcelightmode.js" />

But the build log states file not found:

Executing script found in config.xml for hook “after_prepare”:/scripts/forcelightmode.js
Script file does’t exist and will be skipped: /scripts/forcelightmode.js``

My file structure is:

MyProject.appstudio
|-cache
|-certificates
|-forms
|-icon-splash
|-images
|-modules
|-properties
|-scripts - forcelightmode.js
|-voltbuilder
|-.gitignore
|-MyProject.project

After adding “scripts” to the extraFiles in the Properties window (one file per line), I now get this error:

Executing script found in config.xml for hook "after_prepare": scripts/AndroidLightMode.js
Script file does't exist and will be skipped: /scripts/AndroidLightMode.js

Note I renamed the .js file and updated the config to match.

It’s probably a matter of getting the paths correct. I’m not sure what the proper pathname would be: the next thing I would try is

<hook type="after_prepare" src="./scripts/AndroidLightMode.js" />

If that doesn’t work, let me know and we’ll try some other combinations.

I’ve put that to the side for now and will return back to it at a later date.

Looking at the log snippets above, it seems to be adding the first “/”, = “/scripts/AndroidLightMode.js”, it should be “scripts/AndroidLightMode.js”, as set in the config.

Did that resolve the issue?

My config is,

<hook type="after_prepare" src="scripts/forcelightmode.js" />

but the logs report,

Script file does't exist and will be skipped: /scripts/AndroidLightMode.js

it seems the build process is adding the initial “/”, unless its just the logging adding that?

Just tried it here. I did the following:

  1. Added a scripts folder to the project directory.
  2. I put a file named AndroidLightMode.js into the scripts folder.
  3. I added one line to that file: console.log(“AndroidLightMode.js executed”);
  4. I added scripts/AndroidLightMode.js to extrafiles in Project Properties
  5. I added <hook type="after_prepare" src="www/scripts/AndroidLightMode.js" /> to the config.xml Voltbuilder project property.
  6. Submitted to voltbuilder. This is in the log:
    Prepared android project successfully
    Executing script found in config.xml for hook “after_prepare”: www/scripts/AndroidLightMode.js
    AndroidLightMode.js executed

The proper path starts with www: the first thing VoltBuilder does is copy all your files into a www folder.

That’s great thank you. I’m working on the iOS version now, I’ll give it a go soon.

The reason for needing to force lightmode on Android is because on Android I’ve found that long text in a Select option doesn’t text-wrap when shown in the dropdown, so I’ve had to make a custom one but I can’t match Androids dark mode colors as they vary per device, hence forcing light mode.