java.lang.NoSuchMethodError:没有静态方法getDrawable(Landroid / content / Context; I)

时间:2017-06-12 10:43:14

标签: android socialize-sdk

将Socialize SDK集成到我的应用程序中。我还将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文件。

--------- 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文件。

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'

1 个答案:

答案 0 :(得分:2)

升级 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'