【问题标题】:Unable to 'ionic cordova build' No scripts found for hook "after_compile" and "after_build"Unable to 'ionic cordova build' 没有找到钩子“after_compile”和“after_build”的脚本
【发布时间】:2021-01-17 18:38:44
【问题描述】:

无法让ionic cordova build android 工作。

信息:

  • ubuntu 20..,
  • 节点 10,离子 5,
  • 局部角度 8,
  • 5 级,
  • android sdk 28、30。
  • 所有变量都被导出...据我所知

FIRST: 在 npm install 和 global ionic、cordova 和 angular install 之后,我运行命令 ionic cordova build android。我在输出中收到此错误:

...
      ember-cli:testing cli: command.validateAndRun +1ms
    The specified command run is invalid. For available options, see `ng help`.
    [ERROR] An error occurred while running subprocess ng.
            
            ng run app:ionic-cordova-build --platform=android exited with exit code 1.
            

SECOND : 运行 ng run app:ionic-cordova-build --platform=android 时解决没有错误,即使它在运行 'ionic cordova build android' 时“以退出代码 1 退出”

第三次: 运行 ng run app:ionic-cordova-build --platform=android 后,我运行 ionic cordova build android 并得到了这个结果,但构建文件夹中没有 apk:

    ...
BUILD SUCCESSFUL in 23s
42 actionable tasks: 42 executed
Command finished with error code 0: /home/art/Documents/obc/platforms/android/gradlew cdvBuildDebug,-b,/home/art/Documents/obc/platforms/android/build.gradle
Built the following apk(s): 
        /home/art/Documents/obc/platforms/android/app/build/outputs/apk/debug/app-debug.apk
No scripts found for hook "after_compile".
No scripts found for hook "after_build".
art@pop-os:~/Documents/obc$ 

在运行ionic cordova build android 之前我是否遗漏了一些步骤?

有没有办法强制它运行脚本完成?

是否需要在 package.json 文件中添加“after_compile”、“after_build”脚本?

【问题讨论】:

  • 没有你的package.json,你很难用失败的命令ionic cordova build android来支持你。请将其添加到您的帖子中。

标签: android angular cordova ionic-framework ionic5


【解决方案1】:

可以在项目的config.XML 中使用<hook> 元素定义挂钩,例如:

<hook type="before_build" src="scripts/appBeforeBuild.bat" />
<hook type="before_build" src="scripts/appBeforeBuild.js" />
<hook type="before_plugin_install" src="scripts/appBeforePluginInstall.js" />

<platform name="android">
    <hook type="before_build" src="scripts/android/appAndroidBeforeBuild.bat" />
    <hook type="before_build" src="scripts/android/appAndroidBeforeBuild.js" />
    <hook type="before_plugin_install" src="scripts/android/appAndroidBeforePluginInstall.js" />
    ...
</platform>

成功构建后写入apk文件的路径。在您的日志中找到:

Built the following apk(s): /home/art/Documents/obc/platforms/android/app/build/outputs/apk/debug/app-debug.apk

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-04-11
    • 1970-01-01
    • 1970-01-01
    • 2020-04-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多