3

I want to add admob to my project and have followed the instructions from the documentation but I'm getting an error:

Cannot find symbol '@integer/google_play_services_version

inside the AndroidManifest.xml. I've looked inside the sdk directory and google_play_services version 4.0.30 is installed. Here's my build.gradle

buildscript {
  repositories {
    mavenCentral()
    }
  dependencies {
    classpath 'com.android.tools.build:gradle:0.7.+'
  }
}
apply plugin: 'android'

repositories {
    mavenCentral()
}

android {
    compileSdkVersion 19
    buildToolsVersion '19.0.0'

defaultConfig {
    minSdkVersion 15
    targetSdkVersion 19
}

compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_7
    targetCompatibility JavaVersion.VERSION_1_7
}
buildTypes {
    release {
        runProguard true
        proguardFile getDefaultProguardFile('proguard-android.txt')
    }
}
productFlavors {
    defaultFlavor {
        proguardFile 'proguard-rules.txt'
    }
  }
}

dependencies {
    compile files('libs/libGoogleAnalyticsServices.jar')
    compile 'com.google.android.gms:play-services:4.0.30'
}

After adding it, I've synced the project with gradle. I also have the required entry in AndroidManifest.xml which gives me the error

<meta-data android:name="com.google.android.gms.version"
        android:value="@integer/google_play_services_version" />

The official docs say that for android studio we don't need to include the library but I don't understand why it doesn't find it.


Edit: I finally solved it. The problem was that I was using the wrong sdk. Android studio ships with its own SDK and that was set as default in the IDE.

To fix

  • Change your project's SDK from android-studio\\sdk to android-sdk. If you don't know how, here's how.
  • If you get an error about build tools not found make sure the version in your build.gradle corresponds to your new sdk's version.
Community
  • 1
  • 1
Daniel
  • 1,075
  • 2
  • 14
  • 26
  • possibly duplicate of http://stackoverflow.com/questions/21081598/import-google-play-services-library-in-android-studio/21086904#21086904 – Piyush Agarwal Jan 16 '14 at 09:36
  • @pyus13 From what you linked: "The com.google.android.gms.version number resolves fine in my manifest." - It doesn't in mine. – Daniel Jan 16 '14 at 09:39
  • If you're still getting the error, could you please post the complete logcat? Thanks. – fasteque Jan 16 '14 at 09:46
  • @Daniel make sure you have downloaded Google Repository from SDK Manager. – Piyush Agarwal Jan 16 '14 at 10:10
  • @Daniel regarding your edit, if your local.properties file have different SDK path than Project sdk , Android Studio is smart enough to tell you that there is some conflicts in sdk paths in your local.properties in a dialog and you can correct it by just clicking on a button in dialog so no need to bother about about local.properties file. – Piyush Agarwal Jan 16 '14 at 11:43
  • @pyus13 It didn't for me. – Daniel Jan 16 '14 at 13:56
  • 1
    @Daniel it is introduced in AS 0.3.7 release which version of studio are you using ? – Piyush Agarwal Jan 16 '14 at 18:18
  • 1
    @pyus13 AS 0.4 Sorry about about, I edited my question in a hurry. What I meant to say was that `build.gradle` had the `buildToolsVersion '19.0.0'` and the new sdk had version `19.0.1`, so I got an error because of that. Thanks for noticing. And yes, you are correct, the `local.properties` file was modified by the IDE :) – Daniel Jan 16 '14 at 18:38
  • Thanks a ton. @Daniel. You've saved my day. Mwaaaah :) – Partha Chakraborty Jun 03 '16 at 09:01

1 Answers1

3

You must have Google Repository installed in order to use Google Play Services in Android Studio.

If not Installed it from SDK Manager > Extras.

After Installation your library should be located on path

 $SDK_DIR\extras\google\m2repository\com\google\android\gms\play-services
Piyush Agarwal
  • 25,608
  • 8
  • 98
  • 111