按Apache官方教程新建的Cordova项目执行Android构建失败
Hey there! Let’s break down those messages you’re seeing when running cordova build android --verbose—most are totally normal, but there’s one line worth noting:
Normal, Expected Messages
No scripts found for hook "before_build". No scripts found for hook "before_prepare".
This is just Cordova letting you know you haven’t set up any custom hook scripts for thebefore_buildorbefore_preparestages. Hooks are optional custom scripts you can add to automate tasks during the build process; if you don’t need them, this message is nothing to worry about—it’s just the default behavior.Checking config.xml and package.json for saved platforms that haven't been added to the project
Cordova automatically syncs platform information between yourconfig.xml(the Cordova-specific config file) andpackage.json(the standard Node.js project config). This line is just it starting that routine check.Config.xml and package.json platforms are the same. No pkg.json modification.
Initially, Cordova detects that your platform lists match perfectly, so no changes are needed topackage.json.
The Line to Pay Attention To
Package.json and config.xml platforms are different. Updating config...
This means Cordova found a mismatch between the platforms listed inpackage.jsonandconfig.xmlright after its initial check. This can happen if you manually edited one of the files, or if a previous platform add/remove operation didn’t fully sync the two files. The good news? Cordova is automatically fixing the mismatch by updatingconfig.xmlto align withpackage.json(or vice versa).
Quick Fix if This Mismatch Keeps Happening
If you keep seeing this message on every build, you can manually sync the files yourself:
- Open
config.xmland check the<platform>elements (look for<platform name="android">). - Open
package.jsonand check thecordova.platformsarray. - Make sure both files list exactly the same platforms (e.g., both include
"android"). - Run
cordova prepareto force a full sync of your project configuration.
内容的提问来源于stack exchange,提问作者Ben Carpenter

