Recently, I want to use Vector Drawable to manage all the icons. Vector Drawable works well in Android API 21+, but when I tried to use it on one of my test devices [Amazon KFTHWI Android 4.4.3 API 19], all the icons could not be loaded at all!
I followed the advice here and here . But still it doesnβt work.
Here is my configuration:
In the gradle script project file:
buildscript { repositories { jcenter() } dependencies { classpath 'com.android.tools.build:gradle:2.1.0' classpath ... } }
So the gradle plugin version should be 2.0+
In the main module gradle script file:
android{ ... defaultConfig{ ... vectorDrawables.useSupportLibrary = true ... } } dependencies{ ... compile 'com.android.support:appcompat-v7:23.4.0' compile 'com.android.support:gridlayout-v7:23.4.0' ... }
This core module contains the application. The reason I am compiling the gridlayout-v7 library is because I use some Gridlayouts in the application.
Here is my implementation:
Since I need to generate some views according to the data I received, I set the image source to Java code.
ImageView icon = new ImageView(this); icon.setImageResource(R.drawable.ic_lock_black_24dp);
ic_lock_black_24dp.xml is created from the Icon material library in Studio Vector Asset.
My expectation:
I believe that my configuration in my main gradle script module will not allow Android Studio to generate Png for vectors and will allow Android to generate Drawables for Vectors directly at runtime.
But I'm only partially right ... My configuration actually prohibits Android Studio from creating Png when building. BUT my old Android device [API 19] cannot generate Drawables from Vectors !! Thus, there are no icons in the application now ...
Here are the exceptions: [Amazon KFTHWI Android 4.4.3 API 19]
W/ImageView:Unable to find resource:2130837702 android.content.res.Resources$NotFoundException: File res/drawable/ic_lock_black_24dp.xml from drawable resource ID
Oddly enough, all the icons will be well represented if I do not use the AppCompat support library, but I know that this is due to the fact that Android Studio creates Png when building. I can even find these Png in the APK.
My problem:
Now I still want to use Vector Drawable on older Android devices, which means I'm still trying to avoid using Pngs. Can someone give me some advice or tell me in what steps I did something wrong?