1

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.

Supreethks
  • 597
  • 6
  • 16

1 Answers1

4

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.

aga
  • 27,954
  • 13
  • 86
  • 121
  • I already have that distribution url in the wrapper file: distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists distributionUrl=https\://services.gradle.org/distributions/gradle-2.1-all.zip – Supreethks Dec 05 '14 at 08:17
  • @Supreethks try to enable gradle wrapper in project settings, I've added info on how to do it. – aga Dec 05 '14 at 08:21
  • I did try that, enabled android studio to use wrapper and ran `Make Project` I got this build error : Error:(20) A problem occurred evaluating root project 'u2020'. > Could not create plugin of type 'AppPlugin'. – Supreethks Dec 05 '14 at 08:25
  • @Supreethks try to update android gradle plugin in `build.gradle` file also to one of the latest revisions. I used `classpath 'com.android.tools.build:gradle:1.0.0-rc4'` which works with the `Android Studio 1.0 RC 4` and project was imported w/o any issues. – aga Dec 05 '14 at 08:46
  • Changed the version of gradle plugin also still no luck. The project builds fine if I use local instance of gradle 2.1. Still cant figure out what is the problem with my gradle wrapper :( – Supreethks Dec 05 '14 at 10:11
  • @Supreethks I've changed my answer, take a look at the the last paragraph. – aga Dec 05 '14 at 10:39
  • Heard the latest release of Android studio has broken the myriad range of dependencies to version numbers. Hope a fresh install would work well. Accepting your answer as you have been very helpful. – Supreethks Dec 11 '14 at 11:54