问题描述
今天,Android Studio(设置为稳定频道更新)已向我提供了将更新下载到Android支持存储库46.0.0的功能,所以我做到了.然后突然由于 MenuItemCompat.setOnActionExpandListener 而使我们的应用每次都崩溃.
Today Android Studio (set to Stable channel updates) has offered me to download an update to Android Support Repository 46.0.0, so I did it. Then suddenly our app has started to crash each time because of MenuItemCompat.setOnActionExpandListener.
是的,我应该已经有发行说明,但是我没有-这是事实.
Yes I've should have check release notes yet, but I did not - that's a fact.
现在我们的问题是什么-即使我们使用推荐的符号MenuItemCompat.setOnActionExpandListener,我们的应用程序也崩溃了,建议您使用MenuItemCompat.setOnActionExpandListener.废话.
Now what's our problem - Even we're using recommended notation MenuItemCompat.setOnActionExpandListener, our app crashed and we're advised to to use MenuItemCompat.setOnActionExpandListener. That's nonsense.
有人遇到同样的问题吗?或者仅仅是我们的代码问题吗?有人可以提供建议如何解决此问题或如何强制使用支持库的早期版本吗?假设25.1.0.问题似乎在26.0.0-alpha1中,很可能包含在支持存储库版本46中(请参阅该存储库的发行说明- https://developer.android.com/topic/libraries/support-library/revisions.html#26-0-0-alpha1 )
Is there someone who run into the same issue or is it just a matter of our code? Can someone provide an advice how to fix this or how to force to use earlier version of support library? Let's say 25.1.0. Issue seems to be in 26.0.0-alpha1 which is very likely included in Support Repository version 46 (see Release notes for that repository - https://developer.android.com/topic/libraries/support-library/revisions.html#26-0-0-alpha1)
顺便说一句.我们的build.gradle已经声明支持库的修复版本为25.1.0.似乎新的支持库在使用gradle构建时会以某种方式强制在内部使用其他版本.
Btw. our build.gradle already states fix version for support libs to 25.1.0. It seems new support library somehow forces to use other versions internally when built with gradle.
compile 'com.android.support:appcompat-v7:25.1.0'
compile 'com.android.support:design:25.1.0'
compile 'com.android.support:support-v4:25.1.0'
非常感谢您.
代码
MenuItemCompat.setOnActionExpandListener(menu.findItem(R.id.action_search), new MenuItemCompat.OnActionExpandListener() {
@Override
public boolean onMenuItemActionExpand(MenuItem menuItem) {
...
}
StackTrace的一部分
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.dev, PID: 4835
java.lang.UnsupportedOperationException: This is not supported, use MenuItemCompat.setOnActionExpandListener()
at android.support.v7.view.menu.MenuItemImpl.setOnActionExpandListener(MenuItemImpl.java:745)
at android.support.v4.view.MenuItemCompat.setOnActionExpandListener(MenuItemCompat.java:363)
at com.example.fragments.DevicesFragment.onCreateOptionsMenu(DevicesFragment.java:455)
at android.support.v4.app.Fragment.performCreateOptionsMenu(Fragment.java:2338)
at android.support.v4.app.FragmentManagerImpl.dispatchCreateOptionsMenu(FragmentManager.java:3070)
at android.support.v4.app.FragmentController.dispatchCreateOptionsMenu(FragmentController.java:328)
at android.support.v4.app.FragmentActivity.onCreatePanelMenu(FragmentActivity.java:321)
at android.support.v7.view.WindowCallbackWrapper.onCreatePanelMenu(WindowCallbackWrapper.java:95)
at android.support.v7.app.AppCompatDelegateImplBase$AppCompatWindowCallbackBase.onCreatePanelMenu(AppCompatDelegateImplBase.java:333)
at android.support.v7.app.AppCompatDelegateImplV9.preparePanel(AppCompatDelegateImplV9.java:1372)
at android.support.v7.app.AppCompatDelegateImplV9.doInvalidatePanelMenu(AppCompatDelegateImplV9.java:1652)
at android.support.v7.app.AppCompatDelegateImplV9$1.run(AppCompatDelegateImplV9.java:134)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
更新:这似乎与这个问题有关,因为我也尝试过这样做,并且同样的事情发生在我身上.无论如何,我都不想更新到API 26-带有Android Studio 2.3的Android支持回购46.0.0
UPDATE:This seems to be connected to this issue, since I've tried that also and same thing happened to me. I do not want to update to API 26 anyway - Android Support Repo 46.0.0 with Android Studio 2.3
推荐答案
这只是26.0.0-alpha1版本中的错误.通过更新您的build.gradle
文件切换回25.3.0.
It is just a bug in the 26.0.0-alpha1 release. Switch back to 25.3.0 by updating your build.gradle
file.
这篇关于即使我正在使用MenuItemCompat.setOnActionExpandListener,我的应用程序也会崩溃,建议您使用MenuItemCompat.setOnActionExpandListener的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!