首页 > 解决方案 > Phonegap 构建 config.xml 和地理位置

问题描述

在 PhoneGap 构建中使用地理定位时,我遇到了一个非常奇怪的问题。我让它与我的 config.xml 一起工作,如下所示:

<?xml version='1.0' encoding='utf-8'?>
<widget id="net.seekadventure" version="0.0.2" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">
  <name>Seek Adventure Map</name>
  <description>
      A map to help you find your next Adventure!
  </description>
  <author email="myEmail" href="https://www.seekadventure.net">
      Seek ADventure Team
  </author>
  <content src="index.html" />
  <plugin name="cordova-plugin-whitelist" spec="1" />



    <preference name="permissions" value="none"/>
    <feature name="http://api.phonegap.com/1.0/geolocation"/>

    <plugin name="cordova-plugin-geolocation" spec="1" />

<icon src="icon.png" />


  <access origin="*" />
  <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>

关闭的部分是,当我安装它并在手机上打开它时,它会给我一个弹出窗口,上面写着:

“此应用是为旧版 Android 构建的,可能无法正常运行。请尝试检查更新,或联系开发人员”

因为我得到了那个错误,所以我做了一些研究并将它添加到我的 config.xml

<preference name="android-minSdkVersion" value="27" />
  <preference name="android-maxSdkVersion" value="29" />
  <preference name="android-targetSdkVersion" value="28" />

当我添加上面的代码时,它修复了关于在旧版本上构建但 GPS 权限不起作用的错误......有什么想法吗?

更新:

我还尝试为插件指定源和版本,但没有帮助:

<plugin name="cordova-plugin-geolocation" source="npm" spec="4.0.2" />

标签: androidphonegap-buildphonegap

解决方案


我没有在我的 config/xml 中指定 CLI 版本,这是导致问题的原因:

  <preference name="phonegap-version" value="cli-9.0.0" />

推荐阅读