我被要求对以前由其他开发人员构建的(非离子)Cordova应用程序进行一些更改。该项目附带了一个依赖管理文件,但是之前的开发人员已经将Cordova本身排除在依赖项之外(可能是因为他在他的机器上全局安装了Cordova),所以我不知道他使用的是什么版本的Cordova。我添加了最新版本的Cordova(9.0.0)。
如果我通过Cordova在浏览器中运行它,该应用程序效果很好。但是,当我为iOS构建并在我的设备上运行时,很明显有些东西无法正常工作,例如启动画面和键盘设置。
如果我在Xcode中检查控制台输出,我会在应用程序启动后看到很多关于插件的错误消息。这里有一些例子:
2019-04-03 17:24:50.502504-0700 APP_NAME [693:225720]错误:未找到插件BuildInfo,或者不是CDVPlugin。检查config.xml中的插件映射。
2019-04-03 17:24:50.502721-0700 APP_NAME [693:225720] - [CDVCommandQueue executePending] [第142行] FAILED pluginJSON = [“BuildInfo1245166954”,“BuildInfo”,“init”,[]]
2019-04-03 17:24:52.005066-0700 APP_NAME [693:225720]错误:找不到插件'StatusBar',或者不是CDVPlugin。检查config.xml中的插件映射。
2019-04-03 17:24:52.005259-0700 APP_NAME [693:225720] - [CDVCommandQueue executePending] [第142行] FAILED pluginJSON = [“StatusBar1245166955”,“StatusBar”,“_ ready”,[]]
2019-04-03 17:24:52.005390-0700 APP_NAME [693:225720]错误:找不到插件'StatusBar',或者不是CDVPlugin。检查config.xml中的插件映射。
2019-04-03 17:24:52.005453-0700 APP_NAME [693:225720] - [CDVCommandQueue executePending] [第142行] FAILED pluginJSON = [“INVALID”,“StatusBar”,“hide”,[]]
尽管有错误消息,但config.xml文件已经列出了插件:
<plugin name="cordova-plugin-whitelist" spec="1" />
<plugin name="cordova-plugin-keyboard" spec="~1.2.0" />
<plugin name="cordova-plugin-splashscreen" spec="~5.0.2" />
<plugin name="cordova-plugin-statusbar" spec="~2.4.2" />
<plugin name="cc.fovea.cordova.purchase" spec="~7.2.5">
<variable name="BILLING_KEY" value="[removed]" />
</plugin>
<plugin name="cordova-plugin-buildinfo" spec="^2.0.2" />
在platforms/ios/ios.json
,有这样的:
"installed_plugins": {
"cc.fovea.cordova.purchase": {
"PACKAGE_NAME": "[removed]"
},
"cordova-plugin-buildinfo": {
"PACKAGE_NAME": "[removed]"
},
"cordova-plugin-keyboard": {
"PACKAGE_NAME": "[removed]"
},
"cordova-plugin-splashscreen": {
"PACKAGE_NAME": "[removed]"
},
"cordova-plugin-statusbar": {
"PACKAGE_NAME": "[removed]"
},
"cordova-plugin-whitelist": {
"PACKAGE_NAME": "[removed]"
}
在platforms/ios/www/cordova_plugins.js
,有这样的:
cordova.define('cordova/plugin_list', function(require, exports, module) {
module.exports = [
{
"id": "cc.fovea.cordova.purchase.InAppPurchase",
"file": "plugins/cc.fovea.cordova.purchase/www/store-ios.js",
"pluginId": "cc.fovea.cordova.purchase",
"clobbers": [
"store"
]
},
{
"id": "cordova-plugin-buildinfo.BuildInfo",
"file": "plugins/cordova-plugin-buildinfo/www/buildinfo.js",
"pluginId": "cordova-plugin-buildinfo",
"clobbers": [
"BuildInfo"
]
},
{
"id": "cordova-plugin-keyboard.keyboard",
"file": "plugins/cordova-plugin-keyboard/www/keyboard.js",
"pluginId": "cordova-plugin-keyboard",
"clobbers": [
"window.Keyboard",
"cordova.plugins.Keyboard"
]
},
{
"id": "cordova-plugin-splashscreen.SplashScreen",
"file": "plugins/cordova-plugin-splashscreen/www/splashscreen.js",
"pluginId": "cordova-plugin-splashscreen",
"clobbers": [
"navigator.splashscreen"
]
},
{
"id": "cordova-plugin-statusbar.statusbar",
"file": "plugins/cordova-plugin-statusbar/www/statusbar.js",
"pluginId": "cordova-plugin-statusbar",
"clobbers": [
"window.StatusBar"
]
}
];
module.exports.metadata =
// TOP OF METADATA
{
"cc.fovea.cordova.purchase": "7.2.8",
"cordova-plugin-buildinfo": "2.0.2",
"cordova-plugin-keyboard": "1.2.0",
"cordova-plugin-splashscreen": "5.0.2",
"cordova-plugin-statusbar": "2.4.2",
"cordova-plugin-whitelist": "1.3.3"
};
// BOTTOM OF METADATA
});
在platforms/ios/www/plugins
中,每个插件都有一个文件夹。每个文件夹都包含一个www
文件夹,其中包含一个JS文件:
platforms/ios/www/plugins
+---cc.fovea.cordova.purchase
¦ +---www
¦ store-ios.js
¦
+---cordova-plugin-buildinfo
¦ +---www
¦ buildinfo.js
¦
+---cordova-plugin-keyboard
¦ +---www
¦ keyboard.js
¦
+---cordova-plugin-splashscreen
¦ +---www
¦ splashscreen.js
¦
+---cordova-plugin-statusbar
+---www
statusbar.js
在Xcode中,所有插件的.m文件都列在Build Phases> Compile Sources中
我一再卸载并重新安装ios
平台并重建项目,但无济于事。
我知道插件是在以前的开发人员制作的构建中工作的,我不明白为什么插件在我构建时没有加载;一切似乎都配置正确。
我通过降级到Cordova 8.1.2解决了这个问题