【问题标题】:Could not find property 'zipAlignEnabled' on com.android.build.gradle.internal.api.ApplicationVariantImpl_Decorated在 com.android.build.gradle.internal.api.ApplicationVariantImpl_Decorated 上找不到属性“zipAlignEnabled”
【发布时间】:2014-12-01 06:14:50
【问题描述】:

0.14.0 android gradle 插件升级后,我的项目停止构建并出现错误:构建脚本错误,发现不支持的 Gradle DSL 方法:'renderscriptSupportMode()。在查看http://tools.android.com/tech-docs/new-build-system 的发行说明后,我进行了以下必要的更改:

Renamed a few properties to make things more consistent.
BuildType.runProguard                 ->  minifyEnabled
BuildType.zipAlign                    -> zipAlignEnabled
BuildType.jniDebugBuild               -> jniDebuggable
BuildType.renderscriptDebug           -> renderscriptDebuggable
ProductFlavor.renderscriptSupportMode -> renderscriptSupportModeEnabled
ProductFlavor.renderscriptNdkMode     -> renderscriptNdkModeEnabled 

更改上述属性后,一些错误消失了,但我仍然得到以下信息:

Could not find property 'zipAlignEnabled' on com.android.build.gradle.internal.api.ApplicationVariantImpl_Decorated

是否有人遇到过这个错误,或者如果我遗漏了什么,请告诉我?下面是导致错误的 gradle.build 的 sn-p。

if (variant.zipAlignEnabled) {
        def file = variant.outputFile
        def fileName = file.name.replace(".apk", "-" + majorCode + "." + minorCode + "." +miniCode + "-" +buildNumber+".apk")
        variant.outputFile = new File(file.parent, fileName)
    }

【问题讨论】:

    标签: android gradle android-gradle-plugin


    【解决方案1】:

    你试过了吗:

    if (variant.buildType.zipAlignEnabled) { ...

    (奖励):您也可能会遇到麻烦:

    variant.outputFile = ...
    

    如果是这样,您可能会发现以下链接很有用:Gradle warning: variant.getOutputFile() and variant.setOutputFile() are deprecated

    【讨论】:

    • 我不得不使用 variant.outputs[0].outputFile
    • 感谢@ITJscott,我在发布问题后不久意识到我需要将variant.outputFile 更改为variant.outputs.each。我尝试了 variant.buildType.zipAlignEnabled 并且它有效:)。再次感谢
    • @Lo-Tan variant.outputs[0].outputFile 如果您的构建脚本只输出一个文件,或者您确定第一个变体就是那个你要。然而,上面链接中的解决方案显示了如何遍历“变体”集合,允许单个或多个输出文件。
    【解决方案2】:

    您需要做几件事才能从 0.9 迁移到 1.0 见http://tools.android.com/tech-docs/new-build-system/migrating-to-1-0-0

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-01-25
      • 2015-02-02
      • 2016-01-18
      • 2015-01-22
      • 2010-10-09
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多