shrinkResources true引发的问题及解决

在构建release版本的APP时,遇到图片资源丢失的问题,发现是由于shrinkResources配置为true引起的。资源收缩会删除未引用的资源,包括库中的资源。此功能需要与代码收缩(如ProGuard)配合使用。为避免SDK中图片资源被删除,可通过在res/raw/keep.xml文件中指定要保留的资源来解决。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

背景

今天偶然发现release版本的包上出现图片无法显示的问题,之前在debug版一直没有出现,因为用的SDK需要把图片资源放到drawable下,分析了下apk包,发现相应的图片资源没有被打包进来,起初认为是混淆的原因,但是混淆只是针对代码,后发现了这个配置shrinkResources true

介绍

“resource shrinking”: the automatic removal of resources that are unused, at build time, in the packaged app. In addition to removing resources in your project that are not actually needed at runtime, this also removes resources from libraries you are depending on if they are not actually needed by your application.

以上是官方说明,大概意思是在应用构建打包的过程中自动删除没有引用的资源,对依赖的库同样有效

使用

Note that resource shrinking only works in conjunction with code shrinking (such as ProGuard).That’s how it can remove unused resources from libraries; normally, all resources in a library are used, and it is only when we remove unused code that it becomes apparent which resources are referenced from the remainin

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值