Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 795
tangens Avatar asked Sep 20 '16 09:09

tangens


3 Answers

tasks.whenTaskAdded { task ->   if (task.name == 'assembleRelease') {     task.finalizedBy 'yourRenameTasks'   } } 
like image 135
HalZhang Avatar answered Sep 27 '22 02:09

HalZhang


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() << { ... }

like image 21
Volodymyr Avatar answered Sep 27 '22 02:09

Volodymyr


maybe wrap code in afterEvaluate{} will be work:

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

gradle-2.14.1 and android gradle plugin 2.2.0

details: Could not get unknown property 'assembleDebug' (2.2-beta)

like image 27
w7849516230 Avatar answered Sep 25 '22 02:09

w7849516230