无法连接到Firebase云消息传递

时间:2016-09-12 18:44:56

标签: android firebase firebase-cloud-messaging

我正在尝试但无法连接到Firebase Cloud Mssaging服务。以下是错误:

background sync failed: SERVICE_NOT_AVAILABLE, retry in 320s

还有更多。这是log cat:

09-12 23:56:34.682 24569-24613/aboundinfo.mzkhan.firebaseapp I/OpenGLRenderer: Initialized EGL, version 1.4
09-12 23:56:34.712 24569-24613/aboundinfo.mzkhan.firebaseapp I/OpenGLRenderer: HWUI protection enabled for context ,  &this =0xa0922088 ,&mEglDisplay = 1 , &mEglConfig = 8 
09-12 23:56:34.712 24569-24613/aboundinfo.mzkhan.firebaseapp D/OpenGLRenderer: Enabling debug mode 0
09-12 23:56:34.852 24569-24569/aboundinfo.mzkhan.firebaseapp I/Timeline: Timeline: Activity_idle id: android.os.BinderProxy@305676cc time:224172576
09-12 23:56:34.862 24569-24615/aboundinfo.mzkhan.firebaseapp D/FirebaseInstanceId: background sync failed: SERVICE_NOT_AVAILABLE, retry in 10s
09-12 23:56:39.662 24776-24776/aboundinfo.mzkhan.firebaseapp:background_crash D/ResourcesManager: creating new AssetManager and set to /data/app/aboundinfo.mzkhan.firebaseapp-2/base.apk
09-12 23:56:39.862 24776-24776/aboundinfo.mzkhan.firebaseapp:background_crash W/DynamiteModule: Local module descriptor class for com.google.android.gms.crash not found.
09-12 23:56:39.912 24776-24776/aboundinfo.mzkhan.firebaseapp:background_crash D/ResourcesManager: creating new AssetManager and set to /data/app/com.google.android.gms-1/base.apk
09-12 23:56:39.912 24776-24776/aboundinfo.mzkhan.firebaseapp:background_crash W/ResourcesManager: Asset path '/system/framework/com.android.media.remotedisplay.jar' does not exist or contains no resources.
09-12 23:56:39.912 24776-24776/aboundinfo.mzkhan.firebaseapp:background_crash W/ResourcesManager: Asset path '/system/framework/com.android.location.provider.jar' does not exist or contains no resources.
09-12 23:56:39.972 24776-24776/aboundinfo.mzkhan.firebaseapp:background_crash D/ChimeraCfgMgr: Reading stored module config
09-12 23:56:40.002 24776-24776/aboundinfo.mzkhan.firebaseapp:background_crash I/DynamiteModule: Considering local module com.google.android.gms.crash:0 and remote module com.google.android.gms.crash:3
09-12 23:56:40.002 24776-24776/aboundinfo.mzkhan.firebaseapp:background_crash I/DynamiteModule: Selected remote version of com.google.android.gms.crash, version >= 3
09-12 23:56:40.032 24776-24776/aboundinfo.mzkhan.firebaseapp:background_crash D/ChimeraFileApk: Primary ABI of requesting process is armeabi-v7a
09-12 23:56:40.032 24776-24776/aboundinfo.mzkhan.firebaseapp:background_crash I/art: DexFile_isDexOptNeeded failed to open oat file '/data/dalvik-cache/arm/data@data@com.google.android.gms@app_chimera@m@00000008@DynamiteModulesC_GmsCore_prodlmp_xxhdpi_release.apk@classes.dex' for file location '/data/data/com.google.android.gms/app_chimera/m/00000008/DynamiteModulesC_GmsCore_prodlmp_xxhdpi_release.apk': Failed to open oat filename for reading: No such file or directory
09-12 23:56:40.032 24776-24776/aboundinfo.mzkhan.firebaseapp:background_crash D/ChimeraFileApk: Classloading successful. Optimized code found.
09-12 23:56:40.042 24776-24776/aboundinfo.mzkhan.firebaseapp:background_crash I/FirebaseCrashReceiverServiceImpl: FirebaseCrashReceiverServiceImpl created by ClassLoader com.google.android.chimera.container.internal.DelegateLastPathClassLoader[DexPathList[[zip file "/data/data/com.google.android.gms/app_chimera/m/00000008/DynamiteModulesC_GmsCore_prodlmp_xxhdpi_release.apk"],nativeLibraryDirectories=[/vendor/lib, /system/lib]]]
09-12 23:56:40.042 24776-24776/aboundinfo.mzkhan.firebaseapp:background_crash D/FirebaseCrashReceiverServiceImpl: onCreate
09-12 23:56:40.092 24776-24776/aboundinfo.mzkhan.firebaseapp:background_crash I/DynamiteModule: Considering local module com.google.android.gms.flags:0 and remote module com.google.android.gms.flags:1
09-12 23:56:40.092 24776-24776/aboundinfo.mzkhan.firebaseapp:background_crash I/DynamiteModule: Selected remote version of com.google.android.gms.flags, version >= 1
09-12 23:56:40.172 24776-24776/aboundinfo.mzkhan.firebaseapp:background_crash I/FirebaseCrashSenderServiceImpl: FirebaseCrashSenderServiceImpl created by ClassLoader com.google.android.chimera.container.internal.DelegateLastPathClassLoader[DexPathList[[zip file "/data/data/com.google.android.gms/app_chimera/m/00000008/DynamiteModulesC_GmsCore_prodlmp_xxhdpi_release.apk"],nativeLibraryDirectories=[/vendor/lib, /system/lib]]]
09-12 23:56:40.172 24776-24776/aboundinfo.mzkhan.firebaseapp:background_crash D/FirebaseCrashSenderServiceImpl: onCreate
09-12 23:56:44.732 24569-24592/aboundinfo.mzkhan.firebaseapp W/DynamiteModule: Local module descriptor class for com.google.firebase.auth not found.
09-12 23:56:44.972 24569-25015/aboundinfo.mzkhan.firebaseapp D/FirebaseInstanceId: background sync failed: SERVICE_NOT_AVAILABLE, retry in 20s
09-12 23:57:05.042 24569-25603/aboundinfo.mzkhan.firebaseapp D/FirebaseInstanceId: background sync failed: SERVICE_NOT_AVAILABLE, retry in 40s
09-12 23:57:45.172 24569-26405/aboundinfo.mzkhan.firebaseapp D/FirebaseInstanceId: background sync failed: SERVICE_NOT_AVAILABLE, retry in 80s
09-12 23:59:21.432 24569-28178/aboundinfo.mzkhan.firebaseapp D/FirebaseInstanceId: background sync failed: SERVICE_NOT_AVAILABLE, retry in 160s
09-13 00:02:10.832 24569-31836/aboundinfo.mzkhan.firebaseapp D/FirebaseInstanceId: background sync failed: SERVICE_NOT_AVAILABLE, retry in 320s
09-13 00:02:34.662 24569-24569/aboundinfo.mzkhan.firebaseapp V/ActivityThread: updateVisibility : ActivityRecord{3239ee18 token=android.os.BinderProxy@305676cc {aboundinfo.mzkhan.firebaseapp/aboundinfo.mzkhan.firebaseapp.MainActivity}} show : false
09-13 00:02:34.662 24569-24569/aboundinfo.mzkhan.firebaseapp D/FirebaseApp: Notifying background state change listeners.
09-13 00:02:34.842 24569-32479/aboundinfo.mzkhan.firebaseapp I/DynamiteModule: Considering local module com.google.android.gms.tagmanager:3 and remote module com.google.android.gms.tagmanager:3
09-13 00:02:34.842 24569-32479/aboundinfo.mzkhan.firebaseapp I/DynamiteModule: Selected local version of com.google.android.gms.tagmanager
09-13 00:02:34.932 24569-32479/aboundinfo.mzkhan.firebaseapp W/GoogleTagManager: Tag Manager's event handler WILL NOT be installed (no container loaded)
09-13 00:02:34.932 24569-32479/aboundinfo.mzkhan.firebaseapp I/GoogleTagManager: Tag Manager initilization took 66ms
09-13 00:02:56.442 24569-24569/aboundinfo.mzkhan.firebaseapp D/FirebaseApp: Notifying background state change listeners.
09-13 00:02:56.502 24569-24569/aboundinfo.mzkhan.firebaseapp I/Timeline: Timeline: Activity_idle id: android.os.BinderProxy@305676cc time:224554224
    public class MyFirebaseInstanceIDService extends FirebaseInstanceIdService {


    private static final String TAG = "MyFirebaseIIDService";

    @Override
    public void onTokenRefresh() {

        //Getting registration token
        String refreshedToken = FirebaseInstanceId.getInstance().getToken();

        //Displaying token on logcat
        Log.d(TAG, "Refreshed token: " + refreshedToken);

    }

    private void sendRegistrationToServer(String token) {
        //You can implement this method to store the token on your server
        //Not required for current project
    }
}
    public class MyFirebaseMessagingService extends FirebaseMessagingService {
    private static final String TAG = "MyFirebaseMsgService";

    @Override
    public void onMessageReceived(RemoteMessage remoteMessage) {
        //Displaying data in log
        //It is optional
        Log.d(TAG, "From: " + remoteMessage.getFrom());
        Log.d(TAG, "Notification Message Body: " + remoteMessage.getNotification().getBody());

        //Calling method to generate notification
        sendNotification(remoteMessage.getNotification().getBody());
    }

    //This method is only generating push notification
    //It is same as we did in earlier posts
    private void sendNotification(String messageBody) {
        Intent intent = new Intent(this, MainActivity.class);
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent,
                PendingIntent.FLAG_ONE_SHOT);

        Uri defaultSoundUri= RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
        NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
                .setSmallIcon(R.mipmap.ic_launcher)
                .setContentTitle("Firebase Push Notification")
                .setContentText(messageBody)
                .setAutoCancel(true)
                .setSound(defaultSoundUri)
                .setContentIntent(pendingIntent);

        NotificationManager notificationManager =
                (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

        notificationManager.notify(0, notificationBuilder.build());
    }
}
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="aboundinfo.mzkhan.firebaseapp">

    <uses-permission android:name="android.permission.INTERNET"/>
    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">

        <activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <service
            android:name=".firebase.MyFirebaseMessagingService"
            >
            <intent-filter>
                <action android:name="com.google.firebase.MESSAGING_EVENT"/>
            </intent-filter>
        </service>

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

我的傻瓜:

    apply plugin: 'com.android.application'

android {
    compileSdkVersion 24
    buildToolsVersion "24.0.2"

    defaultConfig {
        applicationId "aboundinfo.mzkhan.firebaseapp"
        minSdkVersion 16
        targetSdkVersion 24
        versionCode 1
        versionName "1.0"
        multiDexEnabled true
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:24.2.0'
    compile 'com.google.firebase:firebase-core:9.4.0'
    compile 'com.google.firebase:firebase-messaging:9.4.0'
    compile 'com.google.android.gms:play-services:9.4.0'
    compile 'com.google.firebase:firebase-analytics:9.0.0'
}
apply plugin: 'com.google.gms.google-services'

1 个答案:

答案 0 :(得分:0)

您是否在清单中添加了这两项服务?

    <service android:name=".gcm.CustomFcmListenerService">
        <intent-filter>
            <action android:name="com.google.firebase.MESSAGING_EVENT" />
        </intent-filter>
    </service>

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