Problem with AndroidStudio library

1

Good morning,

I try to add the compile 'com.android.support:design:22.2.0' library to my program:

   buildscript {
   repositories {
    jcenter()
}
dependencies {
    classpath 'com.android.tools.build:gradle:2.2.2'
    compile 'com.android.support:design:22.2.0'



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

And it gives me an error that tells me to install Android Support Repository

  

Error: Could not find method compile () for arguments   [com.android.support:design:22.2.0] on object of type   org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.

     

Please install the Android Support Repository from the Android SDK   Manager. Open Android SDK Manager

The problem is that I already have it installed and I do not understand why it does not detect it.

Greetings, thank you.

Edit:

Edit2:

After being a bit fiddling I think I've already found the solution, and that is that my project has 2 files build.gradle : build.gradle (MyApplication) and < em> build.gradle (app) . I added the library to the latter and it does not give any errors. Thank you all for your help.

    
asked by J.Soto 27.11.2016 в 22:02
source

3 answers

2

In Android Studio you can have several build.gradle . One that is at a general level of project, and one for each of the modules that you have within the project. Typically you only have one module within the project, the application itself, and it is within the build.gradle of that module where you have to put the dependencies.

In the text that you have pasted there is a message:

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

Basically because the build.gradle that you are using is the one of the project, not the one of your app.

Find another build.gradle that should be inside of your application, and put the dependencies there.

    
answered by 28.11.2016 / 11:17
source
2

The problem is simply configuration, if you are going to use the library:

 com.android.support:design

You must use

com.android.support:appcompat

with the same version preferably (Android Studio requires us to have updated or at least similar versions).

Therefore, in your dependencies, add in the build.gradle of your application the support library and eliminate classpath 'com.android.tools.build:gradle:2.2.2' :

dependencies {

    compile 'com.android.support:appcompat-v7:22.2.0'
    compile 'com.android.support:design:22.2.0'

}

Define the classpath of the gradle version is done in the build.gradle that is in the root of your project not in the one of the application:

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.2.2'
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        jcenter()
    }
}

Update:

Another problem that generates what is asked is that add the following definition:

  classpath 'com.google.gms:google-services:3.0.1'

inside the build.gradle:

buildscript {
    repositories {
        jcenter()
        google()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.1.4'
        classpath 'com.google.gms:google-services:3.0.1' //***Provoca error.

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

This version possibly used "compile" instead of "implementation", so when updating the problem is solved:

buildscript {

        ...
        ...
        dependencies {
            classpath 'com.android.tools.build:gradle:3.1.4'
            classpath 'com.google.gms:google-services:4.1.0'

            // NOTE: Do not place your application dependencies here; they belong
            // in the individual module build.gradle files
        }
    }
    
answered by 28.11.2016 в 16:32
0

You must install Android Support Repository.

after that compiles compile 'com.android.support:design:24.2.1'

    
answered by 27.11.2016 в 22:32