我所在的团队最终正在推出AppCompat(欢呼),但自升级以来我们的测试套件失败了。
从命令行运行测试套件时,我遇到了一些测试问题。
从Android Studio单独运行它们时,它们会通过。
我发现有关堆栈跟踪的有趣之处在于,当我们不在工具栏中使用共享图标时,它会引用ShareActionProvider。
下面的堆栈跟踪:
android.content.res.Resources$NotFoundException: unknown resource 0
at org.robolectric.shadows.ShadowAssetManager.getAndResolve(ShadowAssetManager.java:384)
at org.robolectric.shadows.ShadowAssetManager.getResourceValue(ShadowAssetManager.java:129)
at android.content.res.AssetManager.getResourceValue(AssetManager.java)
at android.content.res.Resources.getValue(Resources.java:1347)
at android.support.v7.widget.AppCompatDrawableManager.createDrawableIfNeeded(AppCompatDrawableManager.java:226)
at android.support.v7.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:199)
at android.support.v7.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:192)
at android.support.v7.widget.ShareActionProvider.onCreateActionView(ShareActionProvider.java:229)
at android.support.v4.view.ActionProvider.onCreateActionView(ActionProvider.java:166)
at android.support.v7.view.menu.MenuItemImpl.getActionView(MenuItemImpl.java:630)
at android.support.v7.widget.ActionMenuPresenter.getItemView(ActionMenuPresenter.java:190)
at android.support.v7.widget.ActionMenuPresenter.flagActionItems(ActionMenuPresenter.java:451)
at android.support.v7.view.menu.MenuBuilder.flagActionItems(MenuBuilder.java:1138)
at android.support.v7.view.menu.BaseMenuPresenter.updateMenuView(BaseMenuPresenter.java:91)
at android.support.v7.widget.ActionMenuPresenter.updateMenuView(ActionMenuPresenter.java:229)
at android.support.v7.view.menu.MenuBuilder.dispatchPresenterUpdate(MenuBuilder.java:284)
at android.support.v7.view.menu.MenuBuilder.onItemsChanged(MenuBuilder.java:1030)
at android.support.v7.view.menu.MenuBuilder.startDispatchingItemsChanged(MenuBuilder.java:1053)
at android.support.v7.app.ToolbarActionBar.populateOptionsMenu(ToolbarActionBar.java:460)
at android.support.v7.app.ToolbarActionBar$1.run(ToolbarActionBar.java:61)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
答案 0 :(得分:1)
解决方案是将此行添加到我们的顶级主题:
<item name="actionModeShareDrawable">@drawable/ic_share</item>
ic_share
是我们用于分享的图标。
例如:
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="actionModeShareDrawable">@drawable/ic_share</item>
</style>