Android 使用 cordova-whitelist-plugin 构建失败

Android build failed with cordova-whitelist-plugin

我是科尔多瓦的新手, 我正在为 cordova 使用几个插件,其中一个是白名单插件。 当我将白名单插件添加到我的 cordova 项目并在 android 设备上从 eclipse 添加 运行 时,出现以下错误。

-compile:
   [javac] Compiling 31 source files to D:\software\eclipse\configuration\org.eclipse.osgi99\data\proj_gen\GoFindoMobile\android\bin\classes
   [javac] D:\software\eclipse\configuration\org.eclipse.osgi99\data\proj_gen\GoFindoMobile\android\src\org\apache\cordova\whitelist\WhitelistPlugin.java:42: error: no suitable method found for parse(Context)
   [javac]         new CustomConfigXmlParser().parse(context);
   [javac]                                    ^
   [javac]     method ConfigXmlParser.parse(XmlResourceParser) is not applicable
   [javac]       (actual argument Context cannot be converted to XmlResourceParser by method invocation conversion)
   [javac]     method ConfigXmlParser.parse(Activity) is not applicable
   [javac]       (actual argument Context cannot be converted to Activity by method invocation conversion)
   [javac] D:\software\eclipse\configuration\org.eclipse.osgi99\data\proj_gen\GoFindoMobile\android\src\org\apache\cordova\whitelist\WhitelistPlugin.java:46: error: no suitable method found for parse(XmlPullParser)
   [javac]         new CustomConfigXmlParser().parse(xmlParser);
   [javac]                                    ^
   [javac]     method ConfigXmlParser.parse(XmlResourceParser) is not applicable
   [javac]       (actual argument XmlPullParser cannot be converted to XmlResourceParser by method invocation conversion)
   [javac]     method ConfigXmlParser.parse(Activity) is not applicable
   [javac]       (actual argument XmlPullParser cannot be converted to Activity by method invocation conversion)
   [javac] D:\software\eclipse\configuration\org.eclipse.osgi99\data\proj_gen\GoFindoMobile\android\src\org\apache\cordova\whitelist\WhitelistPlugin.java:64: error: no suitable method found for parse(Context)
   [javac]             new CustomConfigXmlParser().parse(webView.getContext());
   [javac]                                        ^
   [javac]     method ConfigXmlParser.parse(XmlResourceParser) is not applicable
   [javac]       (actual argument Context cannot be converted to XmlResourceParser by method invocation conversion)
   [javac]     method ConfigXmlParser.parse(Activity) is not applicable
   [javac]       (actual argument Context cannot be converted to Activity by method invocation conversion)
   [javac] D:\software\eclipse\configuration\org.eclipse.osgi99\data\proj_gen\GoFindoMobile\android\src\org\apache\cordova\whitelist\WhitelistPlugin.java:69: error: method does not override or implement a method from a supertype
   [javac]         @Override
   [javac]         ^
   [javac] D:\software\eclipse\configuration\org.eclipse.osgi99\data\proj_gen\GoFindoMobile\android\src\org\apache\cordova\whitelist\WhitelistPlugin.java:106: error: method does not override or implement a method from a supertype
   [javac]         @Override
   [javac]         ^
   [javac] D:\software\eclipse\configuration\org.eclipse.osgi99\data\proj_gen\GoFindoMobile\android\src\org\apache\cordova\whitelist\WhitelistPlugin.java:111: error: method does not override or implement a method from a supertype
   [javac]     @Override
   [javac]     ^
   [javac] D:\software\eclipse\configuration\org.eclipse.osgi99\data\proj_gen\GoFindoMobile\android\src\org\apache\cordova\whitelist\WhitelistPlugin.java:119: error: method does not override or implement a method from a supertype
   [javac]     @Override
   [javac]     ^
   [javac] D:\software\eclipse\configuration\org.eclipse.osgi99\data\proj_gen\GoFindoMobile\android\src\org\apache\cordova\whitelist\WhitelistPlugin.java:130: error: method does not override or implement a method from a supertype
   [javac]     @Override
   [javac]     ^
   [javac] Note: Some input files use or override a deprecated API.
   [javac] Note: Recompile with -Xlint:deprecation for details.
   [javac] 8 errors

构建失败

当我不使用白名单插件时它编译正常。

这很可能是因为您使用的是旧版本的 Cordova (<= v4.x) 和最新的白名单插件 (>= v5.x)。在 Cordova 5 中,他们将 ConfigXmlParser api 切换为 Context 而不是 Activity.