1
votes

I am trying google analytic in my project. but found following error message after changing build.gradle file.

Error:Could not find com.google.gms:google-services:2.0.0-alpha6. Searched in the following locations: file:/home/vaibhav/android-studio/gradle/m2repository/com/google/gms/google-services/2.0.0-alpha6/google-services-2.0.0-alpha6.pom file:/home/vaibhav/android-studio/gradle/m2repository/com/google/gms/google-services/2.0.0-alpha6/google-services-2.0.0-alpha6.jar https://repo1.maven.org/maven2/com/google/gms/google-services/2.0.0-alpha6/google-services-2.0.0-alpha6.pom https://repo1.maven.org/maven2/com/google/gms/google-services/2.0.0-alpha6/google-services-2.0.0-alpha6.jar Required by: :MaterialTabs-master:unspecified

where I 1. Add the dependency to your project-level build.gradle:

classpath 'com.google.gms:google-services:2.0.0-alpha6'

2.Add the plugin to your app-level build.gradle:

apply plugin: 'com.google.gms.google-services'

and

  1. add a dependency for Google Play Services. Inside build.gradle add:

compile 'com.google.android.gms:play-services-analytics:8.4.0'

Thanks in advance.

2

2 Answers

7
votes

I had the same problem as you did, and having looked at Google Analytics Quickstart project linked by Tiem Song's answer the I think you are missing the jcenter() repository as I was.

JCenter is the now the default repository used with Android’s gradle plugin[0], but older projects were created using mavenCentral() as the default repository, which doesn't have any of the google-services.

Your build.gradle should look like.

repositories {
    ...
    jcenter()
}
dependencies {
    ...
    classpath 'com.android.tools.build:gradle:2.0.0-beta6'
    classpath 'com.google.gms:google-services:2.0.0-beta6'
}

(I have also updated the beta version from 5 to 6, but that is just to make the answer as current as possible)

Hope that helps

[0] - http://blog.bintray.com/2015/02/09/android-studio-migration-from-maven-central-to-jcenter/

0
votes

Give the beta5 versions of the dependencies a try:

classpath 'com.android.tools.build:gradle:2.0.0-beta5'
classpath 'com.google.gms:google-services:2.0.0-beta5'

The Google Analytics Quickstart project is a working Android app and includes build.gradle examples.