我把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.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)
我创建了一个全新的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 (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'
}
在出现这个错误之前,我遇到了这个问题:java.lang.NoSuchMethodError: No static method setOnApplyWindowInsetsListener。
在此之前,我还遇到了另一个类似的错误。通过更新我的支持库,两个错误都得到了解决。现在我已经拥有了最新版本(24.2.1)的appcompatv7和design库,所以我不知道该怎么做了。