tangens tangens - 2 months ago 262
Android Question

After update to Android Studio 2.2 / gradle plugin 2.2.0: "could not get unknown property 'assembleRelease'"

After updating Android Studio to version 2.2 and the Gradle-plugin to 2.2.0, I get following error:

"Could not get unknown property 'assembleRelease' for project ':app' of type org.gradle.api.Project."

When I change the plugin version back to 2.1.3 the code still works, but that's no long-term option for me.

My code:

apply plugin: 'com.android.application'

dependencies {
...
}

android {
...
}

...
assembleRelease.doLast {
file('build/outputs/apk/app-release.apk').renameTo("AppName-1.0.0-${project.ext.androidVersionCode}.apk")
}


Hint:
project.ext.androidVersionCode is a variable defined otherwhere and contains a build number. The code in assembleRelease.doLast shall just move/rename the generated apk file.

Thank you for advices!
tangens

Answer

You may rewrite your task a bit and try like this:

task renameBuildTask() {
  file('build/outputs/apk/app-release.apk').renameTo("AppName-1.0.0-${project.ext.androidVersionCode}.apk")
  dependsOn 'assembleRelease'
}

Also you can check this question to get better understanding.

EDIT

As @tangens said in a comment:

It works when I replace the call gradle assemble by e.g. gradle renameBuildTask. Thank you! The answer contains an error. Correct would be: task renameBuildTask() << { ... }

Comments