2017-06-12 64 views
1

我正在將Socialize SDK集成到我的app中。我也將我的Android Studio更新爲2.3.3。我的Activity的super.onCreate(savedInstanceState)給了我一個錯誤。這裏提出了同樣的問題'java.lang.NoSuchMethodError: No static method getDrawable(Landroid/content/Context;I)Landroid/graphics/drawable/Drawable;'。但是這並不能幫助我,因爲我的libs文件夾下沒有任何jar文件。java.lang.NoSuchMethodError:沒有靜態方法getDrawable(Landroid/content/Context; I)

--------- beginning of crash 
    06-12 16:07:41.954 16968-16968/com.jeyashri.kitchen.jeyashriskitchen E/AndroidRuntime: FATAL EXCEPTION: main 
                          Process: com.jeyashri.kitchen.jeyashriskitchen, PID: 16968 
                          java.lang.NoSuchMethodError: No static method getDrawable(Landroid/content/Context;I)Landroid/graphics/drawable/Drawable; in class Landroid/support/v4/content/ContextCompat; or its super classes (declaration of 'android.support.v4.content.ContextCompat' appears in /data/app/com.jeyashri.kitchen.jeyashriskitchen-1/base.apk:classes8.dex) 
                           at android.support.v7.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:201) 
                           at android.support.v7.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:189) 
                           at android.support.v7.widget.AppCompatDrawableManager.checkVectorDrawableSetup(AppCompatDrawableManager.java:710) 
                           at android.support.v7.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:194) 
                           at android.support.v7.widget.TintTypedArray.getDrawableIfKnown(TintTypedArray.java:81) 
                           at android.support.v7.app.AppCompatDelegateImplBase.<init>(AppCompatDelegateImplBase.java:129) 
                           at android.support.v7.app.AppCompatDelegateImplV9.<init>(AppCompatDelegateImplV9.java:152) 
                           at android.support.v7.app.AppCompatDelegateImplV11.<init>(AppCompatDelegateImplV11.java:29) 
                           at android.support.v7.app.AppCompatDelegateImplV14.<init>(AppCompatDelegateImplV14.java:53) 
                           at android.support.v7.app.AppCompatDelegateImplV23.<init>(AppCompatDelegateImplV23.java:31) 
                           at android.support.v7.app.AppCompatDelegateImplN.<init>(AppCompatDelegateImplN.java:31) 
                           at android.support.v7.app.AppCompatDelegate.create(AppCompatDelegate.java:200) 
                           at android.support.v7.app.AppCompatDelegate.create(AppCompatDelegate.java:184) 
                           at android.support.v7.app.AppCompatActivity.getDelegate(AppCompatActivity.java:518) 
                           at android.support.v7.app.AppCompatActivity.onCreate(AppCompatActivity.java:70) 
                           at com.jeyashri.kitchen.jeyashriskitchen.Activity.MainActivity.onCreate(MainActivity.java:60) 
                           at android.app.Activity.performCreate(Activity.java:6679) 
                           at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118) 
                           at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2618) 
                           at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2726) 
                           at android.app.ActivityThread.-wrap12(ActivityThread.java) 
                           at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1477) 
                           at android.os.Handler.dispatchMessage(Handler.java:102) 
                           at android.os.Looper.loop(Looper.java:154) 
                           at android.app.ActivityThread.main(ActivityThread.java:6119) 
                           at java.lang.reflect.Method.invoke(Native Method) 
                           at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886) 
                           at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776) 

下面是我的gradle文件的id。

apply plugin: 'com.android.application' 

android { 
    compileSdkVersion 26 
    buildToolsVersion "26.0.0" 
    defaultConfig { 
     applicationId "com.jeyashri.kitchen.jeyashriskitchen" 
     minSdkVersion 21 
     targetSdkVersion 26 
     versionCode 1 
     versionName "1.0" 
     testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 
     multiDexEnabled true 
     vectorDrawables.useSupportLibrary = true 
    } 
    buildTypes { 
     release { 
      minifyEnabled false 
      proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 
     } 
    } 
    sourceSets { 
     main { 
      java.srcDirs = ['src/main/java', 'src/main/java/com.jeyashri.kitchen.jeyashrikitchen.Fragments', 'src/main/java/Fragements'] 
     } 
    } 
} 

android { 
    configurations.all { 
     resolutionStrategy.force 'com.google.code.findbugs:jsr305:1.3.9' 
    } 
} 

dependencies { 
    compile fileTree(include: ['*.jar'], dir: 'libs') 
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { 
     exclude group: 'com.android.support', module: 'support-annotations' 
    }) 
    //compile 'com.android.support:appcompat-v7:25.3.1' 
    //compile 'com.android.support:design:25.3.1' 
    compile 'com.android.support.constraint:constraint-layout:1.0.2' 
    testCompile 'junit:junit:4.12' 
    compile 'com.socialize:facebook:3.1.6' 
    compile 'com.socialize:ioc:3.1.6' 
    compile 'com.socialize:loopy:3.1.7' 
    compile 'com.socialize:library:3.1.7' 
    compile 'com.google.android.gms:play-services-ads:8.4.0' 
    compile 'com.google.apis:google-api-services-youtube:v3-rev176-1.22.0' 
    //compile 'com.android.support:appcompat-v7:26.0.0-alpha1' 
    compile 'com.android.support:appcompat-v7:26.+' 
    compile 'com.android.support:design:26.0.0-alpha1' 
} 

只有當我在gradle中添加下面的文件時,纔會出現此問題。否則應用程序無崩潰運行。

compile 'com.socialize:facebook:3.1.6' 
    compile 'com.socialize:ioc:3.1.6' 
    compile 'com.socialize:loopy:3.1.7' 
    compile 'com.socialize:library:3.1.7' 
+0

嘗試添加在我的/ libs文件夾我有一箇舊的Android支持,v13.jar那跟編譯的gradle。您的應用程序試圖使用此.jar的ContextCompat類,並且該類沒有靜態getDrawable(Context)方法。刪除這個.jar解決了問題。 –

+0

在libs文件夾中我沒有​​任何jar文件。 – Siva

回答

1

升級gms:play-services版本。

不要

compile 'com.google.android.gms:play-services-ads:8.4.0' 

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