Ad

Gradle .execute Method Showing Error After Gradle Update

- 1 answer

My project was running perfect with gradle plugin version 3.0.1 after updating to version 3.4.1 I am going through sync failure.

Previously I was using wrapper 4.10.1 which is now updated to 5.1.1.

afterEvaluate(new Action<Project>() {

@Override
void execute(Project project) {
    tasks.getByName("assembleRelease").doLast {
        tasks.copyReleaseBuild.execute() //error is here
        tasks.copyReleaseBuildToXX.execute()
        tasks.copyReleaseBuildToXXXX.execute()
    }
}

copyReleaseBuild task is written something like below...

task copyReleaseBuild(type: Copy) {
    def releaseDir = getProjectProperty('releaseDir')
    if (releaseDir?.trim()) {
    //if release folder is provided
    def releaseAarFile =
            getProjectProperty('sourceCodeDir') + "/android-corekit/kit/build/outputs/aar/kit-release.aar"
    from releaseAarFile
    into releaseDir
    }

task copyReleaseBuildToXX(type: Copy) {
        from "./build/outputs/aar/kit-release.aar"
        into "../kitwrapper/libs"
    }

task copyReleaseBuildToXXXX(type: Copy) {
        from "./build/outputs/aar/kit-release.aar"
        into "../kitwrapperapp/libs"
    }
}

I have been trying to resolve from last two days but nothing is working as I lack knowledge of groovy.

Please check error log I am getting while building the project... error log

Ad

Answer

It happens because you are using an updated version of gradle (check the migration to gradle v5)

The following properties and methods of TaskInternal have been removed — use task dependencies, task rules, reusable utility methods, or the Worker API in place of executing a task directly.

  • execute()
  • executer
  • getValidators()
  • addValidator()

Now you can't call the execute method directly, but you have to use the tasks dependencies to obtain the same result.

Just define in your build.gradle:

task copyReleaseBuild {
    dependsOn 'assembleRelease'
    //...
}

and remove this:

afterEvaluate(new Action<Project>() {

@Override
void execute(Project project) {
    tasks.getByName("assembleRelease").doLast {
        tasks.copyReleaseBuild.execute() //error is here
    }
}
Ad
source: stackoverflow.com
Ad