Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Upgrading project to Android Studio 1.0 (Gradle problems)

Just to start I'm very new to android development/android studio/gradle so forgive me if I'm asking a stupid question.

My team has been working on a project with the beta version of android studio, I've just installed the new version (1.0) and i've imported our project from the github remote repo.

When trying to sync the project with gradle i get the error: Gradle version 2.1 is required. Current version is 2.2.1. It recommends that I change the distributionUrl in gradle-2.1 but when I do I get the error that the gradle plugin requires 2.2.1.

The question is why is my project requiring 2.1 and where can I change this?

Here is my gradle.build:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 21
    buildToolsVersion "21.1.0"

    defaultConfig {
        applicationId "com.<teamName>.<projectName>"
        minSdkVersion 14
        targetSdkVersion 21
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            runProguard false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
}

buildscript{
    dependencies{
        classpath 'com.android.tools.build:gradle:1.0.0'
    }
}
like image 573
DomAyre Avatar asked Dec 10 '14 12:12

DomAyre


People also ask

Which Gradle version should I use for Android Studio?

If you've updated your Android Studio to 1.3. 2 version then I would suggest using Build Tools Version 23.0. 0 and compile API 23 Android 6.0. As for Gradle Version - 2.4 or higher up to latest 2.7.

Why is my Gradle build failing?

If gradle --version works, but all of your builds fail with the same error, it is possible there is a problem with one of your Gradle build configuration scripts. You can verify the problem is with Gradle scripts by running gradle help which executes configuration scripts, but no Gradle tasks.


3 Answers

in the gradle-wrapper.properties use the following

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

in build.gradle use

dependencies {
        classpath 'com.android.tools.build:gradle:1.0.+'

also replace

runProguard false

with

 minifyEnabled true

I hope this can help

like image 98
Nobel Avatar answered Sep 28 '22 16:09

Nobel


I was having the same issue that you were and had made the exact same updates as described in the Google docs.

The error I was making was editing my app module's build.gradle, and not the project's build.gradle in the root of the project folder for the com.android.tools.build version.

Here's the updated PROJECT's build.gradle file that I'm using that works.

// Top-level build file where you can add configuration options common to all sub-  projects/modules.

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:1.0.0'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}


ext {
    compileSdkVersion = 21
    buildToolsVersion = "20.0.0"

    minSdkVersion = 15
    targetSdkVersion = 21
}

allprojects {
    repositories {
        jcenter()
    }
}
like image 43
activelogic Avatar answered Sep 28 '22 17:09

activelogic


To change the gradle distribution used go to this file: {Project folder}/gradle/wrapper/graddle-wrapper.properties.

Then change the distributionUrl to use 2.1:

distributionUrl=https\://services.gradle.org/distributions/gradle-2.1-all.zip
like image 39
Joel Avatar answered Sep 28 '22 16:09

Joel