Build Project with Gradle 2.2.1 and Android Studio 1.2.2

Question

I want switch to Android Studio from Eclipse then i download k9mail open source project and decide to import this in AS. I don't familiar with AS and Gradle and build system. I install Android Studio 1.2.2 version and Gradle 2.2.1.

When i set version 2.2.1 or 2.4 to top level Gradle, I see below error:

Error:Could not find com.android.tools.build:gradle:2.2.1.
Searched in the following locations:
file:/C:/Program Files/Android/Android    Studio/gradle/m2repository/com/android/tools/build/gradle/2.2.1/gradle-2.2.1.pom
file:/C:/Program Files/Android/Android Studio/gradle/m2repository/com/android/tools/build/gradle/2.2.1/gradle-2.2.1.jar
https://jcenter.bintray.com/com/android/tools/build/gradle/2.2.1/gradle-2.2.1.pom
https://jcenter.bintray.com/com/android/tools/build/gradle/2.2.1/gradle-2.2.1.jar
Required by:
:k-9-master:unspecified

I go to this directory (C:/Program Files/...), i have not 2.2.1 folder, i have just 1.1.0 and 1.2.3 folder.

When i changed to 1.0.0 gradle file's version, i give below error:

Error:(22, 0) Gradle DSL method not found: 'android()'
Possible causes:The project 'k-9-master' may be using a version of Gradle that does not contain the method.
The build file may be missing a Gradle plugin.
Apply Gradle plugin

I have these errors around one week. I'm tired. I am in a loop, if change to 2.2.1 have one error and else to change 1.1.0 or 1.0.0 or 1.2.3 have another error :(

Please if you have any knowledge, share with me. I am confused and i don't use Intelij before.

Solution

You are confusing

  • gradle

  • gradle plugin for android

In the top level build.gradle you have to specify the gradle plugin:

classpath 'com.android.tools.build:gradle:1.2.3'

In the gradle/wrapper/gradle-wrapper.properties you have to specify the gradle version:

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