Gradle version conflict after adding cordova fcm plugin

6.3k views Asked by At

After adding FCM Plugin to project it is not building anymore.

Where cordova is checking GRADLE version? From package.json? I've tried to change ANDROID_GRADLE_TOOLS_VERSION spec on package.json, without success.

cordova plugin add cordova-plugin-fcm-with-dependecy-updated
cordova run android
FCMPlugin: Support for Gradle v4 or lower is deprecated. Please upgrade to a newer version.FAILURE: Build failed with an exception.

* What went wrong:
A problem occurred configuring project ':app'.
> Could not create task ':app:processDebugGoogleServices'.
   > Cannot create a proxy class for abstract class 'GoogleServicesTask'.
BUILD FAILED in 3s

I tried to use plugin version 7.0.8 as suggested by Tiago

cordova plugin add [email protected]

Now I have conflicts with the camera plugin

> Task :app:compileDebugJavaWithJavac
C:\myapp\app\platforms\android\app\src\main\java\org\apache\cordova\camera\CameraLauncher.java:40: error: package android.support.v4.content does not exist
import android.support.v4.content.FileProvider;
                                 ^
C:\myapp\app\platforms\android\app\src\main\java\org\apache\cordova\camera\CordovaUri.java:25: error: package android.support.v4.content does not exist
import android.support.v4.content.FileProvider;
                                 ^
C:\myapp\app\platforms\android\app\src\main\java\org\apache\cordova\camera\FileProvider.java:21: error: package android.support.v4.content does not exist
public class FileProvider extends android.support.v4.content.FileProvider {}
                                                            ^
C:\myapp\app\platforms\android\app\src\main\java\org\apache\cordova\camera\CameraLauncher.java:303: error: cannot find symbol
        this.imageUri = new CordovaUri(FileProvider.getUriForFile(cordova.getActivity(),
                                                   ^
  symbol:   method getUriForFile(Activity,String,File)
  location: class FileProvider
C:\myapp\app\platforms\android\app\src\main\java\org\apache\cordova\camera\CameraLauncher.java:801: error: cannot find symbol
                        Uri tmpFile = FileProvider.getUriForFile(cordova.getActivity(),
                                                  ^
  symbol:   method getUriForFile(Activity,String,File)
  location: class FileProvider
5 errors

> Task :app:compileDebugJavaWithJavac FAILED

FAILURE: Build failed with an exception.

Removing fcm plugin camera plugin works again. Also its weird that even after removing fcm plugin it is still on the project and showing error messages on console

FCMPlugin.js:46 FCM: has been created
FCMPlugin.js:41 FCM: Ready error:  Class not found
FCMPlugin.js:43 FCM: Ready!
FCMPlugin.js:23 FCM: Error listening to native events Class not found
2

There are 2 answers

4
Tiago P. O. On

So apparently, we will have to wait for the fcm plugin guys to fix this. There is this github issue opened a few days ago and it seems that they just have to update the version in the plugin.

A workaround for now is downgrade to a previous version. I used "cordova-plugin-fcm-with-dependecy-updated": "7.0.8" and is working.

Github issue: https://github.com/andrehtissot/cordova-plugin-fcm-with-dependecy-updated/issues/222

1
Ibni Amin On

If your Cordova project contains plugins/libraries which reference both the Android Support Library and AndroidX, your Android build will fail because the two cannot live side-by-side in an Android build.

This plugin provides a shim to migrate references to the legacy Android Support Library to the new AndroidX mappings in a Cordova Android platform project.

This enables a Cordova project for which AndroidX has been enabled (e.g. using cordova-plugin-androidx) to successfully build even if it contains plugins which reference the legacy Support Library.

The plugin uses a hook script to replace any legacy Support Library references:

Gradle artifacts in app/build.gradle and project.properties with new artifact mappings Class/package names in AndroidManifest.xml or the Java source code (of Cordova plugins) with new class mappings.