Reputation: 17083
First of all: This is not a duplicate of this
Error:Could not find property 'assembleDebug' on project ':app'
The problem:
Since the update to Android Studio 2.2 (gradle plugin 2.2) You can no longer make the task assembleDebug
or assembleRelease
to be dependent on a new task in this way:
assembleDebug.dependsOn 'checkstyle'
More details in this issue
It gives you the following error:
Error:Could not get unknown property 'assembleDebug' for project ':app' of type org.gradle.api.Project.
Upvotes: 8
Views: 5878
Reputation: 702
An alternative way that I found to work in gradle version 2.2.0:
in your build.gradle file:
task dummyAssembleDebug{
dependsOn 'assembleDebug'
}
and then to use it
tasks.dummyAssembleDebug.dependsOn someTask
Upvotes: 1
Reputation: 462
put this inside buildTypes method in build.gradle for me this code worked :
task setEnvRelease << {
ant.propertyfile(
file: "src/main/assets/build.properties") {
entry(key: "EO_WS_DEPLOY_ADDR", value: "http://PRODUCTION IP")
}
}
task setEnvDebug << {
ant.propertyfile(
file: "src/main/assets/build.properties") {
entry(key: "EO_WS_DEPLOY_ADDR", value: "http://DEBUG IP TEST")
}
}
tasks.whenTaskAdded { task ->
if (task.name == 'assembleDebug') {
task.dependsOn 'setEnvDebug'
} else if (task.name == 'assembleRelease') {
task.dependsOn 'setEnvRelease'
}
}
Upvotes: 1
Reputation: 17083
An alternative is to refer to the task in the following way:
tasks.whenTaskAdded { task ->
if (task.name == 'assembleDebug') {
task.dependsOn 'checkstyle'
}
}
UPDATE
Android tasks are typically created in the "afterEvaluate" phase. Starting from 2.2, those tasks also include "assembleDebug" and "assembleRelease". To access such tasks, the user will need to use an afterEvaluate closure:
afterEvaluate {
assembleDebug.dependsOn someTask
}
Source: https://code.google.com/p/android/issues/detail?id=219732#c32
Upvotes: 23