cordova-plugin-background-geolocation: AAPT: error: resource mipmap/icon (aka io.ionic.starter:mipmap/icon) not found.

Im using this plugin on my app, but when I use it on a page, all the times throws this error.

Your Environment

Ionic info:

   Ionic CLI                     : 6.4.0 (/usr/local/lib/node_modules/@ionic/cli)
   Ionic Framework               : @ionic/angular 5.0.7
   @angular-devkit/build-angular : 0.901.0
   @angular-devkit/schematics    : 9.1.0
   @angular/cli                  : 9.1.0
   @ionic/angular-toolkit        : 2.2.0

Cordova:

   Cordova CLI       : 9.0.0 (cordova-lib@9.0.1)
   Cordova Platforms : android 8.1.0
   Cordova Plugins   : cordova-plugin-ionic-keyboard 2.2.0, cordova-plugin-ionic-webview 4.1.3, (and 11 other plugins)

Utility:

   cordova-res (update available: 0.11.0) : 0.9.0
   native-run (update available: 1.0.0)   : 0.3.0

System:

   Android SDK Tools : 26.1.1 (/root/Android/Sdk/)
   NodeJS            : v13.8.0 (/usr/local/bin/node)
   npm               : 6.13.6
   OS                : Linux 5.3

Cordova plugin list:```



cordova-android-support-gradle-release 3.0.1 "cordova-android-support-gradle-release"
cordova-plugin-advanced-http 2.4.1 "Advanced HTTP plugin"
cordova-plugin-background-geolocation 3.1.0 "CDVBackgroundGeolocation"
cordova-plugin-background-mode 0.7.3 "BackgroundMode"
cordova-plugin-ble-central 1.2.4 "BLE"
cordova-plugin-device 2.0.3 "Device"
cordova-plugin-file 6.0.2 "File"
cordova-plugin-geolocation 4.0.2 "Geolocation"
cordova-plugin-ionic-keyboard 2.2.0 "cordova-plugin-ionic-keyboard"
cordova-plugin-ionic-webview 4.1.3 "cordova-plugin-ionic-webview"
cordova-plugin-splashscreen 5.0.3 "Splashscreen"
cordova-plugin-statusbar 2.4.3 "StatusBar"
cordova-plugin-whitelist 1.3.4 "Whitelist"

Steps to Reproduce

1.sudo ionic cordova run android 2. 3. 4.

Context

I want to use background geolocation to follow my movements durin a period of time

Debug logs

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:processDebugResources'.
> Android resource linking failed
  /home/absant/Escritorio/workspace/project2/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.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 9s
[ERROR] An error occurred while running subprocess cordova.
        ```


About this issue

Most upvoted comments

After hours trying to solve this problem, my DEFINITIVE solution that worked fine (without touch the files inside platforms), was:

1º - run cordova platform remove android

2º - Added this line in my config.xml inside the tag <platform name="android"> <resource-file src="resources/android/icon/drawable-xxxhdpi-icon.png" target="app/src/main/res/mipmap/icon.png" />

3º - Update the plugin settings inside config.xml

<plugin name="@mauron85/cordova-plugin-background-geolocation" spec="3.1.0">
   <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="ALWAYS_USAGE_DESCRIPTION" value="App requires background tracking " />
   <variable name="MOTION_USAGE_DESCRIPTION" value="App requires motion detection" />
</plugin>

4º - Configure my package.json

// package.json
  {
    "cordova": {
      "plugins": {
      "@mauron85/cordova-plugin-background-geolocation": {
        "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"
      },
      },
    },
  }

5º - Last step run cordova platform add android

IONIC VERSION: 6.4.0 CORDOVA VERSION: 9.0.0 (cordova-lib@9.0.1) NODE VERSION: v10.16.0

Please update this as a fix, it is ridiculous that we cannot compile until manual fix this bug.

I already posted the solution here https://github.com/apache/cordova-android/issues/678#issuecomment-574714031

Is not a good practice to touch the files inside platforms> (edit or create stuff there), so I recommend to change the ICON variable and keep it like

<plugin name="@mauron85/cordova-plugin-background-geolocation" spec="3.0.3"> ... <variable name="ICON" value="@mipmap/ic_launcher" /> ... </plugin>

This route “mipmap/ic_launcher” will work. BTW now package is @mauron85/cordova-plugin-background-geolocation, the other one is deprecated

Add the following line to the android platform in config.xml: <resource-file src="resources/android/icon/drawable-xxxhdpi-icon.png" target="app/src/main/res/mipmap/icon.png" />

Mi solución fue armar un Hook que copie uno de mis iconos en la carpeta pedida y con el nombre adecuado.

            var fs = require('fs');
            var path = require('path');
            var rootdir = context.opts.projectRoot;

            var srcfile = path.join(rootdir,"resources/android/icon_notificacion/drawable-hdpi/icon.png");
            var destfile = path.join(rootdir,"platforms/android/app/src/main/res/mipmap/icon.png");

            fs.createReadStream(srcfile).pipe(fs.createWriteStream(destfile));

@lrcampos97 's solution worked for me.

@RaschidJFR , @Ircampos97, thank you guys, I appreciate it and will give it a try. Plan B is to buy a cordova-background-geolocation-lt license, even if it seems to be a bit overkill for my needs.

Just to complement the answer from @ZumelzuR : You can also change this configuration in your package.json:

// package.json
  {
    "cordova": {
      "plugins": {
        "@mauron85/cordova-plugin-background-geolocation": {
          "ICON": "@mipmap/ic_launcher",        // <-- Change this to 'ic_launcher' 
          "SMALL_ICON": "@mipmap/ic_launcher",  // <-- Change this to 'ic_launcher' 
        },
      },
    },
  }

Execute these commands:

mkdir -p platforms/android/app/src/main/res/mipmap 
cp resources/icon.png platforms/android/app/src/main/res/mipmap 
cp resources/splash.png platforms/android/app/src/main/res/mipmap