简体   繁体   English

将项目升级到Android Studio 1.0(Gradle问题)

[英]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. 刚开始我对android开发/ android studio / gradle还是很陌生,所以如果我问一个愚蠢的问题,请原谅我。

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. 我的团队一直在使用Android Studio Beta版进行项目开发,我刚刚安装了新版本(1.0),并且已经从github远程仓库导入了我们的项目。

When trying to sync the project with gradle i get the error: Gradle version 2.1 is required. Current version is 2.2.1. 当尝试与gradle同步项目时出现错误:需要Gradle version 2.1 is required. Current version is 2.2.1. 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. 它建议我在gradle-2.1中更改distributionUrl,但是当我这样做时,我收到了gradle插件需要2.2.1的错误。

The question is why is my project requiring 2.1 and where can I change this? 问题是为什么我的项目需要2.1,在哪里可以更改呢?

Here is my gradle.build: 这是我的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'
    }
}

in the gradle-wrapper.properties use the following 在gradle-wrapper.properties中使用以下内容

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

in build.gradle use 在build.gradle中使用

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

also replace 也替换

runProguard false

with

 minifyEnabled true

I hope this can help 我希望这可以帮助

I was having the same issue that you were and had made the exact same updates as described in the Google docs. 我遇到的问题与您相同,并且所做的更新与Google文档中所述的完全相同。

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. 我犯的错误是在com.android.tools.build版本的项目文件夹根目录中编辑应用程序模块的build.gradle,而不是项目的build.gradle。

Here's the updated PROJECT's build.gradle file that I'm using that works. 这是我正在使用的更新的PROJECT的build.gradle文件。

// 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()
    }
}

To change the gradle distribution used go to this file: {Project folder}/gradle/wrapper/graddle-wrapper.properties . 要更改使用的gradle分布,请转到以下文件: {Project folder} /gradle/wrapper/graddle-wrapper.properties

Then change the distributionUrl to use 2.1: 然后将distributionUrl更改为使用2.1:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM