Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

After updating to AS 1.0 RC 1 and plugin 0.14.4 I am having problems with the renaming part of my build.gradle:

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

throws now:

Error:(78, 0) Could not find property 'outputFile' on com.android.build.gradle.internal.api.ApplicationVariantImpl_Decorated@67e7625f.

and also I cannot jump to the class ApplicationVariantImpl to look how the property might have been renamed. Anyone knows workarounds for this?

like image 594
ligi Avatar asked Nov 24 '14 20:11

ligi


5 Answers

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"))
    }
}
like image 128
Oleg Khalidov Avatar answered Nov 16 '22 05:11

Oleg Khalidov


More comprehensively:

applicationVariants.all { variant ->
    variant.outputs.each  { output ->
        output.outputFile = new File(output.outputFile.parent, output.outputFile.name.replace(".apk", "-" + defaultConfig.versionName + ".apk"))
    }
}
like image 22
Chris Avatar answered Nov 16 '22 05:11

Chris


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'
like image 6
cosic Avatar answered Nov 16 '22 05:11

cosic


Or where there's only one variant:

def apk = outputs[0].outputFile

Instead of

def apk = variant.outputFile
like image 5
Ollie C Avatar answered Nov 16 '22 06:11

Ollie C


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

like image 1
Pedro Loureiro Avatar answered Nov 16 '22 05:11

Pedro Loureiro