首页 > 解决方案 > 添加背景地理定位插件后,Ionic 3 空白应用程序无法构建到 Android

问题描述

我有一个旧的 ionic v3 项目,安装了许多插件并且它可以工作,但是对于一个全新的 ionic v3 'testplugins' 项目,我根本无法使用后台地理定位插件将它构建到 Android!

我已经采取了一些步骤来在 ionic v3 中创建这个问题......

ionic start test blank --type=ionic-angular
ionic cordova platform add android
ionic cordova build android

这构建成功,但现在安装后台地理定位插件。

ionic cordova plugin add cordova-plugin-mauron85-background-geolocation@alpha
ionic cordova build android

这失败并出现以下错误...

* What went wrong:
Execution failed for task ':app:processDebugResources'.
> Android resource linking failed
  testplugins\platforms\android\app\src\main\res\xml\authenticator.xml:2: AAPT: error: resource mipmap/icon (aka io.ionic.starter:mipmap/icon) not found.

  error: failed linking file resources.

我可以确认drawable和mipmap文件存在于文件夹platforms\android\app\src\main\res\

我尝试将@mipmap/icon 更改为@mipmap/ic_launcher,但没有像其他博客所说的那样成功。

包.json

        "GOOGLE_PLAY_SERVICES_VERSION": "11+",
        "ANDROID_SUPPORT_LIBRARY_VERSION": "26+",
        "ICON": "@mipmap/icon",
        "SMALL_ICON": "@mipmap/icon",
        "ACCOUNT_NAME": "@string/app_name",
        "ACCOUNT_LABEL": "@string/app_name",
        "ACCOUNT_TYPE": "$PACKAGE_NAME.account",
        "CONTENT_AUTHORITY": "$PACKAGE_NAME"
      }

我的 config.xml 中没有添加任何内容,我最近使用的其他一些插件似乎就是这种情况。这是正确的吗?

我已将其手动添加到 config.xml ...

<plugin name="cordova-plugin-mauron85-background-geolocation" spec="~3.0.0-alpha.50">
        <variable name="GOOGLE_PLAY_SERVICES_VERSION" value="11+" />
        <variable name="ANDROID_SUPPORT_LIBRARY_VERSION" value="26+" />
        <variable name="ICON" value="@mipmap/icon" />
        <variable name="SMALL_ICON" value="@mipmap/icon" />
        <variable name="ACCOUNT_NAME" value="@string/app_name" />
        <variable name="ACCOUNT_LABEL" value="@string/app_name" />
        <variable name="ACCOUNT_TYPE" value="$PACKAGE_NAME.account" />
        <variable name="CONTENT_AUTHORITY" value="$PACKAGE_NAME" />
    </plugin>

我确定当我安装插件时,一个条目会自动添加到 config.xml。这不再需要了吗?

我需要做什么才能使构建与后台地理定位插件一起使用?

欢迎任何帮助。

标签: ionic3

解决方案


只需删除 android 平台 android 文件夹并重新构建。如果错误仍然存​​在,请尝试再次添加平台android。


推荐阅读