Fix Gradle incompatibility issue when importing Android sample project

16,133

Solution 1

Without knowing gradle, it is quite difficult to resolve this issue.

At the same time Android Studio is an alpha release, so it can change quickly, and each version can introduce incompatible changes

Here the first doc to read about a project with Android Studio: https://developer.android.com/sdk/installing/studio-build.html

You are using AS 0.5.3 so you have to use gradle 1.10/1.11 and the gradle plugin 0.9.x

It means that in your build.gradle script you have to use:

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:0.9.+'
    }
}

May be in your file you have 0.8.3.

Also you have to use gradle 1.10/1.11. You should have a folder project_folder/gradle/wrapper where there is a file gradle-wrapper.properties.

Here you have to change the distributionUrl key to use one of these version:

distributionUrl=http://services.gradle.org/distributions/gradle-1.10-all.zip

Android Studio - Gradle - Gradle plugin have some relation:

Android Studio Gradle issue upgrading to version 0.5.0 - Gradle Migrating From 0.8 to 0.9 - Also Android Studio upgrade to 0.8.1

May be your gradle script can have other issues after these changes.

Solution 2

The only thing which worked for me, was to change where Android Studio go searching for gradle files.

Using the gradle-wrapper.properties (auto-generated) from gradle 2.10 and above it's a lot easier

Don't forget to version control the gradle-wrapper.properties as suggested here: https://docs.gradle.org/current/userguide/gradle_wrapper.html

Selection to resolve gradle versions problem

Solution 3

In the project structure settings as this in the image:

enter image description here

Share:
16,133
Sébastien
Author by

Sébastien

Android and iOS developer.

Updated on June 27, 2022

Comments

  • Sébastien
    Sébastien almost 2 years

    Android Studio (0.5.3) is driving me crazy.

    I have never had any serious issues with Eclipse and ADT. Android Studio is another story: I have not been able to get a single project to build correctly with it.

    So, I am trying to import an Android sample project (which I suppose has correct Gradle settings and should ready to be imported):

    C:\pathToMyAndroidSDK\sdk\samples\android-19\content\StorageProvider
    

    The first error I get is the following:

    Failed to refresh Gradle project 'StorageProvider'
    The project is using an unsupported version of Gradle. Please use version 1.10.
    Please point to a supported Gradle version in the project's Gradle settings or in the project's Gradle wrapper (if applicable.)
    Fix Gradle wrapper and re-import project Gradle settings
    

    OK, so I download Gradle 1.10, and change the project Gradle settings, so that it uses this local Gradle distribution instead of the default gradle wrapper (which seems to be included in the sample project).

    I get a different error this time:

    Failed to refresh Gradle project 'StorageProvider'
    The project is using an unsupported version of the Android Gradle plug-in (0.8.3).
    Version 0.9.0 introduced incompatible changes in the build language.
    Please read the migration guide to learn how to update your project.
    

    I don't know Gradle enough to migrate the configuration myself, and I don't really want to.

    How can I simply use the gradle wrapper without gettting summoned to use Gradle 1.10 (which is not compatible with the project) ? Any other solution is also welcome.

    Note: I have tried with other sample projects in the android-19 folder, only to get the same errors.


    EDIT:

    I have had more luck trying to build under Linux with the command line (gradlew build).

    The build succeeded, regardless of what I set in build.gradle:

    classpath 'com.android.tools.build:gradle:0.9.+'
    

    or

    classpath 'com.android.tools.build:gradle:0.8.+' #(the original configuration of the sample project)
    

    So my problem seems to be caused by bugs in Android Studio.

  • Sébastien
    Sébastien about 10 years
    Why do I need both a standalone install of Gradle AND a Gradle plugin (with different versions) ?
  • Gabriele Mariotti
    Gabriele Mariotti about 10 years
    The plugin is specific for android, while gradle is a generic build system
  • Mathias Asberg
    Mathias Asberg about 10 years
    This is the correct solution. The distributionUrl is old in some builds so changing that will solve the issue
  • Spentak
    Spentak almost 10 years
    I have followed these exact steps and i get "the project is using an unsupported version of Gradle. Please use version 1.10." When I change the classpath to 1.10 it says that version of Gradle cannot be found
  • Gabriele Mariotti
    Gabriele Mariotti almost 10 years
    @Spentak check the link stackoverflow.com/questions/22252956/… for your version.
  • mattdlockyer
    mattdlockyer almost 10 years
    Thanks great post, consider copying the table from your link into your post... This really helped thanks again!