java.lang.NoSuchMethodError: No static method isCtrlPressed(Landroid/view/KeyEvent;)Z in class Landroid/support/v4/view/KeyEventCompatHoneycomb;

java.lang.NoSuchMethodError: No static method isCtrlPressed(Landroid/view/KeyEvent;)Z in class Landroid/support/v4/view/KeyEventCompatHoneycomb;

我在执行应用程序时遇到了此类错误。

我的代码在支持库 24.2.0(Linux 操作系统中的 Android studio)中工作,当我 运行 此代码在 windows 操作系统中时我出现一些错误,对于该解决方案,我将我的支持库升级到 25.0.0 并解决了,但现在生成了下面提到的错误。

compileSdkVersion = 25
buildToolsVersion = '25.0.0'
supportLibraryVersion = '25.0.0'
targetSdkVersion = 25

E/UncaughtException: java.lang.NoSuchMethodError: No static method isCtrlPressed(Landroid/view/KeyEvent;)Z in class Landroid/support/v4/view/KeyEventCompatHoneycomb; or its super classes (declaration of 'android.support.v4.view.KeyEventCompatHoneycomb' appears in /data/app/com.xxx/base.apk:classes23.dex)
 at android.support.v4.view.KeyEventCompat$HoneycombKeyEventVersionImpl.isCtrlPressed(KeyEventCompat.java:120)
 at android.support.v4.view.KeyEventCompat.isCtrlPressed(KeyEventCompat.java:197)
 at android.support.v7.app.AppCompatActivity.dispatchKeyEvent(AppCompatActivity.java:532)
 at android.support.v7.view.WindowCallbackWrapper.dispatchKeyEvent(WindowCallbackWrapper.java:57)
 at android.support.v7.app.AppCompatDelegateImplBase$AppCompatWindowCallbackBase.dispatchKeyEvent(AppCompatDelegateImplBase.java:315)
 at com.android.internal.policy.PhoneWindow$DecorView.dispatchKeyEvent(PhoneWindow.java:2310)
 at android.view.ViewRootImpl$ViewPostImeInputStage.processKeyEvent(ViewRootImpl.java:4127)
 at android.view.ViewRootImpl$ViewPostImeInputStage.onProcess(ViewRootImpl.java:4089)
 at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3642)
 at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3695)
 at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3661)
 at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:3787)
 at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:3669)
 at android.view.ViewRootImpl$AsyncInputStage.apply(ViewRootImpl.java:3844)
 at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3642)
 at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3695)
 at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3661)
 at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:3669)
 at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3642)
 at android.view.ViewRootImpl.deliverInputEvent(ViewRootImpl.java:5922)
 at android.view.ViewRootImpl.doProcessInputEvents(ViewRootImpl.java:5896)
 at android.view.ViewRootImpl.enqueueInputEvent(ViewRootImpl.java:5857)
 at android.view.ViewRootImpl$ViewRootHandler.handleMessage(ViewRootImpl.java:3434)
 at android.os.Handler.dispatchMessage(Handler.java:102)
 at android.os.Looper.loop(Looper.java:148)
 at android.app.ActivityThread.main(ActivityThread.java:5417)
 at java.lang.reflect.Method.invoke(Native Method)
 at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
 at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)`

我解决了这个问题。 确保您的 buildToolVersion、CompileSdkVersion 和 targetSdkVersion 与您的支持库匹配。

在下面的配置中我得到了错误,

compileSdkVersion = 24
buildToolsVersion = '24.0.2'
targetSdkVersion = 24
supportLibraryVersion = '24.2.0'

所以,我更新到

compileSdkVersion = 25
buildToolsVersion = '25.0.0'
targetSdkVersion = 25
supportLibraryVersion = '25.0.1'

这解决了我的问题。确保它必须与主要发布版本匹配。