Build issue with FCM plugin - FCMPlugin: Plugin install variables are not accessible, as package.json was unreachable/unreadable

In my ionic 5 application with capacitor, I am trying to implement push notifications with FCM plugin.

I have correctly setup my Firebase project and google-services.json file is also in place. It has been kept at android/app

However, when I build, it fails saying the following

Configure project :app
FCMPlugin: Plugin install variables are not accessible, as package.json was unreachable/unreadable.FCMPlugin: Plugin install variables are not accessible, as package.json was unreachable/unreadable.FCMPlugin: Plugin install variables are not accessible, as package.json was unreachable/unreadable.FCMPlugin: Support for Gradle v4 or lower is deprecated. Please upgrade to a newer version.google-services.json not found, google-services plugin not applied. Push Notifications won’t work

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’.

Why it says package.json is not reachable? When building the app for android, do i need to explicitly copy the package.json file?

Pls help me to fix this. Thanks…

Did you findm the solution?

Hi, Sorry for the late reply. I was able to find a fix for this which I cannot remember now. But Anyway, I thought of updating Capacitor, Android and Ionic on my app. So after updating I am again facing the same issue. I still could not find a solution for it.

Were u able to fix it BTW ?

Ok, Finally my build is successful.

Actually you don’t have to worry about this whole FCMPlugin: Plugin install variables are not accessible, as package.json was unreachable/unreadable thing.

If you go to your node modules -> cordova-plugin-fcm-with-dependency-updated -> src -> android -> FCMPlugin.gradlem, you can see following dependencies section.

dependencies {
        // Load system enviroment defined values, or, if unavailable, plugin defaults
        def ANDROID_GOOGLE_SERVICES_VERSION = System.getenv('ANDROID_GOOGLE_SERVICES_VERSION') ?: '4.3.4'
        def ANDROID_GRADLE_TOOLS_VERSION = System.getenv('ANDROID_GRADLE_TOOLS_VERSION') ?: '4.1.0'      
        try {
            // Load configuration from install variables (package.json) two directories above
            def PLUGIN_CONFIG = new groovy.json.JsonSlurper().parseText(file("${projectDir}/../../package.json").text).cordova.plugins['cordova-plugin-fcm-with-dependecy-updated']
            ANDROID_GOOGLE_SERVICES_VERSION = PLUGIN_CONFIG.ANDROID_GOOGLE_SERVICES_VERSION
            ANDROID_GRADLE_TOOLS_VERSION = PLUGIN_CONFIG.ANDROID_GRADLE_TOOLS_VERSION
        } catch(Exception e0) {
            try {
                // Load configuration from install variables (package.json) three directories above
                def PLUGIN_CONFIG = new groovy.json.JsonSlurper().parseText(file("${projectDir}/../../../package.json").text).cordova.plugins['cordova-plugin-fcm-with-dependecy-updated']
                ANDROID_GOOGLE_SERVICES_VERSION = PLUGIN_CONFIG.ANDROID_GOOGLE_SERVICES_VERSION
                ANDROID_GRADLE_TOOLS_VERSION = PLUGIN_CONFIG.ANDROID_GRADLE_TOOLS_VERSION
            } catch(Exception e1) {
                def WARNING_STYLE = "${(char)27}[33;49"+"m"
                def DEFAULT_STYLE = "${(char)27}[39;49"+"m"
                print(WARNING_STYLE+"FCMPlugin: Plugin install variables are not accessible, as package.json was unreachable/unreadable."+DEFAULT_STYLE)                
            }
        }
        // Override config with project values if available
        ANDROID_GOOGLE_SERVICES_VERSION = rootProject.hasProperty('ANDROID_GOOGLE_SERVICES_VERSION') ? rootProject.ext.ANDROID_GOOGLE_SERVICES_VERSION : ANDROID_GOOGLE_SERVICES_VERSION
        ANDROID_GRADLE_TOOLS_VERSION = rootProject.hasProperty('ANDROID_GRADLE_TOOLS_VERSION') ? rootProject.ext.ANDROID_GRADLE_TOOLS_VERSION : ANDROID_GRADLE_TOOLS_VERSION
        // Avoid use "GRADLE_VERSION" because jitpack sets this like a environment variable
        classpath "com.android.tools.build:gradle:${ANDROID_GRADLE_TOOLS_VERSION}"
        classpath "com.google.gms:google-services:${ANDROID_GOOGLE_SERVICES_VERSION}"
    }

In the try catch block there, you can see the error message that we are talking about.

If you read the whole section carefully, you can understand that the first line assigns a value to ANDROID_GOOGLE_SERVICES_VERSION . If System env value is not available, the value ‘4.3.4’ is assigned to it.

The second line assigns 4.1.0 to ANDROID_GRADLE_TOOLS_VERSION if the corresponding env value is not available.

the lines that follow above two lines check if the package.json contains values that should be assigned to them overriding the values that were assigned previously. (4.3.4 and 4.1.0)

But our package.json file does not contain those values. I dont know about the scenarios with cordova. But I am using capacitor. My Package.json file does not contain those values.

However, the code prints the error "FCMPlugin: Plugin install variables are not accessible, as package.json was unreachable/unreadable" since it cannot find values from package.json file which we can safely ignore since we have already assigned values for them.


So, just ignore this. It works with this warning. You really don’t have to care.

Verified by installing the app in a real device. Push messages work fine. :slight_smile:


Don’t forget to place the google-services.json file in android -> app directory.

Cheers !!