Skip to content Skip to sidebar Skip to footer

Could Not Find Method Leftshift() For Arguments After Updating Studio 3.4

After updating studio 3.4 and Gradle version to 5.1.1 I got the error on my task as Could not find method leftShift() My task: task incrementBetaVersion << { println('Inc

Solution 1:

To solve this error, change << with doLast like this.

task incrementBetaVersion  {
    doLast {
        println("Incrementing Beta Version Number...")
        incrementVersionNumber('BetaVersionNumber')
        println("Incrementing Beta Version Number...")
        incrementVersionName('BetaVersionName')
    }
}

Left shift operator represent's doLast { }.

<< was deprecated in Gradle 4.x and removed in Gradle 5.0

From Docs:

<< for task definitions no longer works. In other words, you can not use the syntax

task myTask << { …​ }.

Use the Task.doLast() method instead, like this:

task myTask {
    doLast {
        ...
        ...
    }
}

More info here: https://discuss.gradle.org/t/could-not-find-method-leftshift-for-arguments-on-task-of-type-org-gradle-api-defaulttask/30614

https://docs.gradle.org/current/userguide/upgrading_version_4.html#changes_5.0

Solution 2:

Just Remove "<<" from Task and add your code in doLast{}

For solution of Could not find method leftShift() for arguments on task of type org.gradle.api.DefaultTask

task incrementBetaVersion << {
   // your code
}

to

task incrementBetaVersion {
   doLast {
      // your code
    }
}

Reference https://discuss.gradle.org/t/could-not-find-method-leftshift-for-arguments-on-task-of-type-org-gradle-api-defaulttask/30614/2

<< (LeftShift()) operator is deprecated in 4.x Gradle and Removed in 5.x Gradle Version.

Solution 3:

It happening because of the Left Shift operator has been replaced by doLast { }.

<< has deprecated in 4.x and removed in 5.0 version

Now you will have to change the code:

task incrementBetaVersion << {
    println("Incrementing Beta Version Number...")
    incrementVersionNumber('BetaVersionNumber')
    println("Incrementing Beta Version Number...")
    incrementVersionName('BetaVersionName')
}

to

task incrementBetaVersion  {
    doLast {
        println("Incrementing Beta Version Number...")
        incrementVersionNumber('BetaVersionNumber')
        println("Incrementing Beta Version Number...")
        incrementVersionName('BetaVersionName')
    }
}

Solution 4:

To solve this error is pretty simple.

Just replace << with doLast

See below updated code, today I fix in my cordova Android project.

task cdvPrintProps {
   doLast {
       //your code
   }
}

Solution 5:

I had this error in a Kotlin project that is using MockMaker to mock non final classes.

The solution is to change the old syntax to this new one:

task createTestResources {
    description = "Allows Mocking non-final classes and data classes in a Kotlin project"
    doLast {
        defmockMakerFile=newFile("$projectDir/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker")
        if (System.env.MOCK_MAKER != null) {
            logger.info("Using MockMaker ${System.env.MOCK_MAKER}")
            mockMakerFile.parentFile.mkdirs()
            mockMakerFile.createNewFile()
            mockMakerFile.write(System.env.MOCK_MAKER)
        } else {
            logger.info("Using default MockMaker")
        }
    }
}

Note that a few things have changed, like including the doLast block, and removing the << from the task signature. It works for me now. Hope it does for you too :-)

Post a Comment for "Could Not Find Method Leftshift() For Arguments After Updating Studio 3.4"