Reputation: 940
I've read this article, but still it doesn't make sense to me.
Since gradle build tools 1.5.0 we can use vector drawables in the app. For Lollipop and above vectors are used and for below os versions gradle generates PNG files and places them in the drawable_'density'_v4. OK, that's clear.
Now we have also compatibility support for vector drawables, I have followed this instructions to support them in my app, but when it was done and everything seems to work, I could still find in the apk file generated PNG files.
So, what's the difference and why PNG files are generated if support drawable should be used?
Upvotes: 2
Views: 1958
Reputation: 309
The difference between a)PNG generation solution Vs. b)VectorDrawableCompat is :
1) APK size. For a), you better use multi-apk such that one APK for >=21, one for <21. Such that, the APK size for >=21 can be reduced. For b), the APK size should be reduced for the whole APK regardless of the min API level.
2) Functionality Limitation. For a) There is some rarely-used attributes inside Vectordrawable is not support. For b) Although all attributes are supported, it requires some code change, like from anrdoid:src to app:srcCompat.
3) Reference: For a), you can refer to VectorDrawable (or generated PNG) anywhere in the Java / XML, without knowing it is Vector or not. But for b) you have to use app:srcCompat to refer to VectorDrawableCompat, or use within DrawableContainer.
In short, if you target for the best APK size for all OS version and don't mind changing the code a bit, use VectorDrawableCompat. Otherwise, the PNG generation + separate APK will be good enough for you.
Upvotes: 0
Reputation: 35661
For Gradle 2 you need to add:
android {
defaultConfig {
vectorDrawables.useSupportLibrary = true
}
}
to your build.gradle.
For gradle 1.5
android {
defaultConfig {
generatedDensities = []
}
aaptOptions {
additionalParameters "--no-version-vectors"
}
}
Full details here: http://android-developers.blogspot.co.uk/2016/02/android-support-library-232.html
Upvotes: 4