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

AndroidGradleAndroid StudioAndroid Gradle-Pluginbuild.gradle

Android Problem Overview


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?

Android Solutions


Solution 1 - Android

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"))
    }
}

Solution 2 - Android

More comprehensively:

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

Solution 3 - Android

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'

Solution 4 - Android

Or where there's only one variant:

def apk = outputs[0].outputFile

Instead of

def apk = variant.outputFile

Solution 5 - Android

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

Solution 6 - Android

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 https://stackoverflow.com/questions/27016385/error26-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!

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionligiView Question on Stackoverflow
Solution 1 - AndroidOleg KhalidovView Answer on Stackoverflow
Solution 2 - AndroidChrisView Answer on Stackoverflow
Solution 3 - AndroidcosicView Answer on Stackoverflow
Solution 4 - AndroidOllie CView Answer on Stackoverflow
Solution 5 - AndroidPedro LoureiroView Answer on Stackoverflow
Solution 6 - AndroidWilliaan LopesView Answer on Stackoverflow