Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
452 views
in Technique[技术] by (71.8m points)

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

I'm setting shrinkResources to true as follows:

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

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% ?

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.

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

R.raw.Keep (xml file)

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

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

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.

Use this site to Shrink your images media4x.com


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...