java.lang.NoSuchMethodError: No static method getDrawable(Landroid/content/Context;I)Landroid/graphics/drawable/Drawable;

java.lang.NoSuchMethodError: No static method getDrawable(Landroid/content/Context;I)Landroid/graphics/drawable/Drawable;

我将 Android Studio 更新到 2.2,我的项目将不再构建。我的 Activity 的 super.onCreate(savedInstanceState) 给我一个错误:

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/x.y.z-1/base.apk:classes32.dex)
                                                                     at android.support.v7.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:197)
                                                                     at android.support.v7.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:185)
                                                                     at android.support.v7.widget.AppCompatDrawableManager.checkVectorDrawableSetup(AppCompatDrawableManager.java:720)
                                                                     at android.support.v7.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:190)
                                                                     at android.support.v7.widget.TintTypedArray.getDrawableIfKnown(TintTypedArray.java:77)
                                                                     at android.support.v7.app.AppCompatDelegateImplBase.<init>(AppCompatDelegateImplBase.java:127)
                                                                     at android.support.v7.app.AppCompatDelegateImplV9.<init>(AppCompatDelegateImplV9.java:147)
                                                                     at android.support.v7.app.AppCompatDelegateImplV11.<init>(AppCompatDelegateImplV11.java:27)
                                                                     at android.support.v7.app.AppCompatDelegateImplV14.<init>(AppCompatDelegateImplV14.java:50)
                                                                     at android.support.v7.app.AppCompatDelegateImplV23.<init>(AppCompatDelegateImplV23.java:29)
                                                                     at android.support.v7.app.AppCompatDelegate.create(AppCompatDelegate.java:199)
                                                                     at android.support.v7.app.AppCompatDelegate.create(AppCompatDelegate.java:181)
                                                                     at android.support.v7.app.AppCompatActivity.getDelegate(AppCompatActivity.java:521)
                                                                     at android.support.v7.app.AppCompatActivity.onCreate(AppCompatActivity.java:71)
                                                                     at zz.yyy.xxx.activities.AsdActivity.onCreate(AsdActivity.java:12)
                                                                     at android.app.Activity.performCreate(Activity.java:6904)
                                                                     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1136)
                                                                     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3266)
                                                                     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3415)
                                                                     at android.app.ActivityThread.access00(ActivityThread.java:229)
                                                                     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1821)
                                                                     at android.os.Handler.dispatchMessage(Handler.java:102)
                                                                     at android.os.Looper.loop(Looper.java:148)
                                                                     at android.app.ActivityThread.main(ActivityThread.java:7325)
                                                                     at java.lang.reflect.Method.invoke(Native Method)
                                                                     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
                                                                     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)

我制作了一个全新的 Activity 来查看是否是我的代码导致了问题,但没有帮助。这是 activity:

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;

public class AsdActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_asd);
    }
}

这是我的 build.gradle(应用程序)

buildscript {
    repositories {
        maven { url 'https://maven.fabric.io/public' }
    }

    dependencies {
        classpath 'io.fabric.tools:gradle:1.+'

    }
}
apply plugin: 'com.android.application'
apply plugin: 'io.fabric'

repositories {
    maven { url 'https://maven.fabric.io/public' }
}

android {
    compileSdkVersion 24
    buildToolsVersion "23.0.3"

        defaultConfig {
           minSdkVersion 21
           targetSdkVersion 24
           ...
        }

    buildTypes {

        debug {
            ...
            minifyEnabled false
        }

        release {
            ...
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }

}

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    testCompile 'junit:junit:4.12'
    compile('com.crashlytics.sdk.android:crashlytics:2.5.5@aar') {
        transitive = true;
    }

    compile project(':ViewLib')
    compile files('libs/commons-io-2.5.jar')
    compile project(':GridHeaders')
    compile 'com.amazonaws:aws-android-sdk-s3:2.2.16'
    compile 'com.google.code.gson:gson:2.6.2'
    compile 'com.squareup.okhttp3:okhttp:3.2.0'
    compile 'com.github.franmontiel:PersistentCookieJar:v0.9.3'
    compile 'com.amazonaws:aws-android-sdk-mobileanalytics:2.2.9'
    compile('com.facebook.fresco:fresco:0.11.0') {
        exclude module: 'support-v4'
    }
    compile 'org.apache:pdfbox-android:1.8.9.0'
    compile 'com.android.support:appcompat-v7:24.2.1'
    compile 'com.android.support:design:24.2.1'
}

在这个错误之前我得到了这个:

在此之前我还有一个类似的错误。两者都通过更新我的支持库得到修复。现在我得到了最新的 (24.2.1) 版本的 appcompatv7 和设计库,所以我不知道我能做什么了。

我能够解决这个问题。在我的 /libs 文件夹下,我有一个用 gradle 编译的旧 android-support-v13.jar。我的应用程序尝试使用此 .jar 的 ContextCompat class,而 class 没有静态 getDrawable(Context) 方法。删除这个 .jar 解决了我的问题。