<?xml version="1.0" enCoding="utf-8"?><androID.support.constraint.ConstraintLayout xmlns:androID="http://schemas.androID.com/apk/res/androID" xmlns:tools="http://schemas.androID.com/tools" androID:layout_wIDth="match_parent" androID:layout_height="match_parent" tools:context="mykwillis.com.mediaroutebutton.MainActivity"> <androID.support.v7.app.MediaRoutebutton androID:ID="@+ID/vIDeo_layer_Chromecast_button" androID:layout_wIDth="match_parent" androID:layout_height="match_parent" androID:layout_gravity="center"/></androID.support.constraint.ConstraintLayout>
我已经创建了一个基本的Robolectric测试的开始,它只是构建和创建MainActivity:
@RunWith(RobolectricTestRunner.class)@Config(constants = BuildConfig.class)public class MainActivityTest { @Test public voID loadActivity() { MainActivity activity = Robolectric.buildActivity(MainActivity.class).create().get(); }}
当我尝试运行此测试时,收到以下错误:
androID.vIEw.InflateException: XML file build/intermediates/res/merged/deBUG/layout/activity_main.xml line #-1 (sorry,not yet implemented): XML file build/intermediates/res/merged/deBUG/layout/activity_main.xml line #-1 (sorry,not yet implemented): Error inflating class androID.support.v7.app.MediaRoutebuttonCaused by: androID.vIEw.InflateException: XML file build/intermediates/res/merged/deBUG/layout/activity_main.xml line #-1 (sorry,not yet implemented): Error inflating class androID.support.v7.app.MediaRoutebutton
深入研究,当Robolectric尝试加载MediaRoutebutton的样式信息时,它似乎失败了.相关的堆栈跟踪似乎是这样的:
Caused by: java.lang.classCastException: org.robolectric.res.AttrData cannot be cast to org.robolectric.res.StyleData atorg.robolectric.shadows.ShadowAssetManager.resolveStyle(ShadowAssetManager.java:617) at org.robolectric.shadows.ShadowAssetManager.buildTypedValue(ShadowAssetManager.java:742) at org.robolectric.shadows.ShadowAssetManager.attrsToTypedArray(ShadowAssetManager.java:793) at org.robolectric.shadows.ShadowResourcesImpl$ShadowthemeImpl.obtainStyledAttributes(ShadowResourcesImpl.java:177) at androID.content.res.ResourcesImpl$themeImpl.obtainStyledAttributes(ResourcesImpl.java) at androID.content.res.Resources$theme.obtainStyledAttributes(Resources.java:1440) at androID.content.Context.obtainStyledAttributes(Context.java:587) at androID.support.v7.app.MediaRouterthemeHelper.getthemecolor(MediaRouterthemeHelper.java:169) at androID.support.v7.app.MediaRouterthemeHelper.getControllercolor(MediaRouterthemeHelper.java:94) at androID.support.v7.app.MediaRouterthemeHelper.createthemedContext(MediaRouterthemeHelper.java:62) at androID.support.v7.app.MediaRoutebutton.(MediaRoutebutton.java) at androID.vIEw.LayoutInflater.createVIEw(LayoutInflater.java:645)
我使用以下依赖项:
dependencIEs { compile filetree(dir: 'libs',include: ['*.jar']) compile 'com.androID.support:appcompat-v7:25.3.0' compile 'com.androID.support:mediarouter-v7:25.3.0' compile 'com.androID.support.constraint:constraint-layout:1.0.2' testCompile 'junit:junit:4.12' testCompile "org.robolectric:robolectric:3.3.1" testCompile 'org.khronos:opengl-API:gl1.1-androID-2.1_r1' // https://github.com/robolectric/robolectric/issues/1932}
我认为这意味着我对Robolectric提供了一个Shadow for MediaRoutebutton(由com.androID.support:mediarouter-v7:25.3.0提供)的运气不好,而且我需要自己为这个类创建一个Shadow.我在http://robolectric.org/extending/跟随指南试图创建一个简单的阴影,至少可以让我的视图加载,但无济于事.这是我创造的:
@Implements(androID.support.v7.app.MediaRoutebutton.class)public class MediaRoutebuttonShadow extends ShadowVIEw { public voID __constructor__(Context context,AttributeSet attributeSet,int defStyle) { }}
然后我将@Config语句更新为:
@Config(constants = BuildConfig.class,shadows = MediaRoutebuttonShadow.class)
不幸的是,我在这个配置中得到了同样的错误.
有关如何创建允许视图加载的最小阴影的任何指针?
更新:演示此问题的示例应用程序位于:https://github.com/mykwillis/android-mediaroutebutton-test
解决方法 此问题已跟踪 here,已使用 Robolectric version 4.0中的新功能解决.更新依赖项并将testoptions部分添加到build.gradle:
dependencIEs { // ... testCompile "org.robolectric:robolectric:4.0"}testoptions { unitTests { includeAndroIDResources = true }}
并将此行添加到gradle.propertIEs:
enableunitTestBinaryResources=true
还要确保您已更新到最新的gradle插件.
总结以上是内存溢出为你收集整理的将Robolectric与android.support.v7.app.MediaRouteButton一起使用全部内容,希望文章能够帮你解决将Robolectric与android.support.v7.app.MediaRouteButton一起使用所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)