2016-06-30 78 views
0

我試圖用使用Android工作室Android應用谷歌的通知,以及我有這個類來註冊服務GCM 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); 
} 

} 

但是當我嘗試調用方法registerGCM()這說明我這個錯誤

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) 

專行

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

回答

0

對於您的錯誤IncompatibleClassChan geError,根據這個thread,這意味着你已經對庫進行了一些不兼容的二進制修改而不需要重新編譯客戶端代碼。有關此問題的更多信息,請閱讀上述鏈接。

因此,要解決您的問題,您可以按照此相關SO question中的解決方案。嘗試使用gradle依賴關係樹來解決這個錯誤。

運行gradle -q app:dependencies --configuration compile並檢查輸出這樣的條目:

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

而且更新您的依賴到最新版本,以解決這個問題。