Cordova/Phonegap / iOS:错误:找不到插件“Plugin01”,或者不是 CDVP 插件。检查 config.xml 中的插件映射
Posted
技术标签:
【中文标题】Cordova/Phonegap / iOS:错误:找不到插件“Plugin01”,或者不是 CDVP 插件。检查 config.xml 中的插件映射【英文标题】:Cordova/Phonegap / iOS: ERROR: Plugin 'Plugin01' not found, or is not a CDVPlugin. Check your plugin mapping in config.xml 【发布时间】:2015-07-20 09:22:46 【问题描述】:升级到 Phonegap 5 后,我无法为旧项目或新项目创建工作插件。
有很多这样的问题,但大多数与对我来说很好用的版本 3 相关。找不到与版本 5 相关的好文档。
我创建了一个新的测试项目,就像那样,但我仍然无法让它工作。
phonegap create test01 com.example.test01 Test01
phonegap platform add ios
phonegap plugin add ../test01-plugin01/
phonegap build ios
插件.xml
<?xml version="1.0" encoding="UTF-8"?>
<plugin xmlns="http://www.phonegap.com/ns/plugins/1.0"
id="com.example.plugin01"
version="1.0.0">
<name>Plugin01</name>
<!-- ios -->
<platform name="ios">
<header-file src="src/ios/Plugin01.h" />
<source-file src="src/ios/Plugin01.m" />
</platform>
</plugin>
插件01.h
#import <Foundation/Foundation.h>
#import <Cordova/CDVPlugin.h>
@interface Plugin01 : CDVPlugin
NSString* callbackID;
@property (nonatomic, copy) NSString* callbackID;
- (void)test:(CDVInvokedUrlCommand*)command;
@end
config.xml
<?xml version='1.0' encoding='utf-8'?>
<widget id="com.example.test01" version="1.0.0" xmlns="http://www.w3.org/ns/widgets" xmlns:gap="http://phonegap.com/ns/1.0">
<name>Test01</name>
<description>
Hello World sample application that responds to the deviceready event.
</description>
<author email="support@phonegap.com" href="http://phonegap.com">
PhoneGap Team
</author>
<content src="index.html" />
<preference name="permissions" value="none" />
<preference name="orientation" value="default" />
<preference name="target-device" value="universal" />
<preference name="fullscreen" value="true" />
<preference name="webviewbounce" value="true" />
<preference name="prerendered-icon" value="true" />
<preference name="stay-in-webview" value="false" />
<preference name="ios-statusbarstyle" value="black-opaque" />
<preference name="detect-data-types" value="true" />
<preference name="exit-on-suspend" value="false" />
<preference name="show-splash-screen-spinner" value="true" />
<preference name="auto-hide-splash-screen" value="true" />
<preference name="disable-cursor" value="false" />
<preference name="android-minSdkVersion" value="7" />
<preference name="android-installLocation" value="auto" />
<gap:plugin name="org.apache.cordova.battery-status" />
<gap:plugin name="org.apache.cordova.camera" />
<gap:plugin name="org.apache.cordova.media-capture" />
<gap:plugin name="org.apache.cordova.console" />
<gap:plugin name="org.apache.cordova.contacts" />
<gap:plugin name="org.apache.cordova.device" />
<gap:plugin name="org.apache.cordova.device-motion" />
<gap:plugin name="org.apache.cordova.device-orientation" />
<gap:plugin name="org.apache.cordova.dialogs" />
<gap:plugin name="org.apache.cordova.file" />
<gap:plugin name="org.apache.cordova.file-transfer" />
<gap:plugin name="org.apache.cordova.geolocation" />
<gap:plugin name="org.apache.cordova.globalization" />
<gap:plugin name="org.apache.cordova.inappbrowser" />
<gap:plugin name="org.apache.cordova.media" />
<gap:plugin name="org.apache.cordova.network-information" />
<gap:plugin name="org.apache.cordova.splashscreen" />
<gap:plugin name="org.apache.cordova.vibration" />
<gap:plugin name="com.example.plugin01" />
<icon src="icon.png" />
<icon gap:platform="android" gap:qualifier="ldpi" src="www/res/icon/android/icon-36-ldpi.png" />
<icon gap:platform="android" gap:qualifier="mdpi" src="www/res/icon/android/icon-48-mdpi.png" />
<icon gap:platform="android" gap:qualifier="hdpi" src="www/res/icon/android/icon-72-hdpi.png" />
<icon gap:platform="android" gap:qualifier="xhdpi" src="www/res/icon/android/icon-96-xhdpi.png" />
<icon gap:platform="blackberry" src="www/res/icon/blackberry/icon-80.png" />
<icon gap:platform="blackberry" gap:state="hover" src="www/res/icon/blackberry/icon-80.png" />
<icon gap:platform="ios" src="www/res/icon/ios/icon-57.png" />
<icon gap:platform="ios" src="www/res/icon/ios/icon-72.png" />
<icon gap:platform="ios" src="www/res/icon/ios/icon-57-2x.png" />
<icon gap:platform="ios" src="www/res/icon/ios/icon-72-2x.png" />
<icon gap:platform="webos" src="www/res/icon/webos/icon-64.png" />
<icon gap:platform="winphone" src="www/res/icon/windows-phone/icon-48.png" />
<icon gap:platform="winphone" gap:role="background" src="www/res/icon/windows-phone/icon-173-tile.png" />
<gap:splash gap:platform="android" gap:qualifier="port-ldpi" src="www/res/screen/android/screen-ldpi-portrait.png" />
<gap:splash gap:platform="android" gap:qualifier="port-mdpi" src="www/res/screen/android/screen-mdpi-portrait.png" />
<gap:splash gap:platform="android" gap:qualifier="port-hdpi" src="www/res/screen/android/screen-hdpi-portrait.png" />
<gap:splash gap:platform="android" gap:qualifier="port-xhdpi" src="www/res/screen/android/screen-xhdpi-portrait.png" />
<gap:splash gap:platform="blackberry" src="www/res/screen/blackberry/screen-225.png" />
<gap:splash gap:platform="ios" src="www/res/screen/ios/screen-iphone-portrait.png" />
<gap:splash gap:platform="ios" src="www/res/screen/ios/screen-iphone-portrait-2x.png" />
<gap:splash gap:platform="ios" src="www/res/screen/ios/screen-iphone-portrait-568h-2x.png" />
<gap:splash gap:platform="ios" src="www/res/screen/ios/screen-ipad-portrait.png" />
<gap:splash gap:platform="ios" src="www/res/screen/ios/screen-ipad-landscape.png" />
<gap:splash gap:platform="winphone" src="www/res/screen/windows-phone/screen-portrait.jpg" />
<access origin="*" />
<plugin name="cordova-plugin-whitelist" version="1" />
<plugin name="com.example.plugin01" />
<allow-intent href="http://*/*" />
<allow-intent href="https://*/*" />
<allow-intent href="tel:*" />
<allow-intent href="sms:*" />
<allow-intent href="mailto:*" />
<allow-intent href="geo:*" />
<platform name="android">
<allow-intent href="market:*" />
</platform>
<platform name="ios">
<allow-intent href="itms:*" />
<allow-intent href="itms-apps:*" />
</platform>
</widget>
index.html
<button onclick="test01();">Test</button>
</div>
</div>
<script type="text/javascript" src="cordova.js"></script>
<script type="text/javascript" src="js/index.js"></script>
<script type="text/javascript">
app.initialize();
function test01()
cordova.exec(null, null, 'Plugin01', 'test', []);
</script>
当我在 Plugin
文件夹中打开项目时,我可以在 Xcode 中看到 Plugin01.h
和 Plugin01.m
。我可以在 iPhone 上运行应用程序。
当我触摸“测试”按钮时,出现以下错误:
2015-07-20 12:00:29.108 Test01[1925:1174928] ERROR: Plugin 'Plugin01' not found, or is not a CDVPlugin. Check your plugin mapping in config.xml.
2015-07-20 12:00:29.109 Test01[1925:1174928] -[CDVCommandQueue executePending] [Line 159] FAILED pluginJSON = ["INVALID","Plugin01","test",[]]
我无法从 WebView 执行我的本机代码
【问题讨论】:
【参考方案1】:您必须在 plugin.xml 的配置文件标签内添加功能标签,以便将其添加到 config.xml
<name>Plugin01</name>
<!-- ios -->
<platform name="ios">
<config-file target="config.xml" parent="/*">
<feature name="Plugin01">
<param name="ios-package" value="Plugin01"/>
</feature>
</config-file>
<header-file src="src/ios/Plugin01.h" />
<source-file src="src/ios/Plugin01.m" />
</platform>
【讨论】:
以上是关于Cordova/Phonegap / iOS:错误:找不到插件“Plugin01”,或者不是 CDVP 插件。检查 config.xml 中的插件映射的主要内容,如果未能解决你的问题,请参考以下文章
在 iOS 上调试 Cordova (PhoneGap) 代码
Phonegap / Cordova 在 ios8 中不起作用
在 Cordova / PhoneGap 中生成 iOS 和 Android 图标
Cordova/PhoneGap:childBrowser UI 图像低分辨率/大块(iOS)