Reputation: 14818
When migrating to androidx I am getting above error when back pressing.
java.lang.NoSuchMethodError: No static method dispatchUnhandledKeyEventPre(Landroid/view/View;Landroid/view/KeyEvent;)Z in class Landroidx/core/view/ViewCompat; or its super classes (declaration of 'androidx.core.view.ViewCompat' appears in 1/split_lib_dependencies_apk.apk)
at androidx.appcompat.app.AppCompatDelegateImpl.dispatchKeyEvent(AppCompatDelegateImpl.java:1162)
at androidx.appcompat.app.AppCompatDelegateImpl$AppCompatWindowCallback.dispatchKeyEvent(AppCompatDelegateImpl.java:2529)
at androidx.appcompat.view.WindowCallbackWrapper.dispatchKeyEvent(WindowCallbackWrapper.java:59)
at com.android.internal.policy.DecorView.dispatchKeyEvent(DecorView.java:329)
at android.view.ViewRootImpl$ViewPostImeInputStage.processKeyEvent(ViewRootImpl.java:4792)
at android.view.ViewRootImpl$ViewPostImeInputStage.onProcess(ViewRootImpl.java:4759)
at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:4082)
at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:4135)
at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:4101)
at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:4109)
at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:4082)
at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:4135)
at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:4101)
at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:4257)
at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:4109)
at android.view.ViewRootImpl$AsyncInputStage.apply(ViewRootImpl.java:4314)
at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:4082)
at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:4135)
at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:4101)
at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:4109)
at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:4082)
at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:4135)
at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:4101)
at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:4290)
at android.view.ViewRootImpl$ImeInputStage.onFinishedInputEvent(ViewRootImpl.java:4451)
at android.view.inputmethod.InputMethodManager$PendingEvent.run(InputMethodManager.java:2434)
at android.view.inputmethod.InputMethodManager.invokeFinishedInputEventCallback(InputMethodManager.java:1998)
at android.view.inputmethod.InputMethodManager.finishedInputEvent(InputMethodManager.java:1989)
at android.view.inputmethod.InputMethodManager$ImeInputEventSender.onInputEventFinished(InputMethodManager.java:2411)
at android.view.InputEventSender.dispatchInputEventFinished(InputEventSender.java:141)
at android.os.MessageQueue.nativePollOnce(Native Method)
at android.os.MessageQueue.next(MessageQueue.java:323)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:6351)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:896)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:786)
I think in ViewCompat class does not have dispatchUnhandledKeyEventPre
method. I am using some third party dependency so I don't know which method causing it
Upvotes: 4
Views: 5818
Reputation: 1733
The accepted answer, while correct, shall become obsolete in the near future when newer versions of appcompat
will be released since the answer is very specific to a particular time frame.
The general answer is that this happens when you are using different mixed versions of appcompat
(appcompat library) in your project, they tend to be incompatible with each other more often. You must check if you are using the latest version of the appcompat library every time you update some APIs through the SDK Manager. It is rather very easy to update if you are using Android Studio.
Go to your build.gradle (Module: app)
and look into the dependencies. The gradle linter will most probably already show you the error that you are using different versions of the appcompat library and whether a newer version is available or not. If you hover over those highlighted lines, it shall give you all the information you require including what version you are using and what is the latest available and whether all of the dependencies are on the same version or not. Follow the prompts, fix them and then run a gradle sync
and you should be fine.
For example, I was using mixed versions of com.android.support:appcompat-v7:28.0.0-alpha3
, com.android.support:design:28.0.0
and com.android.support.constraint:constraint-layout:1.1.2
while the latest were v28.0.0
and v1.1.3
.
Hope this helps.
Upvotes: 2
Reputation: 551
For me, going to the gradle.build file and making sure that all the dependencies are up-to-date (new versions) fixed this problem.
Upvotes: 3