4

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.

Gabriele Mariotti
  • 320,139
  • 94
  • 887
  • 841
Sébastien
  • 13,831
  • 10
  • 55
  • 70

3 Answers3

5

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.

Community
  • 1
  • 1
Gabriele Mariotti
  • 320,139
  • 94
  • 887
  • 841
  • Why do I need both a standalone install of Gradle AND a Gradle plugin (with different versions) ? – Sébastien Mar 29 '14 at 15:06
  • The plugin is specific for android, while gradle is a generic build system – Gabriele Mariotti Mar 29 '14 at 15:33
  • This is the correct solution. The distributionUrl is old in some builds so changing that will solve the issue – Mathias Asberg Apr 16 '14 at 11:00
  • 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 – Spentak Jun 04 '14 at 20:33
  • @Spentak check the link http://stackoverflow.com/questions/22252956/android-studio-gradle-issue-upgrading-to-version-0-5-0-gradle-migrating-from-0/22256954#22256954 for your version. – Gabriele Mariotti Jun 04 '14 at 21:45
  • Thanks great post, consider copying the table from your link into your post... This really helped thanks again! – mattdlockyer Jul 24 '14 at 19:27
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

MatPag
  • 41,742
  • 14
  • 105
  • 114
1

In the project structure settings as this in the image:

enter image description here

bibi
  • 3,671
  • 5
  • 34
  • 50