FCM通知:无法初始化

时间:2016-07-07 05:50:50

标签: android firebase firebase-cloud-messaging

我是firebase的新手,我想实施Firebase云消息传递(FCM)我正面临着开始使用它的问题。 firebase没有初始化。谢谢你的帮助。

的build.gradle

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.1.0'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
        classpath 'com.google.gms:google-services:3.0.0'
    }
}

allprojects {
    repositories {
        jcenter()
    }
}

build.gradle(app)

apply plugin: 'com.android.application'

android {
    compileSdkVersion 24
    buildToolsVersion "24.0.0"

    defaultConfig {
        applicationId "com.example.sai_praneeth7777.hasportal"
        minSdkVersion 21
        targetSdkVersion 24
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:24.0.0'

    compile 'com.google.firebase:firebase-crash:9.2.0'
    compile 'com.google.firebase:firebase-messaging:9.2.0'

    compile 'com.mcxiaoke.volley:library:1.0.18'
    compile 'com.google.code.gson:gson:2.4'

    compile 'com.android.support:cardview-v7:24.0.0'
}

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

这是logcat

07-06 19:17:00.397 18894-18894/ D/FirebaseApp: com.google.firebase.auth.FirebaseAuth is not linked. Skipping initialization.
07-06 19:17:00.482 18894-18894/ W/GooglePlayServicesUtil: Google Play services out of date.  Requires 9256000 but found 9080280
07-06 19:17:00.483 18894-18894/ I/DynamiteModule: Considering local module com.google.android.gms.flags:1 and remote module com.google.android.gms.flags:0
07-06 19:17:00.487 18894-18894/ I/DynamiteModule: Selected local version of com.google.android.gms.flags
07-06 19:17:00.501 18894-18894/ W/ResourcesManager: Asset path '/system/framework/com.android.media.remotedisplay.jar' does not exist or contains no resources.
07-06 19:17:00.501 18894-18894/ W/ResourcesManager: Asset path '/system/framework/com.android.location.provider.jar' does not exist or contains no resources.
07-06 19:17:00.510 18894-18894/ W/DynamiteModule: Local module descriptor class for com.google.android.gms.crash not found.
07-06 19:17:00.517 18894-18894/ W/GooglePlayServicesUtil: Google Play services out of date.  Requires 9256000 but found 9080280
07-06 19:17:00.517 18894-18894/ I/DynamiteModule: Considering local module com.google.android.gms.crash:0 and remote module com.google.android.gms.crash:0
07-06 19:17:00.527 18894-18894/ E/FirebaseCrash: Failed to initialize crash reporting
com.google.firebase.crash.internal.zzg$zza: com.google.android.gms.internal.zzsj$zza: No acceptable module found. Local version is 0 and remote version is 0.
at com.google.firebase.crash.internal.zzg.zzbq(Unknown Source)
at com.google.firebase.crash.FirebaseCrash.<init>(Unknown Source)
at com.google.firebase.crash.FirebaseCrash.getInstance(Unknown Source)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.google.firebase.FirebaseApp.zza(Unknown Source)
at com.google.firebase.FirebaseApp.initializeApp(Unknown Source)
at com.google.firebase.FirebaseApp.initializeApp(Unknown Source)
at com.google.firebase.FirebaseApp.zzeh(Unknown Source)
at com.google.firebase.provider.FirebaseInitProvider.onCreate(Unknown Source)
at android.content.ContentProvider.attachInfo(ContentProvider.java:1686)
at android.content.ContentProvider.attachInfo(ContentProvider.java:1655)
at com.google.firebase.provider.FirebaseInitProvider.attachInfo(Unknown Source)
at android.app.ActivityThread.installProvider(ActivityThread.java:4964)
at android.app.ActivityThread.installContentProviders(ActivityThread.java:4559)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4499)
at android.app.ActivityThread.access$1500(ActivityThread.java:144)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1339)
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)
Caused by: com.google.android.gms.internal.zzsj$zza: No acceptable module found. Local version is 0 and remote version is 0.
at com.google.android.gms.internal.zzsj.zza(Unknown Source)
at com.google.firebase.crash.internal.zzg.zzbq(Unknown Source) 
at com.google.firebase.crash.FirebaseCrash.<init>(Unknown Source) 
at com.google.firebase.crash.FirebaseCrash.getInstance(Unknown Source) 
at java.lang.reflect.Method.invoke(Native Method) 
at java.lang.reflect.Method.invoke(Method.java:372) 
at com.google.firebase.FirebaseApp.zza(Unknown Source) 
at com.google.firebase.FirebaseApp.initializeApp(Unknown Source) 
at com.google.firebase.FirebaseApp.initializeApp(Unknown Source) 
at com.google.firebase.FirebaseApp.zzeh(Unknown Source) 
at com.google.firebase.provider.FirebaseInitProvider.onCreate(Unknown Source) 
at android.content.ContentProvider.attachInfo(ContentProvider.java:1686) 
at android.content.ContentProvider.attachInfo(ContentProvider.java:1655) 
at com.google.firebase.provider.FirebaseInitProvider.attachInfo(Unknown Source) 
at android.app.ActivityThread.installProvider(ActivityThread.java:4964) 
at android.app.ActivityThread.installContentProviders(ActivityThread.java:4559) 
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4499) 
at android.app.ActivityThread.access$1500(ActivityThread.java:144) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1339) 
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) 
07-06 19:17:00.558 18894-18894/ I/FA: App measurement is starting up, version: 9256
07-06 19:17:00.558 18894-18894/ I/FA: To enable debug logging run: adb shell setprop log.tag.FA VERBOSE
07-06 19:17:00.618 18894-18894/ I/FirebaseInitProvider: FirebaseApp initialization successful
07-06 19:17:00.682 18894-18925/ W/GooglePlayServicesUtil: Google Play services out of date.  Requires 9256000 but found 9080280
07-06 19:17:00.684 18894-18907/ I/art: Background partial concurrent mark sweep GC freed 2819(186KB) AllocSpace objects, 2(32KB) LOS objects, 53% free, 880KB/1904KB, paused 5.432ms total 47.807ms
07-06 19:17:00.700 18894-18894/ W/art: Before Android 4.1, method android.graphics.PorterDuffColorFilter android.support.graphics.drawable.VectorDrawableCompat.updateTintFilter(android.graphics.PorterDuffColorFilter, android.content.res.ColorStateList, android.graphics.PorterDuff$Mode) would have incorrectly overridden the package-private method in android.graphics.drawable.Drawable
07-06 19:17:00.855 18894-18927/ D/OpenGLRenderer: Render dirty regions requested: true
[ 07-06 19:17:00.881 18894:18894 D/         ]
HostConnection::get() New Host Connection established 0x7fe26aba3ec0, tid 18894
07-06 19:17:00.890 18894-18894/ D/Atlas: Validating map...
07-06 19:17:00.934 18894-18894/ W/FA: Service connection failed: ConnectionResult{statusCode=SERVICE_VERSION_UPDATE_REQUIRED, resolution=null, message=null}
07-06 19:17:00.983 18894-18907/ W/art: Suspending all threads took: 14.572ms
[ 07-06 19:17:01.050 18894:18927 D/         ]
HostConnection::get() New Host Connection established 0x7fe26d476180, tid 18927
07-06 19:17:01.064 18894-18927/ I/OpenGLRenderer: Initialized EGL, version 1.4
07-06 19:17:01.101 18894-18927/ D/OpenGLRenderer: Enabling debug mode 0
07-06 19:17:10.845 18894-18925/ I/FA: Tag Manager is not found and thus will not be used
07-06 19:17:10.847 18894-18925/ W/GooglePlayServicesUtil: Google Play services out of date.  Requires 9256000 but found 9080280
07-06 19:17:10.847 18894-18894/ W/FA: Service connection failed: ConnectionResult{statusCode=SERVICE_VERSION_UPDATE_REQUIRED, resolution=null, message=null}
07-06 19:18:19.553 18894-19743/ W/FA: Tasks have been queued for a long time
07-06 19:18:19.930 18894-18902/ W/art: Suspending all threads took: 215.213ms
07-06 19:18:20.050 18894-18907/ I/art: Background sticky concurrent mark sweep GC freed 910(82KB) AllocSpace objects, 3(48KB) LOS objects, 11% free, 1679KB/1904KB, paused 80.391ms total 305.959ms
07-06 19:18:20.059 18894-18907/ W/art: Suspending all threads took: 6.418ms

希望此信息有助于解决问题

2 个答案:

答案 0 :(得分:3)

如日志显示,您获得FirebaseApp initialization successful,这表示您的push-notification已成功注册。

如果您从控制台发送消息而您没有收到任何信息,请考虑以下事项:

  • 使用真实设备而不是模拟器检查推送通知。
  • 确保您的设备可以访问互联网。

答案 1 :(得分:0)

对我来说,我必须在清单中声明服务才能使其工作。实际上一切仍然有效,但我没有看到回调,日志说没有初始化,直到我将以下内容添加到Android清单:

<service
android:name=".MyFirebaseInstanceIDService">
<intent-filter>
    <action android:name="com.google.firebase.INSTANCE_ID_EVENT"/>
</intent-filter>

当然用您调用的任何内容替换 MyFirebaseInstanceIDService