1

Ich bin neu in Android, meine Android-App stürzt ab, wenn ich versuche, eine Nachricht mit Firebase zu senden. Irgendwelche Ideen?Firebase-Nachrichten funktionieren nicht

Manifest.xml:

<uses-permission android:name="android.permission.INTERNET" /> 
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> 
<uses-permission android:name="android.permission.GET_ACCOUNTS" /> 
<uses-permission android:name="android.permission.MANAGE_ACCOUNTS" /> 
<uses-permission android:name="android.permission.USE_CREDENTIALS" /> 



<application 
    android:allowBackup="true" 
    android:icon="@mipmap/ic_launcher" 
    android:label="@string/app_name" 
    android:supportsRtl="true" 
    android:theme="@style/AppTheme"> 

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


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

RegistrationIntentService.java:

public class RegistrationIntentService extends FirebaseInstanceIdService { 


// abbreviated tag name 
static final String TAG = "RegIntentService"; 

@Override 
public void onTokenRefresh() { 
    // Get updated InstanceID token. 
    String refreshedToken = FirebaseInstanceId.getInstance().getToken(); 
     Log.d(TAG, "Refreshed token: " + refreshedToken); 


    } 
} 

MyFirebaseMessagingService:

public class MyFirebaseMessagingService extends FirebaseMessagingService{ 

@Override 
public void onMessageReceived(RemoteMessage remoteMessage) { 

    showNotification(remoteMessage.getData().get("message")); 

} 

private void showNotification(String message) { 

    Intent i = new Intent(this, Login.class); 
    i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); 

    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, i, PendingIntent.FLAG_UPDATE_CURRENT); 

    NotificationCompat.Builder builder = new NotificationCompat.Builder(this) 
      .setAutoCancel(true) 
      .setContentTitle("BookStore") 
      .setContentText(message) 
      .setSmallIcon(R.drawable.book) 
      .setContentIntent(pendingIntent); 

    NotificationManager manager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); 
    manager.notify(0, builder.build()); 

    } 


} 

MainActivity:

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_login); 

    FirebaseMessaging.getInstance().subscribeToTopic("test"); 
    FirebaseInstanceId.getInstance().getToken(); 

    } 

Logcat:

Process: gamingproject.sellmybooks, PID: 20478 
                      java.lang.NoSuchMethodError: No static method zzUr()Landroid/content/Intent; in class Lcom/google/firebase/iid/FirebaseInstanceIdInternalReceiver; or its super classes (declaration of 'com.google.firebase.iid.FirebaseInstanceIdInternalReceiver' appears in /data/app/gamingproject.sellmybooks-2/base.apk) 
                       at com.google.firebase.messaging.FirebaseMessagingService.zzz(Unknown Source) 
                       at com.google.firebase.iid.zzb.onStartCommand(Unknown Source) 
                       at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:3055) 
                       at android.app.ActivityThread.access$2200(ActivityThread.java:163) 
                       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1456) 
                       at android.os.Handler.dispatchMessage(Handler.java:102) 
                       at android.os.Looper.loop(Looper.java:135) 
                       at android.app.ActivityThread.main(ActivityThread.java:5536) 
                       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:1397) 
                       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1192) 
07-09 14:14:24.634 970-22768/? E/android.os.Debug: ro.product_ship = true 
07-09 14:14:24.634 970-22768/? E/android.os.Debug: ro.debug_level = 0x4f4c 
07-09 14:14:24.834 2415-22773/? E/SQLiteLog: (284) automatic index on crash_info_summary(package_name_touched) 
07-09 14:14:24.904 2415-22773/? E/SQLiteLog: (284) automatic index on crash_info_summary(package_name_touched) 
07-09 14:14:25.244 20342-20342/? E/WidgetProviderAssistiveLight: buildUpdate PORTRAIT 
07-09 14:14:27.314 268-268/? E/SMD: DCD OFF 
07-09 14:14:29.454 970-997/? E/ActivityManager: checkUser: useridlist=null, currentuser=0 
07-09 14:14:29.454 970-997/? E/ActivityManager: checkUser: useridlist=null, currentuser=0 
07-09 14:14:29.454 970-997/? E/ActivityManager: checkUser: useridlist=null, currentuser=0 
07-09 14:14:29.454 970-997/? E/ActivityManager: checkUser: useridlist=null, currentuser=0 
07-09 14:14:29.484 22805-22805/? E/Zygote: v2 
07-09 14:14:29.504 22805-22805/? E/SELinux: [DEBUG] get_category: variable seinfo: default sensitivity: NULL, cateogry: NULL 
07-09 14:14:29.704 22805-22805/gamingproject.sellmybooks E/AndroidRuntime: FATAL EXCEPTION: main 
                      Process: gamingproject.sellmybooks, PID: 22805 
                      java.lang.NoSuchMethodError: No static method zzUr()Landroid/content/Intent; in class Lcom/google/firebase/iid/FirebaseInstanceIdInternalReceiver; or its super classes (declaration of 'com.google.firebase.iid.FirebaseInstanceIdInternalReceiver' appears in /data/app/gamingproject.sellmybooks-2/base.apk) 
                       at com.google.firebase.messaging.FirebaseMessagingService.zzz(Unknown Source) 
                       at com.google.firebase.iid.zzb.onStartCommand(Unknown Source) 
                       at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:3055) 
                       at android.app.ActivityThread.access$2200(ActivityThread.java:163) 
                       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1456) 
                       at android.os.Handler.dispatchMessage(Handler.java:102) 
                       at android.os.Looper.loop(Looper.java:135) 
                       at android.app.ActivityThread.main(ActivityThread.java:5536) 
                       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:1397) 
                       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1192) 
07-09 14:14:29.714 970-22837/? E/android.os.Debug: ro.product_ship = true 
07-09 14:14:29.714 970-22837/? E/android.os.Debug: ro.debug_level = 0x4f4c 
07-09 14:14:29.794 2415-22838/? E/SQLiteLog: (284) automatic index on crash_info_summary(package_name_touched) 
07-09 14:14:29.834 2415-22838/? E/SQLiteLog: (284) automatic index on crash_info_summary(package_name_touched) 
07-09 14:14:30.214 970-1256/? E/Watchdog: [email protected] 473 
07-09 14:14:30.314 268-268/? E/SMD: DCD OFF 
07-09 14:14:33.314 268-268/? E/SMD: DCD OFF 
07-09 14:14:36.314 268-268/? E/SMD: DCD OFF 
07-09 14:14:39.314 268-268/? E/SMD: DCD OFF 
07-09 14:14:42.324 268-268/? E/SMD: DCD OFF 
07-09 14:14:45.314 268-268/? E/SMD: DCD OFF 
07-09 14:14:48.324 268-268/? E/SMD: DCD OFF 
07-09 14:14:51.324 268-268/? E/SMD: DCD OFF 
07-09 14:14:54.324 268-268/? E/SMD: DCD OFF 
07-09 14:14:56.004 970-1006/? E/PowerManagerService: handleSandman : startDreaming, but isDreaming false 
07-09 14:14:56.164 970-1040/? E/lights: write_int failed to open -1 
07-09 14:14:56.214 970-1070/? E/native: do suspend true 
07-09 14:14:56.344 245-245/? E/qdutils: int qdutils::getHDMINode(): Failed to open fb node 2 
07-09 14:14:56.344 245-245/? E/qdutils: int qdutils::getHDMINode(): Failed to find HDMI node 
07-09 14:14:56.564 245-578/? E/qdutils: int qdutils::getHDMINode(): Failed to open fb node 2 
07-09 14:14:56.564 245-578/? E/qdutils: int qdutils::getHDMINode(): Failed to find HDMI node 
07-09 14:14:57.004 1778-1778/? E/LibSecureUISvc: svc_sock_send_message(suisvc): Error sending data, -1 vs 4: Connection refused 
07-09 14:14:57.324 268-268/? E/SMD: DCD OFF 
07-09 14:15:00.214 970-1256/? E/Watchdog: [email protected] 474 
07-09 14:15:00.324 268-268/? E/SMD: DCD OFF 
07-09 14:15:01.064 1137-1137/? E/LSO: LSO Service is not yet ready!!! 
07-09 14:15:03.324 268-268/? E/SMD: DCD OFF 

gradle:

apply plugin: 'com.android.application' 


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

    // Dependency for Google Sign-In 
    compile 'com.google.android.gms:play-services-auth:9.2.0' 
    compile 'com.google.android.gms:play-services-plus:9.2.0' 
    compile 'com.google.android.gms:play-services-auth:9.2.0' 

    //Facebook Login 
    compile 'com.facebook.android:facebook-android-sdk:4.13.2' 

    // Dependency for Google Messages 
    compile 'com.google.firebase:firebase-messaging:9.2.0' 
} 



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

und

buildscript { 
    repositories { 
     jcenter() 
    } 
    dependencies { 
     classpath 'com.android.tools.build:gradle:2.1.2' 
     classpath 'com.google.gms:google-services:3.0.0' 

    } 
} 

Vielen Dank im Voraus.

+0

Ein Absturz immer auf die LogCat geschrieben und während wir potenziell in der Lage Um den Fehler in Ihrem Code zu erkennen, ist der StackTrace tausendmal hilfreicher. Bitte rufen Sie es ab und bearbeiten Sie Ihre Frage. – reVerse

+0

Ja, ich habe Logcat, aber ich verstehe das nicht – Carlo

+0

Veröffentlichen Sie Ihre Gradle-Datei, Sie vermissen wahrscheinlich eine Firebase-Lib. – alzee

Antwort

2

Ich habe die Lösung gefunden, ich habe dies geschrieben in meinem gradle:

compile 'com.google.firebase:firebase-messaging:9.0.2' 

statt dessen:

compile 'com.google.firebase:firebase-messaging:9.2.0' 
+1

Hallo Cario, 9.2.0 ist die empfohlene Version des Firebase-Messaging-SDK, können Sie klären, welche Version Sie verwenden? –

+1

java.lang.NoSuchMethodError kann anzeigen, dass auf dem Gerät noch nicht die neueste Version der Google Play-Dienste installiert ist. Können Sie die Version der auf dem Gerät installierten Google Play-Dienste bestätigen, so sollte diese Version 9.2.x lauten –