Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android App crashes when OneSignal push notifications are sent

Android app is crashing just after onesignal push notification is sent. I am getting this error. Tried looking at other stackoverflow answers but it didn't help.

Please check the code (build.gradle) & error below.

Dont understant why is it not working :P Please check the code (build.gradle) & error below.

FATAL EXCEPTION: Firebase-FirebaseMessagingService
    Process: com.mario.childhood.game.videogame, PID: 30163
    java.lang.AbstractMethodError: abstract method "void com.google.firebase.iid.zzb.zzd(android.content.Intent)"
        at com.google.firebase.iid.zzc.run(Unknown Source)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607)
        at com.google.android.gms.common.util.concurrent.zza.run(Unknown Source)
        at java.lang.Thread.run(Thread.java:760)

build.gradle

apply plugin: 'com.android.application'

android {
    compileSdkVersion 27
    defaultConfig {
        applicationId "com.myapp"
        minSdkVersion 15
        targetSdkVersion 27
        versionCode 3
        versionName "1.2"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        manifestPlaceholders = [onesignal_app_id: 'XXXX-310c-4776-ae83-XXXX',
                // Project number pulled from dashboard, local value is ignored.
                onesignal_google_project_number: '22978XXXX'
        ]
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:27.1.1'
    implementation 'com.android.support:cardview-v7:27.1.1'
    implementation 'com.android.support.constraint:constraint-layout:1.1.0'
    implementation 'com.anjlab.android.iab.v3:library:1.0.44'
    testImplementation 'junit:junit:4.12'
    implementation 'com.github.delight-im:Android-AdvancedWebView:v3.0.0'
    implementation 'com.google.firebase:firebase-ads:15.0.1'
    implementation 'com.onesignal:OneSignal:[3.9.1, 3.99.99]'
}

build.gradle

buildscript {

    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.2.0-alpha09'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        google()
        jcenter()
        maven { url "https://jitpack.io" }
        maven { url "https://maven.google.com" }
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}
like image 361
akkk Avatar asked May 27 '18 08:05

akkk


People also ask

How do I use OneSignal push notifications on Android?

Send Your First Push NotificationNavigate to the OneSignal dashboard. Select Check Subscribed Users. If everything went well, you should see a green pop-up message indicating that the connection was successful. You can proceed to create your first notification by clicking on the blue Send a Message button.

Does OneSignal sell data?

OneSignal does not share SDK information with third parties except those who process the data on behalf of OneSignal. Data is only shared with third parties if: If an End User or Client requests or authorizes.


1 Answers

You forgot to apply the OneSignal gradle plugin. According to the documentation, you should add

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

to the very top of your app/build.gradle

When applied to your file, it should look like this:

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


apply plugin: 'com.android.application'

android {
    compileSdkVersion 27
    defaultConfig {
        applicationId "com.myapp"
        minSdkVersion 15
        targetSdkVersion 27
        versionCode 3
        versionName "1.2"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        manifestPlaceholders = [onesignal_app_id: 'XXXX-310c-4776-ae83-XXXX',
                // Project number pulled from dashboard, local value is ignored.
                onesignal_google_project_number: '22978XXXX'
        ]
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:27.1.1'
    implementation 'com.android.support:cardview-v7:27.1.1'
    implementation 'com.android.support.constraint:constraint-layout:1.1.0'
    implementation 'com.anjlab.android.iab.v3:library:1.0.44'
    testImplementation 'junit:junit:4.12'
    implementation 'com.github.delight-im:Android-AdvancedWebView:v3.0.0'
    implementation 'com.google.firebase:firebase-ads:15.0.1'
    implementation 'com.onesignal:OneSignal:[3.9.1, 3.99.99]'
}
like image 93
Ondrej Karmazin Avatar answered Oct 29 '22 16:10

Ondrej Karmazin