简体   繁体   English

挂钩失败,错误代码为ENOENT-如何将Android资源添加到配置xml而不是使用挂钩

[英]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. 当我尝试在Windows 7计算机上运行cordova仿真android时,在命令提示符下返回以下错误。

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) 我的系统信息如下(来自离子“ info”命令)

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. 注意Ionic已安装在我的机器上,但未用于该单个项目-我知道此错误与我的hooks目录有关,在after_prepare目录中只有一个钩子。

This file is called 'assets_copy.sh' and is a shell script with the following information. 该文件称为“ assets_copy.sh”,是具有以下信息的shell脚本。

#!/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? 该应用程序最初是由另一位用户在Mac上开发的-在Windows上运行时,如果删除了所有内容,便会删除asset_copy.sh文件,但由于其中包含图标,因此此信息是生成资源图标所必需的,允许使用的替代方法是什么我可以在config.xml中为图标和背景屏幕添加这些相同的Android资源吗?

Added the following to my config.xml file - note this has to be within the nodes. 在我的config.xml文件中添加了以下内容-注意这必须在节点内。 This will assign the icons & then the latter screens - this seems to work for me :) 这将分配图标,然后分配后面的屏幕-这似乎对我有用:)

eg 例如

<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>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM