等级插件3-alpha1 outputFile导致错误 [英] Grade Plugin 3-alpha1 outputFile causes error

查看:86
本文介绍了等级插件3-alpha1 outputFile导致错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将项目更新到Android Studio 3.

I'm trying to update a project to Android Studio 3.

build.gradle文件不再接受以下代码段.

The following snippet is no longer accepted in a build.gradle file.

applicationVariants.all { variant ->

    variant.outputs.each { out ->

        def oFile =out.outputFile  // This line causes failure

        //...
    }
}

该错误是一个简单的无效",但智能提示表明它是自动完成的.

The error is a simple "Not Valid" yet the intellisense suggests it is as it autocompletes fine.

检查idea.log显示以下异常:

Checking the idea.log shows the following exception:

Caused by: java.lang.RuntimeException: Not valid.
at com.android.ide.common.build.ApkData.getMainOutputFile(ApkData.java:136)
at com.android.build.gradle.internal.api.BaseVariantOutputImpl.getOutputFile(BaseVariantOutputImpl.java:60)
at com.android.build.gradle.internal.api.ApkVariantOutputImpl_Decorated.getOutputFile(Unknown Source)
at org.gradle.internal.metaobject.BeanDynamicObject$MetaClassAdapter.getProperty(BeanDynamicObject.java:228)
at org.gradle.internal.metaobject.BeanDynamicObject.tryGetProperty(BeanDynamicObject.java:171)
at org.gradle.internal.metaobject.CompositeDynamicObject.tryGetProperty(CompositeDynamicObject.java:55)
at org.gradle.internal.metaobject.AbstractDynamicObject.getProperty(AbstractDynamicObject.java:59)
at com.android.build.gradle.internal.api.ApkVariantOutputImpl_Decorated.getProperty(Unknown Source)

我在Gradle 4上找不到任何文档.这可能是Bug还是不推荐使用的功能?

I can find no documentation on Gradle 4. Would this be a bug or a function that is deprecated perhaps?

也提交至: https://issuetracker.google.com/issues/38408231

推荐答案

更新:已修复 APK重命名:

使用所有迭代器代替每个:

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


先前的答案,仍然有效:这是新插件的已知问题:


Previous answer, still valid: It's a known problem with the new plugin:

之所以会发生此构建错误,是因为在配置阶段不再创建特定于变体的任务.这导致插件不预先知道其所有输出,但这也意味着更快的配置时间.作为替代方案,我们将引入新的API以提供类似的功能.

This build error occurs because variant-specific tasks are no longer created during the configuration stage. This results in the plugin not knowing all of its outputs up front, but it also means faster configuration times. As an alternative, we will introduce new APIs to provide similar functionality.

根据 查看全文

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