Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

assembleDebug.dependsOn not working

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.

like image 981
Androiderson Avatar asked Sep 22 '16 14:09

Androiderson


3 Answers

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

like image 102
Androiderson Avatar answered Nov 12 '22 05:11

Androiderson


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'
            }
        }
like image 32
Arthur Melo Avatar answered Nov 12 '22 05:11

Arthur Melo


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
like image 1
Malvin Avatar answered Nov 12 '22 03:11

Malvin