shrinkResources 设置为 true,但所有未使用的资源(特别是可绘制对象)未被删除

shrinkResources set to true, but all unused resources (specifically drawables) not getting removed

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

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

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

我在另一个线程中阅读了有关将 shrinkMode 设置为 strict 的内容。那会有帮助吗?我无法尝试,因为我不知道在哪里设置它。查找示例和文档,但不幸的是无法访问正确的页面。

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

To turn off the safety checks, set the shrinkMode to "strict" as in the following keep.xml file:

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

发件人:http://tools.android.com/tech-docs/new-build-system/resource-shrinking

R.raw.Keep(xml 文件)

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

不要忘记从 .java 源文件中引用此资源。有关详细信息,请参阅 this

如果您担心 apk 文件的大小,那么最好也缩小图像文件。 也就是将 RGB 通道转换为 Indexed 通道,这样最多可以节省 50% space。

使用此站点缩小您的图像media4x.com