我正在我的应用中使用一些矢量图形,但只限于 v21 及以上版本 - 它们在资源文件夹 drawable-anydpi-v21 中,并且还有其他 API 级别的备用位图版本 (drawable-hdpi.mdpi,...)。
当我运行一个具有此配置的 Robolectric 时,...
当我运行一个具有此配置的 Robolectric 时,...
@Config(sdk = 16, application = MyApp.class, constants = BuildConfig.class, packageName = "com.company.app")
当使用这些可绘制对象时,膨胀视图时出现以下错误
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中获取可绘制对象。
这是Robolectric的一个bug吗?还是
有更好的方法来指定APK的级别吗?或者
有办法让Robolectric读取矢量标记吗?还是
还有其他方法吗?
build.gradle
文件吗?以确保你如何使用矢量图形。 - Eugen Martynov