Android Robolectric和矢量drawables

Android Robolectric和矢量drawables,第1张

概述我在我的应用程序中使用了一些矢量drawables但仅适用于v21及更高版本 – 它们位于资源文件夹drawable-anydpi-v21中,并且还具有其他api级别的回退位图版本(drawable-hdpi.mdpi,…). 当我使用此配置运行robolectric时 @Config(sdk = 16, application = MyApp.class, constants = BuildCo 我在我的应用程序中使用了一些矢量drawables但仅适用于v21及更高版本 – 它们位于资源文件夹drawable-anydpi-v21中,并且还具有其他API级别的回退位图版本(drawable-hdpi.mdpi,…).

当我使用此配置运行robolectric时

@Config(sdk = 16,application = MyApp.class,constants = BuildConfig.class,packagename = "com.company.app")

我使用这些drawables对视图的膨胀产生以下错误

Caused by: androID.content.res.Resources$NotFoundException: file ./app/build/intermediates/data-binding-layout-out/dev/deBUG/drawable-anydpi-v21/ic_info_outline_white_24dp.xml from drawable resource ID #0x7f02010eCaused by: org.xmlpull.v1.XmlPullParserException: XML file ./app/build/intermediates/data-binding-layout-out/dev/deBUG/drawable-anydpi-v21/ic_info_outline_white_24dp.xml line #-1 (sorry,not yet implemented): invalID drawable tag vector

build.gradle的相关部分是:

androID {      compileSdkVersion 23      buildToolsversion "23.0.3"      defaultConfig {        applicationID "com.example.app"        minSdkVersion 16        targetSdkVersion 23        versionCode 79        versionname "0.39"        // Enabling multIDex support.        multIDexEnabled true        vectorDrawables.useSupportlibrary = true        testApplicationID "com.example.app.test"        testInstrumentationRunner "androID.support.test.runner.AndroIDJUnitRunner"      }      testoptions {        unitTests.returnDefaultValues = true      }   }   dependencIEs {    compile 'com.androID.support:support-vector-drawable:23.4.0'    testCompile "org.robolectric:robolectric:3.1"    testCompile "org.robolectric:shadows-multIDex:3.1"    testCompile "org.robolectric:shadows-support-v4:3.1"   }

所以即使我已经指定了sdk = 16,Robolectric似乎也从drawable-anydpi-v21中获取了drawables.

>这是一个roboelectric的错误吗?要么
>有没有更好的方法来指定APK级别是什么?要么
>有没有办法让roboelectric读取矢量标签?要么
>其他一些方法呢?

解决方法 您是否特别要求您的测试以JELLYBEAN为目标?

鉴于您确实要求您的测试以JELLYBEAN为目标,您可能希望将v21资源放在res / drawable-v21文件夹而不是res / drawable-anydpi-21中.

我最近在将ImageVIEw添加到使用VectorDrawable作为其源的布局后,也遇到了与测试相同的错误.

<ImageVIEw    androID:contentDescription="@string/content_image_description"    androID:src="@drawable/banner"    androID:layout_gravity="right"    androID:layout_wIDth="@dimen/banner_wIDth"    androID:layout_height="@dimen/banner_height"    />

使用robolectric v3.1,我能够通过以下配置注释让我的测试再次通过:

@Config(constants = BuildConfig.class,sdk = Build.VERSION_CODES.LolliPOP,packagename = "com.package")

希望这可以帮助.

总结

以上是内存溢出为你收集整理的Android Robolectric和矢量drawables全部内容,希望文章能够帮你解决Android Robolectric和矢量drawables所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1135855.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-30
下一篇 2022-05-30

发表评论

登录后才能评论

评论列表(0条)

保存