2017-01-31 161 views
8

當我將我的目標sdk級別從23.0.2更改爲25.0.1.My應用程序崩潰在下面的行。 我該怎麼做才能避免這次事故? 請建議更改。java.lang.IllegalAccessError:方法'void android.support.v4.content.ContextCompat。'班'com.google.android.gms.iid.zzd'無法訪問'

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

錯誤日誌:

AndroidRuntime: FATAL EXCEPTION: AsyncTask #2 
Process: com.tuitoapp.admin, PID: 19012              java.lang.RuntimeException: An error occured while executing doInBackground() 
Caused by: java.lang.IllegalAccessError: Method 'void android.support.v4.content.ContextCompat.<init>()' is inaccessible to class 'com.google.android.gms.iid.zzd' (declaration of 'com.google.android.gms.iid.zzd' appears in /data/data/com.tuitoapp.admin/files/instant-run/dex/slice-com.google.android.gms-play-services-gcm-8.3.0_7fd6e981c2dc6578e4c382ecd19f08197a01f8b5-classes.dex) 
                     at com.google.android.gms.iid.zzd.zzdL(Unknown Source) 
                     at com.google.android.gms.iid.InstanceID.zza(Unknown Source) 
                     at com.google.android.gms.iid.InstanceID.getInstance(Unknown Source) 

我的應用程序是的gradle:

// compile fileTree(dir: 'libs', include: ['*.jar']) 
    testCompile 'junit:junit:4.12' 
    compile 'org.achartengine:achartengine:1.2.0' 
    compile('com.crashlytics.sdk.android:crashlytics:[email protected]') { 
     transitive = true; 
    } 
    compile 'org.jsoup:jsoup:1.8.3' 
    compile 'com.mcxiaoke.volley:library:1.0.19' 
    compile 'com.android.support:appcompat-v7:25.1.1' 
    compile 'com.android.support:design:25.1.1' 
    compile 'com.pkmmte.view:circularimageview:1.1' 
    compile 'com.android.support:cardview-v7:25.0.1' 
    compile 'org.achartengine:achartengine:1.2.0' 
    compile 'com.github.npanigrahy:Custom-Calendar-View:v1.0' 
    compile 'com.github.siyamed:android-shape-imageview:[email protected]' 
    compile 'com.google.android.gms:play-services:8.3.0' 
    compile 'com.android.support:multidex:1.0.1' 
    // compile 'com.google.android.gms:play-services:9.8.0 
    // compile 'com.google.android.gms:play-services:9.8.0' 
    compile 'com.android.support:multidex:1.0.1' 
    compile 'pub.devrel:easypermissions:0.1.9' 
    compile 'com.github.ksoichiro:android-observablescrollview:1.6.0' 
    compile 'pl.droidsonroids.gif:android-gif-drawable:1.1.16' 
    compile 'com.miguelcatalan:materialsearchview:1.4.0' 
    compile 'com.github.rey5137:material:1.2.2' 
    compile 'uk.co.chrisjenx:calligraphy:2.1.0' 
    compile 'com.github.blackfizz:eazegraph:[email protected]' 
    compile 'com.github.PhilJay:MPAndroidChart:v2.1.6' 
    compile 'com.squareup.picasso:picasso:2.5.2' 
    compile 'com.nineoldandroids:library:2.4.0' 
    compile 'de.hdodenhof:circleimageview:2.1.0' 
    compile 'com.github.bumptech.glide:glide:3.7.0' 
    compile 'com.android.support:palette-v7:25.0.1' 
    compile 'com.nostra13.universalimageloader:universal-image-loader:1.9.5' 
    compile('com.weiwangcn.betterspinner:library:1.1.0') { 
     exclude group: 'com.android.support', module: 'appcompat-v7' 
    } 
    compile 'swarajsaaj:otpreader:1.0' 
    compile 'com.flipboard:bottomsheet-core:1.4.3' 
    compile 'com.flipboard:bottomsheet-commons:1.4.3' 
    compile 'com.riontech.staggeredtextgridview:staggeredtextgridview:1.0.1' 
    compile 'konifar:fab-transformation:1.0.0' 
    compile project(':flickabledialog') 
    compile 'com.android.support:support-v4:25.0.1' 
} 
apply plugin:'com.google.gms.google-services' 

和應用的熱門gradle這個是:

buildscript { 
    repositories { 
     jcenter() 
     mavenCentral() 
     maven { 
      url "https://jitpack.io" 
     } 
    } 
    dependencies { 
     classpath 'com.android.tools.build:gradle:2.2.3' 
//These two lines are added 
     classpath 'com.google.gms:google-services:1.5.0-beta2' 
     //classpath 'com.google.gms:google-services:3.0.0' 
     // classpath 'com.android.tools.build:gradle:2.0.0-alpha6' 
     classpath 'com.android.tools.build:gradle:1.3.0' 
     classpath 'com.novoda:bintray-release:0.3.4' 
     // classpath 'com.google.gms:google-services:2.0.0-alpha3' 
     // NOTE: Do not place your application dependencies here; they belong 
     // in the individual module build.gradle files 
    } 
} 

task clean(type: Delete) { 
    delete rootProject.buildDir 
} 

回答

0

在應用gradle這個文件,將您的谷歌播放服務依賴關係升級到最新版本。

compile 'com.google.android.gms:play-services:9.6.1' 
+0

我想這解決方案,但它給了錯誤:執行失敗的任務「:應用程序:processDebugGoogleServices」。 >請修正版本衝突,方法是更新google-services插件的版本(有關最新版本的信息,請訪問https://bintray.com/android/android-tools/com.google.gms.google-services /)或將com.google.android.gms的版本更新爲8.3.0。 –

+0

嘗試在項目gradle文件中設置最新的穩定版本的google-services。您已經設置了測試版本,並且不推薦。 –

+0

不要說要添加捆綁版本的谷歌服務。 –

1

試試這個:

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

也的build.gradle:

compile("com.google.android.gms:play-services-location:9.6.1") //if u are not using location you can skip this 
compile("com.google.android.gms:play-services-maps:9.6.1") 
compile("com.google.android.gms:play-services-gcm:9.6.1") 

而在你的Gradle應用:

刪除classpath 'com.google.gms:google-services:1.5.0-beta2'

也是爲什麼使用兩種不同的com.android.tools.build:gradle版本?

+0

它被評論..其實我試圖.. –

+0

做了答案的工作? @ rafsanahmad007 – SRam

+0

@SRam是的,它適用於我的情況... – rafsanahmad007

0

添加依賴

compile 'com.google.android.gms:play-services:10.0.1' 

刪除應用插件和

classpath 'com.google.gms:google-services: 
0

使用谷歌最新版本的播放服務

compile 'com.google.android.gms:play-services:11.0.4' 
相關問題