ostownsville / cordova-plugin-fcm

Google FCM Push Notifications Cordova Plugin
21 stars 17 forks source link

Android build is failing: FCMPlugin.gradle' line: 20 #42

Open wdarking opened 6 years ago

wdarking commented 6 years ago

Cordova: 8.0.0 Ionic: 3.19.1 Node: 8.9.4

cordova build android output:

BUILD FAILED
 in 0s

(node:10845) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): Error: /home/dev/work/app/platforms/android/gradlew: Command failed with exit code 1 Error output:
FAILURE: Build failed with an exception.

* Where:
Script '/home/dev/work/app/platforms/android/cordova-plugin-fcm/app-FCMPlugin.gradle' line: 20

* What went wrong:
A problem occurred evaluating project ':app'.
> com.google.common.util.concurrent.ExecutionError: java.lang.NoClassDefFoundError: com/android/build/gradle/AppPlugin$AppModelBuilder

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

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

BUILD FAILED in 0s
(node:10845) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

config.xml

<?xml version='1.0' encoding='utf-8'?>
<widget id="com.app.test" version="0.8.1" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">
    <name>App Test</name>
    <description>some description</description>
    <author email="wdarking@gmail.com" href="http://ionicframework.com/">App Test</author>
    <content src="index.html" />
    <access origin="*" />
    <allow-navigation href="*" />
    <allow-intent href="http://*/*" />
    <allow-intent href="https://*/*" />
    <allow-intent href="tel:*" />
    <allow-intent href="sms:*" />
    <allow-intent href="mailto:*" />
    <allow-intent href="geo:*" />
    <preference name="orientation" value="portrait" />
    <preference name="AndroidPersistentFileLocation" value="Compatibility" />
    <preference name="webviewbounce" value="true" />
    <preference name="UIWebViewBounce" value="true" />
    <preference name="DisallowOverscroll" value="false" />
    <preference name="ScrollEnabled" value="false" />
    <preference name="android-minSdkVersion" value="16" />
    <preference name="BackupWebStorage" value="none" />
    <preference name="SplashMaintainAspectRatio" value="true" />
    <preference name="FadeSplashScreenDuration" value="300" />
    <preference name="SplashShowOnlyFirstTime" value="false" />
    <preference name="SplashScreen" value="screen" />
    <preference name="SplashScreenDelay" value="3000" />
    <platform name="android"></platform>
    <platform name="ios"></platform>

    <allow-navigation href="http://10.1.1.88:8100" />

    <plugin name="ionic-plugin-keyboard" spec="^2.2.1" />
    <plugin name="cordova-plugin-whitelist" spec="^1.3.3" />
    <plugin name="cordova-plugin-device" spec="^1.1.7" />
    <plugin name="cordova-plugin-splashscreen" spec="^4.1.0" />
    <plugin name="cordova-plugin-fcm" spec="git+https://github.com/ostownsville/cordova-plugin-fcm.git" />
    <plugin name="cordova-plugin-app-event" spec="^1.2.1" />
    <plugin name="cordova-sqlite-storage" spec="^2.2.1" />
    <plugin name="cordova-plugin-file" spec="^4.3.3" />
    <plugin name="cordova-plugin-code-push" spec="^1.11.7" />
    <plugin name="cordova-plugin-statusbar" spec="^2.4.1" />
    <plugin name="cordova-plugin-badge" spec="^0.8.7" />
    <plugin name="de.appplant.cordova.plugin.local-notification" spec="^0.8.5" />

    <engine name="ios" spec="~4.4.0" />
    <engine name="android" spec="7.0.0" />
</widget>

referenced app-FCMPlugin.gradle file:

android {
    defaultConfig {
          multiDexEnabled true
    }
}

buildscript {
    repositories {
            jcenter()
        maven { url 'https://maven.google.com' }
        }
    dependencies {
        classpath 'com.android.tools.build:gradle:+'
        classpath 'com.google.gms:google-services:3.1.1'
    }
}
// apply plugin: 'com.google.gms.google-services'
// class must be used instead of id(string) to be able to apply plugin from non-root gradle file
ext.postBuildExtras = {
    apply plugin: com.google.gms.googleservices.GoogleServicesPlugin // <--- this is line 20
}

It was working ok a few days ago, but recently the build started to fail. Anyone is having the same problem? What could it be?

ricrempel commented 6 years ago

Same problem here, all of a sudden. Have already tried cordova clean, manually cleaning gradle cache, removing and re-adding platform, starting project from scratch...

Commenting out app-FCMPlugin.gradle' line: 20 will have the app build, but then the plugin doesn't work well -- couldn't use FCMPlugin.getToken() for instance.

chrisjpalmer commented 6 years ago

I can confirm I am having the same issue. Did the same thing... wiped out the line 20 then plugin stops working => I debugged the code where the token is retrieved and an exception occurs.

But I seriously don't understand any of this gradle stuff. If some genius could come a long and fix it, that would be awesome.

chrisjpalmer commented 6 years ago

Here's a dirty hack to get it working. I have no idea about the long term fix however:

go to platforms/android/cordova-plugin-fcm and open up the gradle file inside. Make it look like this: image

go to platforms/android/build.gradle Find the lines of code which have image

And add the following lines around them (above and below) image

Have your project open in android studio and go Tools > Android > SYnc Project with Gradle Files.

Build and it should work

chrisjpalmer commented 6 years ago

Basically I came across this solution by going back to basics according to the documentation.

https://developers.google.com/android/guides/google-services-plugin

fatimac commented 6 years ago

Same issue here. It was working the last time I build but now it give me an error

FAILURE: Build failed with an exception.

  • Where: Script '/cordova-plugin-fcm/customer-FCMPlugin.gradle' line: 20

  • What went wrong: A problem occurred evaluating root project 'www_android'.

    com.google.common.util.concurrent.ExecutionError: java.lang.NoClassDefFoundError: com/android/build/gradle/AppPlugin$AppModelBuilder

luigi37 commented 6 years ago

same issue here... any stable fix?

luigi37 commented 6 years ago

Chris Workaround does work.

I copy and paste the text to help others avoiding typos:

go to platforms/android/cordova-plugin-fcm and open up the gradle file inside.

Change the file from:

android {
    defaultConfig {
                multiDexEnabled true
    }
}

buildscript {
    repositories {
            jcenter()
                        maven { url 'https://maven.google.com' }
        }
    dependencies {
        classpath 'com.android.tools.build:gradle:+'
        classpath 'com.google.gms:google-services:3.1.1'
    }
}
// apply plugin: 'com.google.gms.google-services'
// class must be used instead of id(string) to be able to apply plugin from non-root gradle file
ext.postBuildExtras = {
    apply plugin: com.google.gms.googleservices.GoogleServicesPlugin
}

To:

android {
    defaultConfig {
                multiDexEnabled true
    }
}

//buildscript {
//  repositories {
//            jcenter()
//                      maven { url 'https://maven.google.com' }
//        }
//    dependencies {
//        classpath 'com.android.tools.build:gradle:+'
//        classpath 'com.google.gms:google-services:3.1.1'
//    }
//}
// apply plugin: 'com.google.gms.google-services'
// class must be used instead of id(string) to be able to apply plugin from non-root gradle file
//ext.postBuildExtras = {
//    apply plugin: com.google.gms.googleservices.GoogleServicesPlugin
//}

edit file platforms/android/build.gradle

change this:

dependencies {
    compile fileTree(dir: 'libs', include: '*.jar')
    // SUB-PROJECT DEPENDENCIES START
    debugCompile(project(path: "CordovaLib", configuration: "debug"))
    releaseCompile(project(path: "CordovaLib", configuration: "release"))
    compile "com.google.firebase:firebase-core:11.4.2"
    compile "com.google.firebase:firebase-messaging:11.4.2"
    compile "com.android.support:support-v4:24.1.1+"
    // SUB-PROJECT DEPENDENCIES END
}

to this:

buildscript {
    dependencies {
    classpath 'com.google.gms:google-services:3.1.1'
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: '*.jar')
    // SUB-PROJECT DEPENDENCIES START
    debugCompile(project(path: "CordovaLib", configuration: "debug"))
    releaseCompile(project(path: "CordovaLib", configuration: "release"))
    compile "com.google.firebase:firebase-core:11.4.2"
    compile "com.google.firebase:firebase-messaging:11.4.2"
    compile "com.android.support:support-v4:24.1.1+"
    // SUB-PROJECT DEPENDENCIES END
}

apply plugin: 'com.google.gms.google-services'
Maistho commented 6 years ago

Any idea on how to convert this into a patch? Afaik it's not possible to modify build.gradle directly from a plugin, so is it possible to still only use the plugins gradle-file?

luigi37 commented 6 years ago

no clue sorry :-(

wdarking commented 6 years ago

This issue may be related to Google's update on support package:

Google released the new version 28.0.0-alpha1 of com.android.support:support-v4 which is adding 2 new attributes(android:fontVariationSettings and android:ttcIndex). Some of the plugins are using the latest android-support libraries which results in unwanted incompatibilities.

source: https://stackoverflow.com/a/49200782/4687714

I've managed to solve my build problems using this workaround:

cordova platform rm android cordova platform add android

Option 2: Add next code snippet in build.gradle under platforms/android

configurations.all {
    resolutionStrategy.force 'com.android.support:support-v4:27.1.0'
}

Isn't a stable fix though

Maistho commented 6 years ago

@wdarking Cool, I've done a similar thing but still had some issues with multidex not being applied properly. Maybe I need to take a better look at that.

I guess that all plugins probably should do something like what they've done in cordova-plugin-googlemaps in order to properly support the correct android-support version. (Same with play services as well)