Search code examples
androidcordovacordova-cli

Hook failed with error code ENOENT - How to add Android resources to config xml rather than using hooks


When I attempt run cordova emulate android on my Windows 7 machine the following error is returned in my command prompt.

Error: Hook failed with error code ENOENT: C:\wwwroot\stk\stk_ks3\app\hooks\after_prepare\assets_copy.sh
at C:\Users\Zab\AppData\Roaming\npm\node_modules\cordova\node_modules\cordova-lib\src\hooks\HooksRunner.js:195:23
at _rejected (C:\Users\Zab\AppData\Roaming\npm\node_modules\cordova\node_modules\q\q.js:797:24)
at C:\Users\Zab\AppData\Roaming\npm\node_modules\cordova\node_modules\q\q.js:823:30
at Promise.when (C:\Users\Zab\AppData\Roaming\npm\node_modules\cordova\node_modules\q\q.js:1035:31)
at Promise.promise.promiseDispatch (C:\Users\Zab\AppData\Roaming\npm\node_modules\cordova\node_modules\q\q.js:741
1)
at C:\Users\Zab\AppData\Roaming\npm\node_modules\cordova\node_modules\q\q.js:557:44
at flush (C:\Users\Zab\AppData\Roaming\npm\node_modules\cordova\node_modules\q\q.js:108:17)
at process._tickCallback (node.js:355:11)
at Function.Module.runMain (module.js:503:11)
at startup (node.js:129:16)

My system info is as follows (from the Ionic 'info' command)

Your system information:

Cordova CLI: 5.0.0
Ionic CLI Version: 1.4.5
Ionic App Lib Version: 0.0.22
OS: Windows 7 SP1
Node Version: v0.12.2

Note Ionic is installed on my machine but not in use for this individual project - I know this error is related to my hooks directory, this has a single hook within the after_prepare directory.

This file is called 'assets_copy.sh' and is a shell script with the following information.

#!/bin/bash

#iOS assets copy
ios="./platforms/ios"
if [ -d  "$ios" ] 
then
  cp -Rf ./www/res/icons/ios/* ./platforms/ios/'Stk'/Resources/icons
  cp -Rf ./www/res/screens/ios/* ./platforms/ios/'Stk'/Resources/splash
fi

#Android assets copy
 android="./platforms/android"
if [ -d "$android" ] 
then

  cp -Rf ./www/res/icons/android/icon.png ./platforms/android/res/drawable/icon.png
  cp -Rf ./www/res/screens/android/screen-portrait.png ./platforms/android/res/drawable/screen.png

  cp -Rf ./www/res/icons/android/hdpi-icon.png ./platforms/android/res/drawable-hdpi/icon.png
  cp -Rf ./www/res/screens/android/hdpi-screen-portrait.png ./platforms/android/res/drawable-hdpi/screen.png

  cp -Rf ./www/res/icons/android/ldpi-icon.png ./platforms/android/res/drawable-ldpi/icon.png
  cp -Rf ./www/res/screens/android/ldpi-screen-portrait.png ./platforms/android/res/drawable-ldpi/screen.png

  cp -Rf ./www/res/icons/android/mdpi-icon.png ./platforms/android/res/drawable-mdpi/icon.png
  cp -Rf ./www/res/screens/android/mdpi-screen-portrait.png ./platforms/android/res/drawable-mdpi/screen.png

  cp -Rf ./www/res/icons/android/xhdpi-icon.png ./platforms/android/res/drawable-xhdpi/icon.png
  cp -Rf ./www/res/screens/android/xhdpi-screen-portrait.png ./platforms/android/res/drawable-xhdpi/screen.png

fi

The app was originally developed by another user on a Mac - when running on Windows if I remove the assets_copy.sh file everything builds, but as this contains the icons this info is needed to generate the resource icons, what is the alternative method to allow me to add these same Android resources within my config.xml for icons & background screens?


Solution

  • Added the following to my config.xml file - note this has to be within the nodes. This will assign the icons & then the latter screens - this seems to work for me :)

    e.g

    <widget>
     <platform name="android">
       <icon src="www/res/icons/android/icon.png" />
       <icon src="www/res/icons/android/ldpi-icon.png" density="ldpi" />
       <icon src="www/res/icons/android/mdpi-icon.png" density="mdpi" />
       <icon src="www/res/icons/android/hdpi-icon.png" density="hdpi" />
       <icon src="www/res/icons/android/xhdpi-icon.png" density="xhdpi" />
    
       <!-- you can use any density that exists in the Android project -->
       <splash src="www/res/screens/android/screen-portrait.png" />    
       <splash src="www/res/screens/android/hdpi-screen-portrait.png" density="port-hdpi" />
       <splash src="www/res/screens/android/ldpi-screen-portrait.png" density="port-ldpi" />
       <splash src="www/res/screens/android/mdpi-screen-portrait.png" density="port-mdpi" />
       <splash src="www/res/screens/android/xhdpi-screen-portrait.png" density="port-xhdpi" />
     </platform>
    </widget>