In order to use an SVG file in my android project, I have to use vector compat.
First I converted my SVG file into a vector according to http://a-student.github.io/SvgToVectorDrawableConverter.Web/
Then I followed the official blog http://android-developers.blogspot.fr/2016/02/android-support-library-232.html
So here is my build.gradle
android {
compileSdkVersion 23
buildToolsVersion "23.0.3"
defaultConfig {
applicationId "xxx"
minSdkVersion 16
targetSdkVersion 22
versionCode 22
versionName "2.0"
vectorDrawables.useSupportLibrary = true
}
[...]
}
and in my xml I use this
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:card="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/dark_grey"
tools:ignore="MissingPrefix">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="@dimen/login_margin">
<ImageView
android:id="@+id/info_about_app"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:background="@drawable/back_login"
app:srcCompat="@drawable/vector"/> <-- Important line
and my vector looks like
<?xml version="1.0" encoding="utf-8"?>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:auto="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:width="425dp"
android:height="252dp"
android:viewportHeight="504"
android:viewportWidth="850"
auto:height="252dp"
auto:viewportHeight="504"
auto:viewportWidth="850"
auto:width="425dp"
tools:ignore="NewApi">
<group
android:translateY="-548.3622"
auto:translateY="-548.3622">
No problem with preview in Android Studio, but when I try to run my app, I get the following error
Error:(2) No resource identifier found for attribute 'viewportHeight' in package 'xxx'
I think this error is due to bad ids backport but it is the role of
vectorDrawables.useSupportLibrary = true
android plugin for gradle ==> 2.1.0-beta1
How can I fix that?
Just remove this line:
this is what
No resource identifier found for attribute 'viewportHeight'suggests me.OR that you didn't import the support vector compat library.
But I'm inclined to think you did.