2016-06-30 13 views
0

Ich habe versucht, die Google-Benachrichtigungen in Android-App mit Android Studio verwenden, auch ich habe diese Klasse Registration ServiceGCM in Android Studio

public class GCMRegistrationIntentService extends IntentService 
{ 

public static final String REGISTRATION_SUCCESS = "RegistrationSuccess"; 
public static final String REGISTRATION_ERROR = "RegistrationError"; 

public GCMRegistrationIntentService() { 
    super(""); 
} 


@Override 
protected void onHandleIntent(Intent intent) { 
    registerGCM(); 
} 

private void registerGCM() { 
    Intent registrationComplete = null; 
    String token = null; 
    try { 
     InstanceID instanceID = InstanceID.getInstance(getApplicationContext()); 
     token = instanceID.getToken(getString(R.string.gcm_defaultSenderId), GoogleCloudMessaging.INSTANCE_ID_SCOPE, null); 
     Log.w("GCMRegIntentService", "token:" + token); 
     //notify to UI that registration complete success 
     registrationComplete = new Intent(REGISTRATION_SUCCESS); 
     registrationComplete.putExtra("token", token); 
    } catch (Exception e) { 
     Log.w("GCMRegIntentService", "Registration error"); 
     registrationComplete = new Intent(REGISTRATION_ERROR); 
    } 
    //Send broadcast 
    LocalBroadcastManager.getInstance(this).sendBroadcast(registrationComplete); 
} 

} 

aber wenn ich versuche, die Methode registerGCM() aufrufen Es zeigt mir, diese Fehler

06-29 18:00:39.611 5494-5539/com.cisaApp.adrian.cisaappacueductos E/AndroidRuntime: FATAL EXCEPTION: IntentService[] 
                       Process: com.cisaApp.adrian.cisaappacueductos, PID: 5494 
                       java.lang.IncompatibleClassChangeError: The method 'java.io.File android.support.v4.content.ContextCompat.getNoBackupFilesDir(android.content.Context)' was expected to be of type virtual but instead was found to be of type direct (declaration of 'java.lang.reflect.ArtMethod' appears in /system/framework/core-libart.jar) 
                        at com.google.android.gms.iid.zzd.zzdL(Unknown Source) 
                        at com.google.android.gms.iid.zzd.<init>(Unknown Source) 
                        at com.google.android.gms.iid.zzd.<init>(Unknown Source) 
                        at com.google.android.gms.iid.InstanceID.zza(Unknown Source) 
                        at com.google.android.gms.iid.InstanceID.getInstance(Unknown Source) 
                        at com.cisaApp.adrian.cisaappacueductos.GCMRegistrationIntentService.registerGCM(GCMRegistrationIntentService.java:34) 
                        at com.cisaApp.adrian.cisaappacueductos.GCMRegistrationIntentService.onHandleIntent(GCMRegistrationIntentService.java:27) 
                        at android.app.IntentService$ServiceHandler.handleMessage(IntentService.java:65) 
                        at android.os.Handler.dispatchMessage(Handler.java:102) 
                        at android.os.Looper.loop(Looper.java:135) 
                        at android.os.HandlerThread.run(HandlerThread.java:61) 

speziell die Linie

InstanceID instanceID = InstanceID.getInstance(getApplicationContext()); 

Antwort

0

Für Ihre Fehler IncompatibleClassChan geError, entsprechend dieser thread, bedeutet dies, dass Sie einige inkompatible binäre Änderungen an der Bibliothek vorgenommen haben, ohne den Client-Code neu zu kompilieren. Weitere Informationen zu diesem Problem finden Sie unter dem obigen Link.

So für die Lösung für Ihr Problem können Sie die Lösung in diesem verwandten SO question folgen. Versuchen Sie, den Gradle-Abhängigkeitsbaum zu verwenden, um diesen Fehler zu beheben.

Run gradle -q app:dependencies --configuration compile und überprüfen Sie die Ausgabe für Einträge wie folgt aus:

+--- com.mcxiaoke.viewpagerindicator:library:2.4.1 
| \--- com.android.support:support-v4:+ -> 24.0.0-beta1 (*) 

Auch Ihre Abhängigkeiten auf die neueste Version aktualisieren, dieses Problem zu lösen.