Search code examples
androidangularcordovaionic-frameworkionic5

Unable to 'ionic cordova build' No scripts found for hook "after_compile" and "after_build"


Unable to get ionic cordova build android to work.

INFO:

  • ubuntu 20..,
  • node 10, ionic 5,
  • local angular 8,
  • gradle 5,
  • android sdk 28, 30.
  • all vars are exported...As far as I can tell

FIRST: After npm install and global ionic, cordova and angular install I run the command ionic cordova build android.I get this error in the output :

...
      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 : running ng run app:ionic-cordova-build --platform=android resolves without errors, even though it "exited with exit code 1" when running 'ionic cordova build android'

THIRD : after running ng run app:ionic-cordova-build --platform=android i ran ionic cordova build android and got this result with no apk in build folder:

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

Am I missing some steps before running ionic cordova build android?

Are there ways to force it to run the script to completion?

Do I need to add the "after_compile", "after_build" script to the package.json file ?


Solution

  • Hooks could be defined in project's config.XML using <hook> elements, for example:

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

    The path to the apk file is written after the successful build. Locate in your log:

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