我需要从风味中删除特定的 res 文件夹.
sourceSets {主要的 {manifest.srcFile 'AndroidManifest.xml'java.srcDirs = ['src']res.srcDirs = ['res']aidl.srcDirs = ['src']assets.srcDirs = ['assets']}}产品风味{味道1 {源集{味道1 {资源 {排除 'res/drawable-mdpi/*'}}}}风味维度风味"}
但是 drawable-mdpi 文件夹仍然会进入 apk.
那么任何人都可以说明我犯了什么错误.
谢谢维韦克
我终于解决了这个问题!
我找到了这个链接.p>
然后这样做了:
将 xml 文件添加到 res/raw 文件夹.我把它命名为resources_discard.xml,这里是:
<?xml version="1.0" encoding="utf-8"?><资源 xmlns:tools="http://schemas.android.com/tools"工具:discard="@raw/hd/*"/>
此文件放置在适合我的风格的正确目录结构中,称为 lite ("src/lite/res/raw")
这样,res/hd 文件夹的内容不包含在 lite 构建中,有效地减少了我的 lite 构建 apk 大小 50%
更新:要排除一些不同风格的图像,你必须将图像放在assets"文件夹中,并在 gradle 中声明:
风味 {aaptOptions {ignoreAssetsPattern '/folder:*.jpg:*.png'//使用 : 作为分隔符}}
我还了解到/res/raw 文件夹中不能有子文件夹.
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
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 the correct directory structure for my flavor called lite ("src/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%
Update: to exclude some images from different flavors, you have to put the images in the "assets" folder, and in gradle declare:
flavor {
aaptOptions {
ignoreAssetsPattern '/folder:*.jpg:*.png' //use : as delimiter
}
}
I also learned that you can't have subfolders in /res/raw folder.
这篇关于如何从 gradle build 风格中排除 res 文件夹?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!