Could not find property 'outputFile' on com.android.build.gradle.internal.api.ApplicationVariantImpl

╄→гoц情女王★ 提交于 2019-11-27 07:44:49
Oleg Khalidov

try this

applicationVariants.all { variant ->
    variant.outputs.each { output ->
        def file = output.outputFile
        output.outputFile = new File(file.parent, file.name.replace(".apk", "-" + defaultConfig.versionName + ".apk"))
    }
}

More comprehensively:

applicationVariants.all { variant ->
    variant.outputs.each  { output ->
        output.outputFile = new File(output.outputFile.parent, output.outputFile.name.replace(".apk", "-" + defaultConfig.versionName + ".apk"))
    }
}
cosic

This can occur for few reasons:

1.) First as was said before by @Khalidov, try

applicationVariants.all { variant ->
    variant.outputs.each { output ->
        output.outputFile = ...
    }
}

2.) Second try update all other plugins.

For example I got this problem for Spoon, that resolved by update Spoon up to:

classpath 'com.stanfy.spoon:spoon-gradle-plugin:0.14.1'

Or where there's only one variant:

def apk = outputs[0].outputFile

Instead of

def apk = variant.outputFile

Make sure you run the latest gradle version (not the plugin, gradle it self).

Check your gradle-wrapper.properties. Are you running gradle 2.1?

More info on compatibility: http://tools.android.com/tech-docs/new-build-system/version-compatibility

Williaan Lopes

I managed to solve as follows:

old:

buildTypes { 
libertação {

    runProguard false  // esta linha tem que ser mudado

    proguardFiles getDefaultProguardFile ( 'android.txt proguard-' ),  'proguard-rules.pro' 
} 

}

new:

buildTypes { 
libertação {

    minifyEnabled false  // nova versão

    proguardFiles getDefaultProguardFile ( 'android.txt proguard-' ),  'proguard-rules.pro' 
} 

}

edited in file buil.gradle of your project as described in this post by ruan65 Error:(26, 0) Gradle DSL method not found: 'runProguard()'

and after edit too this line:

applicationVariants . all { variant -> 
variant . outputs . each { output -> 
    def file = output . outputFile 
    output . outputFile =  new  File ( file . parent , file . name . replace ( ".apk" ,  "-"  + defaultConfig . versionName +  ".apk" )) 
} 

}

as it was said up there. That settled me!

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!