Build failure with Cordova Android 9.0.0 and cordova-plugin-health 2.0

Hi all,

I am building my cordova app with Ionic appflow.

One of the plugins I am using requires the build environment to use Cordova Android 9.0.0 ( https://cordova.apache.org/announcements/2020/06/29/cordova-android-9.0.0.html ).

The plugin which requires this is version 2.0.0 of the cordova-plugin-health ( https://github.com/dariosalvi78/cordova-plugin-health ).

If I put version 1.1.4 in my config.xml for cordova-plugin-health it builds fine in Ionic appflow.
If I put version 2.0.0 I get the following error output (see below).


ask :app:compileReleaseJavaWithJavac FAILED
/builds/MichielJ87/FitnessPetsRelease/platforms/android/app/src/main/java/org/apache/cordova/health/HealthPlugin.java:149: error: cannot find symbol
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
^
symbol: variable Q
location: class VERSION_CODES
/builds/MichielJ87/FitnessPetsRelease/platforms/android/app/src/main/java/org/apache/cordova/health/HealthPlugin.java:154: error: cannot find symbol
if (!cordova.hasPermission(Manifest.permission.ACTIVITY_RECOGNITION))
^
symbol: variable ACTIVITY_RECOGNITION
location: class permission
/builds/MichielJ87/FitnessPetsRelease/platforms/android/app/src/main/java/org/apache/cordova/health/HealthPlugin.java:155: error: cannot find symbol
dynPerms.add(Manifest.permission.ACTIVITY_RECOGNITION);
^
symbol: variable ACTIVITY_RECOGNITION
location: class permission

According to the plugin creator of cordova-plugin-health, this is due to the fact that the build environment is not using Cordova Android 9.0.0. You can see his response over here https://gitter.im/cordova-plugin-health/Lobby (see response Dario Salvi).

This plugin is essential for my app, and I need to use version 2.0.0 before April 2021, since Google will stop supporting the previous version of Google Fit from then on.

If anybody could please help me on this topic? Many thanks in advance!

Kind regards,
Michiel

Which Build Stack are you choosing? Looks like for Android, you’d select “Linux - 2020.06” to get Cordova v9.0.3 - see here.

Hi, thanks for your answer.
I have selected 2020.06, but it shows me that error. The other 2 possibilities also show the same error.
Not sure if the error can be related to something else? Is there a way to avoid that error?
Kind regards, Michiel

Appflow should use the cordova-android version you specify in package.json or config.xml.

If you don’t have any fixed version, then Appflow will let cordova CLI use the pinned version.

So if you want cordova-android 9 you have to fix that version in package.json/config.xml or use Cordova CLI 10 as it will default to cordova-android 9.

That means you should use 2020.09 or 2020.11, but not 2020.06 as it uses Cordova CLI 9, which will default to cordova-android 8.

1 Like