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

纵然是瞬间 提交于 2019-12-13 14:45:01

问题


I updated Android Studio to 2.2 and my project won't build anymore. My Activity's super.onCreate(savedInstanceState) gives me an error:

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.access$1100(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)

I made a completely new Activity to see if it was my code that was causing the problem but it didn't help. Here's the 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);
    }
}

And here's my build.gradle (app)

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'
}

Before this error I got this: java.lang.NoSuchMethodError: No static method setOnApplyWindowInsetsListener

And before that I had another similar error. Both were fixed by updating my support libraries. Now I got the newest (24.2.1) version of appcompatv7 and design libraries so I don't know how what I can do anymore.


回答1:


I was able to resolve this problem. Under my /libs folder I had an old android-support-v13.jar that got compiled with gradle. My app tried to use the ContextCompat class of this .jar and the class didn't have the static getDrawable(Context) method. Removing this .jar solved my problem.



来源:https://stackoverflow.com/questions/39617770/java-lang-nosuchmethoderror-no-static-method-getdrawablelandroid-content-conte

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!