Android shrinkResources

在尝试打包开源项目时遇到资源文件不存在的异常,问题源于`shrinkResources`设置为true。解决方案是将shrinkResources设为false,或者同时将shrinkResources和minifyEnabled设为true,以确保正确打包和安装应用。

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

网上找了一个开源项目,在打release包时报了一下异常:

Error:A problem was found with the configuration of task ':app:packageQqRelease'.

> File 'F:\android\code\open_source_projects\MultiChannel-master-master\app\build\intermediates\res\resources-qq-release-stripped.ap_' specified for property 'resourceFile' does not exist.

搜资料后,发现是 shrinkResourcestrue引起的问题:如下

	release {
            // release模式下,不显示log
            buildConfigField("boolean", "LOG_DEBUG", "false")
            // 为版本名添加后缀
            versionNameSuffix "-relase"
            // 不开启混淆
            minifyEnabled false
            // 开启ZipAlign优化
            zipAlignEnabled true
            // 移除无用的resource文件
            shrinkResources true
            // 使用config签名
//            signingConfig signingConfigs.config
            // 混淆文件位置
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'

        }

shrinkResources改为false后就OK了,可以正常打包并安装。又在另外一篇文章里看到,shrinkResources

minifyEnabled必须要一起用,即shrinkResources和minifyEnabled要么同为false,要么同为true。

我试着改了看,结果的确可以正常打包安装。



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值