Onesignal-android-sdk: Upgrade Firebase Messaging

Created on 13 May 2019  路  20Comments  路  Source: OneSignal/OneSignal-Android-SDK

I've just migrated our application to target Android 28, and upgrading various libraries including Firebase. However I am now getting a crash on occasion. I'm not certain but I believe it may be when the app receives a push message.

The issue seems to be that Gradle is resolving the com.google.firebase:firebase-messaging dependency to version 17.3.3, whereas the latest version supported by this library is 12.0.1 (note 12.1.0 doesn't exist). See dependency output below.

Would it be possible to upgrade the library to make use of the latest Firebase messaging library? Cheers

See https://mvnrepository.com/artifact/com.google.firebase/firebase-messaging?repo=google

+--- com.onesignal:OneSignal:3.10.8
|    +--- com.google.firebase:firebase-messaging:[10.2.1, 12.1.0) -> 17.3.3
|    |    +--- com.google.android.gms:play-services-basement:16.0.1 -> 16.2.0 (*)
|    |    +--- com.google.android.gms:play-services-tasks:16.0.1 (*)
|    |    +--- com.google.firebase:firebase-common:16.0.3 -> 17.0.0
|    |    |    +--- com.google.android.gms:play-services-basement:16.0.1 -> 16.2.0 (*)
|    |    |    +--- com.google.android.gms:play-services-tasks:16.0.1 (*)
|    |    |    \--- com.google.auto.value:auto-value-annotations:1.6.3
|    |    +--- com.google.firebase:firebase-iid:17.0.3 -> 18.0.0
|    |    |    +--- com.google.android.gms:play-services-basement:16.0.1 -> 16.2.0 (*)
|    |    |    +--- com.google.android.gms:play-services-stats:16.0.1
|    |    |    |    \--- com.google.android.gms:play-services-basement:16.0.1 -> 16.2.0 (*)
|    |    |    +--- com.google.android.gms:play-services-tasks:16.0.1 (*)
|    |    |    +--- com.google.firebase:firebase-common:17.0.0 (*)
|    |    |    \--- com.google.firebase:firebase-iid-interop:16.0.1
|    |    |         +--- com.google.android.gms:play-services-base:16.0.1 (*)
|    |    |         \--- com.google.android.gms:play-services-basement:16.0.1 -> 16.2.0 (*)
|    |    \--- com.google.firebase:firebase-measurement-connector:17.0.1
|    |         \--- com.google.android.gms:play-services-basement:16.0.1 -> 16.2.0 (*)
|    +--- com.google.android.gms:play-services-location:[10.2.1, 12.1.0) -> 16.0.0 (*)
|    +--- com.google.android.gms:play-services-base:[10.2.1, 12.1.0) -> 16.0.1 (*)
|    +--- androidx.legacy:legacy-support-v4:1.0.0 (*)
|    \--- androidx.browser:browser:1.0.0 (*)

Crash stack trance:

2019-05-10 14:01:41.465 21506-21506/nz.co.zoomy.driver.debug E/AndroidRuntime: FATAL EXCEPTION: main
    Process: nz.co.zoomy.driver.debug, PID: 21506
    java.lang.RuntimeException: Unable to instantiate service com.google.firebase.messaging.FirebaseMessagingService: java.lang.ClassNotFoundException: com.google.firebase.messaging.FirebaseMessagingService
        at android.app.ActivityThread.handleCreateService(ActivityThread.java:3519)
        at android.app.ActivityThread.access$1300(ActivityThread.java:199)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1666)
        at android.os.Handler.dispatchMessage(Handler.java:106)
        at android.os.Looper.loop(Looper.java:193)
        at android.app.ActivityThread.main(ActivityThread.java:6669)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
     Caused by: java.lang.ClassNotFoundException: com.google.firebase.messaging.FirebaseMessagingService
        at java.lang.VMClassLoader.findLoadedClass(Native Method)
        at java.lang.ClassLoader.findLoadedClass(ClassLoader.java:738)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:363)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
        at android.app.AppComponentFactory.instantiateService(AppComponentFactory.java:103)
        at androidx.core.app.CoreComponentFactory.instantiateService(CoreComponentFactory.java:68)
        at android.app.ActivityThread.handleCreateService(ActivityThread.java:3514)
        at android.app.ActivityThread.access$1300(ActivityThread.java:199)聽
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1666)聽
        at android.os.Handler.dispatchMessage(Handler.java:106)聽
        at android.os.Looper.loop(Looper.java:193)聽
        at android.app.ActivityThread.main(ActivityThread.java:6669)聽
        at java.lang.reflect.Method.invoke(Native Method)聽
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)聽
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)聽
     Caused by: java.lang.IllegalAccessError: Class com.google.firebase.iid.zzb extended by class com.google.firebase.messaging.FirebaseMessagingService is inaccessible (declaration of 'com.google.firebase.messaging.FirebaseMessagingService' appears in /data/app/nz.co.zoomy.driver.debug-EZu12t6Eu3yar8zt0JtqWg==/base.apk!classes15.dex)
        at java.lang.Class.classForName(Native Method)
        at java.lang.Class.forName(Class.java:453)
        at java.lang.Class.forName(Class.java:378)
        at com.localytics.android.ManifestUtil.isClassSubclassedInManifest(ManifestUtil.java:116)
        at com.localytics.android.ManifestUtil.isServiceSubclassedInManifest(ManifestUtil.java:32)
        at com.localytics.android.PlayServicesUtils.isServiceInManifest(PlayServicesUtils.java:65)
        at com.localytics.android.PlayServicesUtils.cancelBackgroundTask(PlayServicesUtils.java:57)
        at com.localytics.android.ManifestHandler.cancelBackgroundTask(ManifestHandler.java:180)
        at com.localytics.android.ManifestHandler._onUploadCompleted(ManifestHandler.java:162)
        at com.localytics.android.BaseHandler._uploadCallback(BaseHandler.java:326)
        at com.localytics.android.BaseHandler$3.run(BaseHandler.java:129)
        at com.localytics.android.BaseProvider.runBatchTransaction(BaseProvider.java:403)
        at com.localytics.android.BaseHandler._runBatchTransactionOnProvider(BaseHandler.java:154)
        at com.localytics.android.BaseHandler.handleMessage(BaseHandler.java:125)
        at android.os.Handler.dispatchMessage(Handler.java:106)
        at android.os.Looper.loop(Looper.java:193)
        at android.os.HandlerThread.run(HandlerThread.java:65)
Compatibility Issue

Most helpful comment

@sdzshn3 Correct, as long as you have the OneSignal-Gradle-Plugin setup in your build.gradle or using one of the OneSignal wrapper SDKs (React Native, Cordova, etc) that automatically includes this it will select compatible versions of Firebase modules.

All 20 comments

@jsa-nic Thanks for reporting the issue. We will update the version in a future release.

In the meantime if you add implementation 'com.google.firebase:firebase-messaging:18.0.0' to your build.gradle this will force upgrade it.

You might need to upgrade the other components too:

implementation 'com.google.firebase:firebase-messaging:18.0.0'
implementation 'com.google.firebase:firebase-iid:18.0.0'

~Normaling add OneSignal-Gradle-Plugin would resolve a mixture of versions like this but it don't believe it accounts for 18.0.0 yet.~
Update: OneSignal-Gradle-Plugin version 0.12.2 now accounts for version 18.0.0 of Firebase.

@jsa-nic Thanks for reporting.

I am facing the same issue after I migrated to Android X.

Hope @jkasten2 @gdeglin @leemunroe @vsayer will fix ASAP.

I'm getting this when I upgrade to "com.google.firebase:firebase-core:16.0.9". Version 16.0.8 works fine.

@ravindu1024 thanks. will downgrade until issue is resolved.

@nilsorathiya For AndroidX see https://github.com/OneSignal/OneSignal-Android-SDK/issues/687#issuecomment-452526164 for how to enable Google Jetifier to resolve compilability with OneSignal.

Hello everyone, the issue has been resolved in the latest release. Thanks for your patience

Thanks for fixing it..
Now can I remove firebase messaging dependency from gradle after updating OneSignal SDK?

@sdzshn3 Correct, as long as you have the OneSignal-Gradle-Plugin setup in your build.gradle or using one of the OneSignal wrapper SDKs (React Native, Cordova, etc) that automatically includes this it will select compatible versions of Firebase modules.

Reopened this since folks are reporting this across several of our SDK wrappers

We are still investigating. Thanks everyone for your patience


nMvmQtKEKPDhltaF4DpuwrJUBGBsX982m57QSFeA7qn0oFXv1E9+/fIQ3z3epZBOvq3fAWEOO7sdMS4/Xh3PIGe/NMyvVeHe12LWHABlGVTiiP6M5fMqU33mFZIu8KLktsQk8+75i5b1k6yEJLYkHt3aGVOobazr7QE5h6gb098=

From a different thread:

what seemed to fix the issue was running "Sync Project With Gradle Files" in android studio after adding OneSignal-Gradle-Plugin and before building again.

Can folks attempt this and report back results? Cheers

What's the status on this problem? I was facing the:

Fatal Exception: java.lang.IllegalAccessError
Class com.google.firebase.iid.d0 extended by class com.google.firebase.messaging.FirebaseMessagingService is inaccessible (declaration of 'com.google.firebase.messaging.FirebaseMessagingService' appears in base.apk)
android.app.ActivityThread.handleCreateService

`
"Sync Project with Gradle Files" didn't really helped. What was working was to add

    implementation 'com.google.firebase:firebase-messaging:18.0.0'
    implementation 'com.google.firebase:firebase-iid:18.0.0'

to the dependencies. But that doesn't seem like a long term solution..

My app/build.gradle

apply plugin: 'com.onesignal.androidsdk.onesignal-gradle-plugin'

buildscript {
    repositories {
        // ...
        maven { url 'https://plugins.gradle.org/m2/' } // Gradle Plugin Portal
    }
    dependencies {
        // ...
        // OneSignal-Gradle-Plugin
        classpath 'gradle.plugin.com.onesignal:onesignal-gradle-plugin:[0.12.6, 0.99.99]'
    }
}



def localProperties = new Properties()
def localPropertiesFile = rootProject.file('local.properties')
if (localPropertiesFile.exists()) {
    localPropertiesFile.withReader('UTF-8') { reader ->
        localProperties.load(reader)
    }
}

def flutterRoot = localProperties.getProperty('flutter.sdk')
if (flutterRoot == null) {
    throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")
}

def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
if (flutterVersionCode == null) {
    flutterVersionCode = '1'
}

def flutterVersionName = localProperties.getProperty('flutter.versionName')
if (flutterVersionName == null) {
    flutterVersionName = '1.0'
}

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"

android {
    compileSdkVersion 28

    sourceSets {
        main.java.srcDirs += 'src/main/kotlin'
    }

    lintOptions {
        disable 'InvalidPackage'
    }

    defaultConfig {
        // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
        applicationId "se.ercutveckling.<app-name>"
        minSdkVersion 16
        targetSdkVersion 28
        versionCode flutterVersionCode.toInteger()
        versionName flutterVersionName
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }

    buildTypes {
        release {
            // TODO: Add your own signing config for the release build.
            // Signing with the debug keys for now, so `flutter run --release` works.
            signingConfig signingConfigs.debug
        }
    }
}

flutter {
    source '../..'
}

dependencies {
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test:runner:1.1.1'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
    implementation 'com.google.firebase:firebase-messaging:18.0.0'
    implementation 'com.google.firebase:firebase-iid:18.0.0'
    implementation 'com.onesignal:OneSignal:[3.11.4, 3.99.99]'
}
apply plugin: 'io.fabric'
apply plugin: 'com.google.gms.google-services'

@ercadev ,
Thanks for the details. Are you sure you set up the Gradle Plugin correctly? Please double check

@rgomezp sorry, how can I make sure I've set up the gradle plugin correctly? Im using flutter so not so much knowledge about android

Adding
implementation 'com.google.firebase:firebase-messaging:18.0.0' implementation 'com.google.firebase:firebase-iid:18.0.0'

fixed it for me, but yeah its not a great solution :)

@ercadev ,
Please read the README for the plugin: https://github.com/OneSignal/OneSignal-Gradle-Plugin

Also, try @dukaric1991 's recommendation

Closing this issue, firebase messaging lib is going to use version min (19.0.0) to start using Android X for major release in 4.0.0 (Release Date TBD).

@ercadev ,
Please read the README for the plugin: https://github.com/OneSignal/OneSignal-Gradle-Plugin

Also, try @dukaric1991 's recommendation

@rgomezp Flutter SDK setup say to put the code below on app/build.gradle

buildscript {
    repositories {
        maven { url 'https://plugins.gradle.org/m2/' }
    }
    dependencies {
        classpath 'gradle.plugin.com.onesignal:onesignal-gradle-plugin:[0.12.1, 0.99.99]'
    }
}
apply plugin: 'com.onesignal.androidsdk.onesignal-gradle-plugin'

While OneSignal Gradle Plugin README suggest to put the same code but on the root build.gradle
Which one should we follow? We are facing the same crash problem with latest OneSignal release for Flutter. Using implementation 'com.google.firebase:firebase-messaging:18.0.0' solved meanwhile

Followed the guideline :
https://github.com/OneSignal/OneSignal-Gradle-Plugin
instead of
https://documentation.onesignal.com/docs/flutter-sdk-setup because the gradle levels are wrong

Also added
implementation 'com.google.firebase:firebase-messaging:18.0.0'
implementation 'com.google.firebase:firebase-iid:18.0.0'
into app level gradle and solved

Closing this issue, firebase messaging lib is going to use version min (19.0.0) to start using Android X for major release in 4.0.0 (Release Date TBD).

Is there any chance to migrate Unity plugin to npm package same as Google did with all firebase and etc.?

Was this page helpful?
0 / 5 - 0 ratings