当使用Firebase和onesignal时,应用程序在第一次运行时崩溃

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了当使用Firebase和onesignal时,应用程序在第一次运行时崩溃相关的知识,希望对你有一定的参考价值。

最近,我已经将我的firebase和onesignal依赖项升级到最新版本,但是一个奇怪的事情发生了,在应用程序第一次安装后,我打开它,它会在1-2秒后直接粉碎,但是当你打开它时再次第二次,它表现正常而不会破碎。

这是我的gradle(app-level):

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

apply plugin: 'com.android.application'
apply plugin: 'io.fabric'

buildscript {
    repositories {
        maven { url 'https://plugins.gradle.org/m2/' }
    }
    dependencies {
        classpath 'gradle.plugin.com.onesignal:onesignal-gradle-plugin:0.11.2'
    }
}

repositories {
    maven { url 'https://maven.google.com' }
}


android {
    compileSdkVersion 27
    defaultConfig {
        applicationId "com.example.mohammed.skyquestionbank"
        minSdkVersion 19
        targetSdkVersion 27
        versionCode 1
        versionName "1.0"
        manifestPlaceholders = [
                onesignal_app_id               : 'my_id',
                // Project number pulled from dashboard, local value is ignored.
                onesignal_google_project_number: 'REMOTE'
        ]

        multiDexEnabled true

        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    compileOptions {
        targetCompatibility 1.8
        sourceCompatibility 1.8
    }
    dataBinding {
        enabled true
    }

}


dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    implementation 'com.android.support:appcompat-v7:27.1.1'
    implementation 'com.android.support:exifinterface:27.1.1'
    implementation 'com.android.support:multidex:1.0.3'
    implementation 'com.flaviofaria:kenburnsview:1.0.7'
    implementation 'com.squareup.picasso:picasso:2.71828'
    implementation 'com.onesignal:OneSignal:3.10.1'
    implementation 'com.android.support:support-v4:27.1.1'
    implementation 'com.android.support:design:27.1.1'
    implementation 'com.android.support:recyclerview-v7:27.1.1'
    implementation 'com.android.support:cardview-v7:27.1.1'
    implementation 'com.mikhaellopez:circularimageview:3.2.0'
    implementation 'com.android.support:customtabs:27.1.1'
    implementation 'com.android.support:support-media-compat:27.1.1'
    implementation 'com.android.support.constraint:constraint-layout:1.1.3'
    implementation 'com.google.firebase:firebase-auth:16.0.4'
    implementation 'com.firebaseui:firebase-ui-auth:4.2.0'
    implementation 'com.firebaseui:firebase-ui-database:4.0.1'
    implementation 'com.google.firebase:firebase-database:16.0.3'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
    implementation 'com.squareup.retrofit2:converter-gson:2.4.0'
    implementation 'com.squareup.retrofit2:converter-gson:2.4.0'
    implementation 'com.squareup.retrofit2:retrofit:2.4.0'
    implementation 'com.google.firebase:firebase-core:16.0.4'
    implementation 'com.crashlytics.sdk.android:crashlytics:2.9.5'
    implementation 'com.mikepenz:materialdrawer:6.0.9'
    implementation 'com.mikhaellopez:circularprogressbar:2.0.0'
    implementation 'com.zekapp.library:progreswheelview:1.1.5'
}

apply plugin: 'com.google.gms.google-services'

这里是根级别

buildscript {

    repositories {
        google()
        jcenter()
      maven {
          url 'https://maven.fabric.io/public'
      }

    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.2.0'
        classpath 'com.google.gms:google-services:4.0.1'

        classpath 'io.fabric.tools:gradle:1.25.4'


        // 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"}
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

这是粉碎日志:

--------- beginning of crash
10-11 00:26:41.282 5157-5157/com.example.mohammed.skyquestionbank      E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.example.mohammed.skyquestionbank, PID: 5157
    java.lang.NoSuchMethodError: No static method zzac()Lcom/google      /firebase/iid/zzap; in class Lcom/google/firebase/iid/zzap; or its super     classes (declaration of 'com.google.firebase.iid.zzap' appears in /data/app/com.example.mohammed.skyquestionbank-1/base.apk:classes2.dex)             atcom.google.firebase.messaging.FirebaseMessagingService.zzb(Unknown Source)
    at com.google.firebase.iid.zzb.onStartCommand(Unknown Source)
    at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:2864)
    at android.app.ActivityThread.access$2100(ActivityThread.java:144)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1376)
    at android.os.Handler.dispatchMessage(Handler.java:102)
    at android.os.Looper.loop(Looper.java:135)
    at android.app.ActivityThread.main(ActivityThread.java:5221)
    at java.lang.reflect.Method.invoke(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:372)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
10-11 00:26:41.288 1146-1146/? E/EGL_emulation: tid 1146:     eglCreateSyncKHR(1865): error 0x3004 (EGL_BAD_ATTRIBUTE)
答案

所以我自己解决了这个问题,最近版本的firebase-core和firebase-auth 16.0.4似乎有问题,因为他们刚刚发布了这个十月。我不得不将它们降级到16.0.3以匹配我的firebase-database 16.0.3。粉碎了。

以上是关于当使用Firebase和onesignal时,应用程序在第一次运行时崩溃的主要内容,如果未能解决你的问题,请参考以下文章

ios:当应用程序处于焦点时禁用警报通知(OneSignal)

OneSignal.setSubscription(true) 在 Android 上不起作用?

Onesignal,Ionic App:单击通知时打开特定视图不起作用

Android 应用程序未在 Com.onesignal 通知中启动单击

OneSignal 为每个应用程序安装创建多个用户记录

删除用户后可以将用户添加到 OneSignal 吗?