如何从 gradle build 风格中排除 res 文件夹?

时间:2023-02-13
本文介绍了如何从 gradle build 风格中排除 res 文件夹?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要从风味中删除特定的 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>

然后这样做了:

  1. 将 xml 文件添加到 res/raw 文件夹.我把它命名为resources_discard.xml,这里是:

    <?xml version="1.0" encoding="utf-8"?><资源 xmlns:tools="http://schemas.android.com/tools"工具:discard="@raw/hd/*"/>

  2. 此文件放置在适合我的风格的正确目录结构中,称为 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:

  1. 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/*" />
    

  2. 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模板网!

上一篇:“使用 gradle 文件同步项目"在哪里?Android St 下一篇:错误:在我添加新依赖项时,我的项目中的任务

相关文章

最新文章