Cannot add task 'wrapper' as a task with that name already exists

Ben Kemp picture Ben Kemp · Dec 10, 2018 · Viewed 71.9k times · Source

When installing 'react-native init AwesomeProject' I get this error when I run react-native run-android:

Could not determine java version from '11.0.1'.

A quick google suggests I need to update the distributionUrl in the Gradle-wrapper. Having done this I am faced with a new error:

Cannot add task 'wrapper' as a task with that name already exists.

It suggests the issue is in the file:

/AwesomeProject/android/build.gradle' line: 36

which looks like this

task wrapper(type: Wrapper) {
    gradleVersion = '4.4'
    distributionUrl = distributionUrl.replace("bin", "all")
}

I've been back and forth trying to figure out what this does. It seems odd that something wouldn't work straight out of the box. Is anybody facing a similar issue?

Answer

zhouji picture zhouji · Feb 18, 2019

You can also update

task wrapper(type: Wrapper) {
    gradleVersion = '4.4'    
    distributionUrl = distributionUrl.replace("bin", "all")
}

to

wrapper {
    gradleVersion = '4.4'
    distributionUrl = distributionUrl.replace("bin", "all")
}

As

Overriding built-in tasks deprecated in 4.8 now produces an error.

Attempting to replace a built-in task will produce an error similar to the following:

Cannot add task 'wrapper' as a task with that name already exists.

see the last paragraph of Tasks & properties: https://docs.gradle.org/5.2.1/userguide/upgrading_version_4.html

and Customizing the Wrapper task: https://docs.gradle.org/5.2.1/userguide/gradle_wrapper.html#customizing_wrapper