Java Android - phonegap 错误:解析 XML 时出错:未绑定前缀

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/21115471/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-13 06:41:35  来源:igfitidea点击:

Android - phonegap error: Error parsing XML: unbound prefix

javajavascriptxmlcordovaphonegap-plugins

提问by Max Pain

I restarted eclipse and the error changed to "error: Error parsing XML: unbound prefix" on the same line

我重新启动了 eclipse 并且错误在同一行上更改为“错误:解析 XML 时出错:未绑定前缀”

I am trying to use thisplugin in my android phonegap application. It is a local notification plugin. I am getting the error in my config.xml file on this line:

我正在尝试在我的 android phonegap 应用程序中使用这个插件。它是一个本地通知插件。我在这一行的 config.xml 文件中收到错误消息:

<gap:plugin name="de.appplant.cordova.plugin.local-notification" version="0.6.2" />

There is a similar question about this problem here, but the answer is not related to my problem.

有一个关于这个问题的一个类似的问题在这里,但答案是不相关的我的问题。

Here is my config.xml file:

这是我的 config.xml 文件:

<?xml version="1.0" encoding="UTF-8"?>
<widget xmlns     = "http://www.w3.org/ns/widgets"
        id        = "com.xxx.xxx"
        version   = "2.0.0">
    <name>xxx</name>

    <description>
    xxx
    </description>

    <author href="http://www.example.com" email="[email protected]">
    xxx
    </author>

    <access origin="*"/>

    <!-- <content src="xxx" /> for external pages -->
    <content src="index.html" />

    <preference name="loglevel" value="DEBUG" />
    <!--
      <preference name="splashscreen" value="resourceName" />
      <preference name="backgroundColor" value="0xFFF" />
      <preference name="loadUrlTimeoutValue" value="20000" />
      <preference name="InAppBrowserStorageEnabled" value="true" />
      <preference name="disallowOverscroll" value="true" />
    -->

    <feature name="App">
      <param name="android-package" value="org.apache.cordova.App"/>
    </feature>
    <feature name="Geolocation">
      <param name="android-package" value="org.apache.cordova.GeoBroker"/>
    </feature>
    <feature name="Device">
      <param name="android-package" value="org.apache.cordova.Device"/>
    </feature>
    <feature name="Accelerometer">
      <param name="android-package" value="org.apache.cordova.AccelListener"/>
    </feature>
    <feature name="Compass">
      <param name="android-package" value="org.apache.cordova.CompassListener"/>
    </feature>
    <feature name="Media">
      <param name="android-package" value="org.apache.cordova.AudioHandler"/>
    </feature>
    <feature name="Camera">
      <param name="android-package" value="org.apache.cordova.CameraLauncher"/>
    </feature>
    <feature name="Contacts">
      <param name="android-package" value="org.apache.cordova.ContactManager"/>
    </feature>
    <feature name="File">
      <param name="android-package" value="org.apache.cordova.FileUtils"/>
    </feature>
    <feature name="NetworkStatus">
      <param name="android-package" value="org.apache.cordova.NetworkManager"/>
    </feature>
    <feature name="Notification">
      <param name="android-package" value="org.apache.cordova.Notification"/>
    </feature>
    <feature name="Storage">
      <param name="android-package" value="org.apache.cordova.Storage"/>
    </feature>
    <feature name="FileTransfer">
      <param name="android-package" value="org.apache.cordova.FileTransfer"/>
    </feature>
    <feature name="Capture">
      <param name="android-package" value="org.apache.cordova.Capture"/>
    </feature>
    <feature name="Battery">
      <param name="android-package" value="org.apache.cordova.BatteryListener"/>
    </feature>
    <feature name="SplashScreen">
      <param name="android-package" value="org.apache.cordova.SplashScreen"/>
    </feature>
    <feature name="Echo">
      <param name="android-package" value="org.apache.cordova.Echo"/>
    </feature>
    <feature name="Globalization">
      <param name="android-package" value="org.apache.cordova.Globalization"/>
    </feature>
    <feature name="InAppBrowser">
      <param name="android-package" value="org.apache.cordova.InAppBrowser"/>
    </feature>
    <!-- Deprecated plugins element. Remove in 3.0 -->


    <plugins>
        <plugin name="SplashScreen" value="org.apache.cordova.SplashScreen"/>
        <gap:plugin name="de.appplant.cordova.plugin.local-notification" version="0.6.2" />
    </plugins>

</widget>

I am using eclipse with the adt plugin. I generated an android application and made some modification to it so it would work with phonegap (its working fine without the local notification plugin). I am using cordova 2.9.0 version. How can I solve this problem?

我正在使用带有 adt 插件的 eclipse。我生成了一个 android 应用程序并对其进行了一些修改,以便它可以与 phonegap 一起使用(它在没有本地通知插件的情况下工作正常)。我正在使用cordova 2.9.0 版本。我怎么解决这个问题?

采纳答案by drdrej

You need to add a xml namespace.

您需要添加一个 xml 命名空间。

  xmlns:gap="http://phonegap.com/ns/1.0"

Your root xml schould look like this one:

您的根 xml 应该如下所示:

  <widget id="com.example.MyApp" 
    version="1.0.0" xmlns="http://www.w3.org/ns/widgets" 
    xmlns:gap="http://phonegap.com/ns/1.0">

good luck!

祝你好运!

回答by mrmoree

For me the problem was a not interpretable attribute in my manifest file. change the red marked to the green one (see screenshot), make sure you have your android device connected and run phonegap run androidagain.

对我来说,问题是我的清单文件中的一个不可解释的属性。将红色标记更改为绿色(参见屏幕截图),确保您已连接 android 设备并phonegap run android再次运行。

change wrong xml attributes in AndroidManifest.xml

在 AndroidManifest.xml 中更改错误的 xml 属性

Use adb logcat to discover build and runtime issuesFor android you can use the logcat output to debug your phonegap/cordova application. On iOS use the logcat output from xcode

使用 adb logcat 发现构建和运行时问题对于 android,您可以使用 logcat 输出来调试您的 phonegap/cordova 应用程序。在 iOS 上使用 xcode 的 logcat 输出

i discovered the above problem by running adb logcatfrom projects root in console.

我通过adb logcat从控制台中的项目根目录运行发现了上述问题。

if you like to filter the output of any logfile you can do easily by using grepfollowed by your keyword (e.g. error or mergemanifest):

如果您想过滤任何日志文件的输出,您可以使用grep后跟关键字(例如错误或合并清单)轻松完成:

adb logcat | grep error

replace "error" with whatever you are looking for in logcat

用您在 logcat 中寻找的任何内容替换“错误”

回答by Shane McCurdy

Thank you very much mrmoree! This thread pointed me in the right direction. I had an similar issue with the final version of the config.xml being built by ionic-cordova, getting this error:

非常感谢先生!这个线程为我指明了正确的方向。我在 ionic-cordova 构建的 config.xml 的最终版本中遇到了类似的问题,得到了这个错误:

.../platforms/android/app/src/main/res/xml/config.xml:51: AAPT: error: unbound prefix.

.../platforms/android/app/src/main/res/xml/config.xml:51: AAPT: 错误: 未绑定前缀。

I had to switch over the xml tag format to have name="android.permission.CAMERA" platform="android"broken out instead of android:name="android.permission.CAMERA"for it to work. Now it works great.

我不得不切换 xml 标签格式,name="android.permission.CAMERA" platform="android"而不是android:name="android.permission.CAMERA"让它工作。现在效果很好。

<platform name="android">
    <config-file parent="/*" target="AndroidManifest.xml">
        <uses-permission name="android.permission.CAMERA" platform="android" />
        <uses-permission name="android.permission.RECORD_AUDIO" platform="android" />
        <uses-permission name="android.permission.MODIFY_AUDIO_SETTINGS" platform="android" />
    </config-file>
</platform>