可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
I downloaded yesterday Android Studio 2.1.3 (before I worked with 1.5) and now I have this exception:
java.lang.NoSuchMethodError: No static method setOnApplyWindowInsetsListener(Landroid/view/View;Landroid/support/v4/view/OnApplyWindowInsetsListener;)V in class Landroid/support/v4/view/ViewCompatLollipop; or its super classes (declaration of 'android.support.v4.view.ViewCompatLollipop'
that stops my app on setContentView in the MainActivity.
How can I solve this?
回答1:
I had same issue. I tried to run my code on another system with latest downloaded version of Android SDK (API 24). compileSdkVersion
of my code was 23. So, what I did is I opened app.iml
file (located in app module) and found version of components installed and updated them in build.gradle(app module) file.
Like,
compile 'com.android.support:design:23.1.1'
to
compile 'com.android.support:design:24.2.0'
And also updated compileSdkVersion
to 24, buildToolsVersion
to 24.0.1
, targetSdkVersion
to 24
.
Now my code runs fine.
Hope it helps.
回答2:
i have also face this type of error after update android studio 2.1.2 to 2.1.3
try MainActivity extends AppCompatActivity to
MainActivity extends Activity
回答3:
It's should be the same problem as java.lang.NoSuchMethodError: No static method setOnApplyWindowInsetsListener
Try to only use the 24.2.0 version for all the "com.android.support:xxx:..." in your gradle file.
BTW, now, support v4 is split (https://developer.android.com/topic/libraries/support-library/revisions.html#24-2-0-v4-refactor). Try to use only what you need ;)
回答4:
I have also face this type of error after update android studio 2.1.2 to 2.1.3, so I change AppCompat version from 23.4.0 to 24.2.0. Hope it will work! Good luck :)
回答5:
here is the issue :
i also faced this this issue once, and i found that i was using invalid dependency in my gradle :
compile 'com.android.support:design:24.2.1'
compile 'com.android.support:recyclerview-v7:24.2.1'
compile 'com.android.support:support-v4:24.2.1'
use this version of design or some other library, it solved my problem.
Thanks
回答6:
Changing the support library versions to the latest solved my problem.
Snapshot of the constants defined in gradle.properties:
BUILD_TOOLS_VERSION=23.0.2
COMPILE_SDK_VERSION=23
TARGET_SDK_VERSION=23
DESIGN_SUPPORT_VERSION=24.2.0 //changed from 23.2.0
APPCOMPAT_VERSION=24.2.0 //changed from 23.2.0
ANDROID_SUPPORT_VERSION=24.2.0 //changed from 23.2.0
Snapshot of the dependencies I added:
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile ("com.android.support:appcompat-v7:${project.APPCOMPAT_VERSION}"){
exclude module: 'support-v4'
}
compile "com.google.android.gms:play-services-analytics:${project.PLAY_SERVICES_VERSION}"
compile "com.google.android.gms:play-services-gcm:${project.PLAY_SERVICES_VERSION}"
compile "com.android.support:design:${project.DESIGN_SUPPORT_VERSION}"
compile "com.android.support:recyclerview-v7:${project.ANDROID_SUPPORT_VERSION}"
compile "com.android.support:cardview-v7:${project.ANDROID_SUPPORT_VERSION}"
compile "com.google.android.gms:play-services-location:${project.PLAY_SERVICES_VERSION}"
compile "com.google.android.gms:play-services-maps:${project.PLAY_SERVICES_VERSION}"
/* google maps*/
compile 'com.squareup.picasso:picasso:2.4.0'
compile 'com.google.code.gson:gson:2.5'
compile 'com.jakewharton:disklrucache:2.0.2'
compile project(':volley')
}
回答7:
I was facing the same issue.
These are my configuration:
compileSdkVersion 25
buildToolsVersion "25.0.2"
Dependency:
compile 'com.android.support:support-v4:25.3.1'
I tried many things but finally it worked by updating Android SDK platform tools.
Steps:
- Open SDK Manager
- Android SDK -> SDK tools
- Select Android SDK Platform - Tools (26.0.0) & Android SDK Tools (26.0.2)
- After downloading clean & build your project.