I have a requirement to remove a specific res folder from a flavour.
sourceSets { main { manifest.srcFile 'AndroidManifest.xml' java.srcDirs = ['src'] res.srcDirs = ['res'] aidl.srcDirs = ['src'] assets.srcDirs = ['assets'] } } productFlavors { flavor1 { sourceSets { flavor1 { resources { exclude 'res/drawable-mdpi/*' } } } } flavorDimensions "flavor" }
But still drawable-mdpi folder is coming to the apk.
So could anyone please specify what mistake am I making.
Thanks Vivek
2 Answers
Answers 1
I finally solved this problem!
I have found this link.
And did this:
add an xml file to res/raw folder. I named it resources_discard.xml, here is it:
<?xml version="1.0" encoding="utf-8"?> <resources xmlns:tools="http://schemas.android.com/tools" tools:discard="@raw/hd/*" />
this file is placed in a correct directory structure for my flavor called lite "scr/lite/res/raw"
This way, contents of res/hd folder are not included in lite builds, effectively reducing my lite build apk size by 50%
UPD: to exclude some images from different flavors, u have to put the images in assets folder, and in gradle declare:
flavor { aaptOptions { ignoreAssetsPattern '/folder:*.jpg:*.png' //use : as delimiter } }
also i learned that you cant have subfolders in /raw folder.
Answers 2
You could try using splits.
Example (Right from the android SDK webpage):
android { ... splits { // Configures multiple APKs based on screen density. density { // Configures multiple APKs based on screen density. enable true // Specifies a list of screen densities Gradle should not create multiple APKs for. Here you should add all the densities except MDPI. exclude "ldpi", "xxhdpi", "xxxhdpi" // Specifies a list of compatible screen size settings for the manifest. compatibleScreens 'small', 'normal', 'large', 'xlarge' } } }
If that does not work, you could separate your res/MDPI and the rest of the res/Density folders into two separate modules (let's call them, layoutMdpi and layoutAll). Both modules need to have the same package name so their R classes are identical and interchangeable (essentially the same that happens between different versions of the android SDK). Then, create at least two specific dependency configurations for your flavors, one for the ones who should use MDPI, and one for those who should not.
configurations { mdpiCompile allCompile } dependencies { ... mdpiCompile project(':layoutMdpi') allCompile project(':layoutAll') }
And then, since MDPI resources aren't present in layoutAll, you are good to go.
0 comments:
Post a Comment