大佬教程收集整理的这篇文章主要介绍了Android Robolectric和矢量drawables,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
当我使用此配置运行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 #0x7f02010e Caused 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为目标,您可能希望将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所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。