Reputation: 21
I'm targeting my (first) App to API23 and above (minSDKVersion is 23), using almost exclusively vector drawables (imported from SVGs). After build, checking the APK analyzer, all vectorDrawables have been converted to PNG in 6 different resolutions, unnecessarily increasing the APK size. From Android Studio 1.4 introduction articles I assume this is happening to target API<21 for downward compatibility, however, I don't even want that compatibility.
From my understanding, I might be able to control this with aaptOptions within gradle settings, but I'm not sure how. Or is the usage of appcompat and support-v4 encouraging the build to be towards API<21, thus enforcing automatic XML to PNG conversion? How can I stop gradle from converting vector drawables to raster images?
I already switched all compiler settings to minimum 23, compileSDKVersion and targetSDKVersion are 28. All PNGs are deleted from res-folders, all remaining raster images converted to webp.
compileSdkVersion 28
defaultConfig {
minSdkVersion 23
targetSdkVersion 28
versionCode 18
versionName "0.9.5"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
buildToolsVersion '28.0.3'
}
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'com.android.support:support-v4:28.0.0'
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
implementation 'com.google.android.gms:play-services-ads:17.1.2'
implementation 'com.dynamitechetan.flowinggradient:flowinggradient:1.1'
}
Expected result is that only vectordrawables are in the APK, plus a few webP images, reducing overall size. Instead vectordrawables are included in png format in the APK.
Upvotes: 2
Views: 661
Reputation: 1083
According to Android Docs the png should only be generated if your minimum SDK is below 21. Yours is set to 23 which indicates the docs are not completely accurate.
But the comment to your post solved it for me (even using minimum SDK 14). Just add an empty generatedDensities, like:
defaultConfig {
minSdkVersion 14
targetSdkVersion 28
// One or the other of these will work based on build tools:
generatedDensities = []
vectorDrawables.generatedDensities = []
}
Upvotes: 0