shrinkResources设置为true,但所有未使用的资源(特别是可绘制)未被删除 [英] shrinkResources set to true, but all unused resources (specifically drawables) not getting removed

查看:840
本文介绍了shrinkResources设置为true,但所有未使用的资源(特别是可绘制)未被删除的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将shrinkResources设置为true,如下所示:

I'm setting shrinkResources to true as follows:

releasepro {
    minifyEnabled true
    shrinkResources true
    proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    applicationIdSuffix ".pro"
}

但是这只消除了一些未使用的资源。我知道,gradle会做一些猜测,并留下不确定的资源是否未使用。有没有办法删除所有未使用的资源100%?

But this is removing only a few unused resources. I am aware that gradle does some guessing and leaves resources that is is not sure are unused. Is there a way to remove all unused resources 100% ?

我读过关于在另一个线程中将shrinkMode设置为strict的方法。这会有帮助吗?我无法尝试,因为我无法确定它在哪里设置。查看示例和文档,但很遗憾,无法进入正确的页面。

I read about setting the shrinkMode to strict in another thread. Will that help? I could not try it as I could not figure where to set it. Looked for examples and documents but unfortunately could not get to the right page.

有没有办法确保100%清除未使用的资源?

Is there a way to ensure 100% removal of unused resources?

推荐答案

R.raw.Keep(xml文件)

R.raw.Keep (xml file)

<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:tools="http://schemas.android.com/tools"
    tools:shrinkMode="strict" />

不要忘记从.java源文件引用此资源。欲了解更多详情,请参阅

Dont forget to Reference this Resource from .java source file. For more details see this

如果您担心apk文件的大小,那么最好还是缩小图像文件。
这是将RGB频道转换为索引频道,这可以节省高达50%的空间。

if you are worried about the size of your apk file then its good practice to shrink image files as well. That is convert RGB channel to Indexed channel,this can save up to 50% more space.

使用此网站缩小图片 media4x.com

这篇关于shrinkResources设置为true,但所有未使用的资源(特别是可绘制)未被删除的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆