在新的Android插件3.0.0-alpha1中重命名输出文件 [英] Rename output file in the new Android Plugin 3.0.0-alpha1

查看:82
本文介绍了在新的Android插件3.0.0-alpha1中重命名输出文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在以前的gradle插件中使用了它,并且运行正常.

I was using this in the previous gradle plugin and it was working fine.

applicationVariants.all { v ->
v.outputs.each { output ->
    output.outputFile = new File(
            output.outputFile.parent,
            output.outputFile.name.replace("app-release.apk", "companyName-app-v${variant.versionName}.apk"))
}}

随着对3.0.0-alpha1的最新更新,它显示错误.

With the recent update to 3.0.0-alpha1 it shows error.

我阅读了链接 https://developer. android.com/studio/preview/features/new-android-plugin-migration.html ,但无法找到错误的确切来源.

I read the link https://developer.android.com/studio/preview/features/new-android-plugin-migration.html but was unable to find the exact source of error.

我是否已解决此问题?

推荐答案

要更改APK名称,可以将其更改为:

To change the APK name, you can change it to:

android.applicationVariants.all { variant ->
    variant.outputs.all {
        outputFileName = "companyName-app-v${variant.versionName}.apk"
    }
}

如果使用each()遍历变体对象,则需要 开始使用all().这是因为each()仅迭代 在配置期间已经存在的对象-但是那些 新模型在配置时不存在该对象.然而, all()通过在添加对象时拾取对象来适应新模型 在执行过程中.

If you use each() to iterate through the variant objects, you need to start using all(). That's because each() iterates through only the objects that already exist during configuration time — but those object don't exist at configuration time with the new model. However, all() adapts to the new model by picking up object as they are added during execution.

来源

这篇关于在新的Android插件3.0.0-alpha1中重命名输出文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆