AGP8+ android.useNewApkCreator‘ is deprecated 打包失败

在这里插入图片描述

问题

新建一个项目,默认使用最新版的 AGP 和 Gradle,打包构建立马失败!

在这里插入图片描述

错误日志

Caused by: com.android.builder.errors.EvalIssueException: The option 'android.useNewApkCreator' is deprecated.

An exception occurred applying plugin request [id: 'com.android.application', version: '8.3.0']
> Failed to apply plugin 'com.android.internal.application'.
   > com.android.builder.errors.EvalIssueException: The option 'android.useNewApkCreator' is deprecated.
     The current default is 'true'.
     It was removed in version 8.0 of the Android Gradle plugin.

全局搜索,当前项目确实没有配置该属性 android.useNewApkCreator,这属性到底是哪里来的?

在这里插入图片描述

解决

我们都知道,project.properties 属性值主要数据来源是 gradle.properties 配置文件。

在这里插入图片描述

我们通过在 build.gradle 文件输出属性配置,确实是有该配置,并且值是 false

看起来怎么与这两句话意思相反呢?真是差点搞不懂了~

① The current default is ‘true’. 【实际输出确是 false】
② It was removed in version 8.0 of the Android Gradle plugin. 【removed 了,为什么输出还有值?】

val newApkKey = "android.useNewApkCreator"
val containsNewApkKey = project.properties.containsKey(newApkKey)
println("containsNewApkKey:${containsNewApkKey}")

for (p in project.properties) {
    println("项目属性:${p.key} = ${p.value}")
}

在这里插入图片描述

根据上述第二点 ② 如果不是系统内预置,我们确认是否存在某个gradle.properties 文件内配置了该属性,并且这个文件是每个项目都会读取的?

果不其然,通过磁盘全局搜索发现一个醒目了路径下存在这个文件,打开一看正如我所想,注释掉之后再运行不再报错了~

#android.useNewApkCreator=false

这或许是 AS 的默认配置文件吧

在这里插入图片描述
在这里插入图片描述

  • 6
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值