Gradle 2.1 is required Migrate to Gradle wrapper a

2020-04-21 23:14发布

问题:

I am trying to build u202 android project by Jake Wharton. My android studio is failing to build the project. The error being shown is as below:

Gradle 2.1 is required 
Migrate to Gradle wrapper and sync project

The line where error is shown points to apply plugin: 'com.android.application' in the build.gradle file.

I have tried the following solutions but to no avail.

  1. Run gradlew from the highest project directory. However when I run this from command line, I get a message that the build was successful but when I try to sync the project in android studio I get the above mentioned error.
  2. Run gradle through command line. Since the gradle version I had in my path was of version 2.2.1, I got the error that plugin "com.android.application" cannot be found - I assume this is because I have this version of gradle-plugin in the project which needs to be updated to support newer version of gradle: 'com.android.tools.build:gradle:0.13.3'

Finally I could build the project by downloading gradle 2.1 manually and pointing the project to use local gradle instead of wrapper. I wanted to know if there is anything wrong in the way I tried to use gradle wrapper.

回答1:

Go to Settings -> Gradle and click Use default gradle wrapper (recommended). Press Apply.

After that go to project-dir/gradle/wrapper/gradle-wrapper.properties and change distributionUrl like so:

distributionUrl=https\://services.gradle.org/distributions/gradle-2.1-all.zip

Try to Build -> Make Project.

You also may need to make sure that all components (Android Studio, Gradle itself and Android Gradle plugin) can be used together. Check out this page, here we can see that Gradle 2.1 can be used on Android Studio 0.9.0 - 0.9.3 and Gradle plugin has to be of version 0.14.0 - 0.14.4.