【问题标题】:Could not set unknown property 'outputFileName' for object of type com.android.build.gradle.internal.api.ApplicationVariantImpl无法为 com.android.build.gradle.internal.api.ApplicationVariantImpl 类型的对象设置未知属性“outputFileName”
【发布时间】:2021-03-19 03:10:38
【问题描述】:

得到错误

无法为类型对象设置未知属性“outputFileName” com.android.build.gradle.internal.api.ApplicationVariantImpl.

使用安卓工作室 3.2.1

毕业 4.6

applicationVariants.all { variant ->
             variant.outputs.each { output ->
                 def fileName = "${project.name}_${output.baseName}-${variant.versionName}.apk"
                 outputFileName = new File(output.outputFile.parent, fileName).getName()
             }
         }

【问题讨论】:

  • 您要更改版本名称吗?
  • 不,我只是在进行失败的正常构建

标签: android android-studio android-gradle-plugin


【解决方案1】:

你必须使用all

在您的发布版本中使用此代码

android {
    //...
    buildTypes {

        debug {
        
        }
        release {
            android.applicationVariants.all { variant ->
                variant.outputs.all { output ->
                    def fileName = "${project.name}_${output.baseName}-${variant.versionName}.apk"
                    outputFileName = fileName
                }
            }
        }
    }

} 
}

【讨论】:

  • 我试过这个并且得到了新的错误 -- 无法为 BuildType_Decorated{name=output, debuggable=false, testCoverageEnabled=false, jniDebuggable=false, pseudoLocalesEnabled=false, renderscriptDebuggable= 获取未知属性 'baseName' false,renderscriptOptimLevel=3,minifyEnabled=false,zipAlignEnabled=true,signingConfig=null,embedMicroApp=true,mBuildConfigFields={},mResValues={},mProguardFiles=[],mConsumerProguardFiles=[],mManifestPlaceholders={}} com 类型.android.build.gradle.internal.dsl.BuildType.
  • @VatsalDesai 您必须在发布配置检查编辑代码中调用它
  • 一些解释为什么“全部”有效 -> stackoverflow.com/a/44118506/3752244
  • variant.outputs.all { 行实际上应该是 variant.outputs.all { output -> 以避免“未知属性”错误。我已经编辑了答案。
  • @ChadSchultz 你是对的,感谢编辑和评论
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-09-30
  • 1970-01-01
  • 1970-01-01
  • 2020-01-02
  • 2022-08-14
  • 2020-06-15
相关资源
最近更新 更多