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

后端 未结 7 1961
忘掉有多难
忘掉有多难 2020-12-02 14:46

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

Could not determine         


        
相关标签:
7条回答
  • 2020-12-02 15:28

    There's a high chance you have a "task" to run in your build.gradle file, go and remove the line related to wrapper (including its bracket and so on). Then, if you are using IntelliJ, it will automatically bring the new one to your working directory.

    0 讨论(0)
  • 2020-12-02 15:31

    I ran into the issue because I was running my task using the global gradle, and not my local gradle wrapper.

    i.e. in my current directory I had a gradlew executable.

    But I was running this command:

    gradle <task>
    

    When I should have been running:

    ./gradlew <task>
    

    Presumably because running the global gradle tries to create a local wrapper -- and one already existed.

    0 讨论(0)
  • 2020-12-02 15:35

    I have the same issue. the problem in my code was a double declaration on another Gradle file in build.gradle

    build.gradle

    apply from: otherFile.gradle
    ... build. gradle code...
    apply from: otherFile.gradle //Again 
    
    0 讨论(0)
  • 2020-12-02 15:36

    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

    0 讨论(0)
  • 2020-12-02 15:36

    As mentioned in the comments follow - https://stackoverflow.com/a/46867575/4982729:

    1. Open and edit the file app-folder/android/gradle/wrapper/gradle-wrapper.properties; update the line

      distributionUrl=https\://services.gradle.org/distributions/gradle-5.0-all.zip
      
    2. In file AwesomeProject/android/build.gradle try commenting out

      task wrapper(type: Wrapper) {
          gradleVersion = '4.4'
          distributionUrl = distributionUrl.replace("bin", "all")
      }
      
    0 讨论(0)
  • 2020-12-02 15:36

    if "gradle-wrapper.properties" file already have these codes

    distributionBase=GRADLE_USER_HOME
    distributionPath=wrapper/dists
    zipStoreBase=GRADLE_USER_HOME
    zipStorePath=wrapper/dists
    distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-all.zip
    

    then you can remove

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

    from build.gradle

    0 讨论(0)
提交回复
热议问题