Android机器人和矢量绘制



我在我的应用程序中使用了一些矢量绘制图,但仅适用于v21和更高版本-它们位于资源文件夹drawable-anydpi-v21中,并且还为其他api级别(drawable-hdpi.mdpi,…)提供了退位图版本。

当我用这个配置运行机器人时

@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

构建的相关部分。它是:

   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 robolelectric似乎采取drawable-anydpi-v21的drawables。

  1. 这个bug是机器人电气的吗?或者

  2. 是否有更好的方法来指定APK水平是什么?或者

  3. 是否有办法让机器人读取矢量标签?或者

  4. 还有其他方法吗?

您是否特别要求您的测试以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"
    />

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

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

你可以做一件事。取RoboElectric电源,替换所有线路

ContextCompat.getDrawable(context, drawableId)

AppCompatDrawableManager.get().getDrawable(context, drawableId)
编译roboelectric并使用它。它将允许机器人使用矢量。

最新更新