7

I've been trying to include the latest Google Play Services library to my Android Studio project in order to use push messages and Maps API.

Since there are plenty of tutorials on how to include this library on Eclipse and CLI , there are no instructions on how to include the latest library on Android Studio.

I've been searching on many sites and one of the answers which looked to be the most fitting looked to be this one, since other ones appear to document an older version, but it still appears like I'm missing something.

I've tried to include this lib the same way I included the Facebook library to my project (which is oddly better documented for Android Studio than GooglePlay is) but it still looks like i'm missing something.

To do so, I've copied the whole folder <android-sdk>\extras\google\google_play_services\libproject\google-play-services_lib to my <project-path>\libraries\google-play-services_lib

Then in Studio, i tried to add the copied folder in Module > add > Import module, like said in the Facebook documentation or in the link provided. I must be forgetting something like a gradle file, checking a module property, i don't really know anymore what i'm doing with this lib.

EDIT: I AM alreay working on Android Studio.

Community
  • 1
  • 1
Jivay
  • 1,034
  • 3
  • 10
  • 23

4 Answers4

10

Using Android Studio, the only thing you need is to edit the build.gradle file and make sure that there are no android or google jar libraries, which means that you will need to remove jar libraries from your project (unless you're using libs like ActionbarSherlock which may need jar libs).

If you plan using Google Play Services, your build.gradle file should look like this :

dependencies {
    compile 'com.android.support:support-v4:13.0.+'
    compile 'com.android.support:support-v13:13.0.+'
    compile 'com.google.android.gms:play-services:3.1.36'
}

Pretty straightforward indeed.

Also, if you're using Facebook SDK, you will need to edit its build.gradle file and change its dependencies in accordance to your main project's build.gradle.

Jivay
  • 1,034
  • 3
  • 10
  • 23
7

There are two steps to setting this up in Android Studio with Gradle.

1) Install the required parts of the SDK.

Android Studio uses a different Android SDK location to Eclipse, so you will need to do this in Android Studio even if you previously did it for Eclipse (unless you update them to share the same SDK location).

From the Android Studio menu bar, open Tools -> Android -> SDK Manager

Under the Extras section, install these:

  • Android Support Repository
  • Android Support Library
  • Google Play services
  • Google Repository

2) Add the Gradle dependencies.

Do this in the build.gradle for your module (i.e. not the top level one for the overall Android Studio project):

dependencies {
    compile 'com.android.support:support-v4:19.0.0'
    compile 'com.android.support:support-v13:13.0.+'
    compile 'com.google.android.gms:play-services:3.1.36'
}

This might not be the minimum set of instructions required, but it worked for me. :-)

Dan J
  • 25,433
  • 17
  • 100
  • 173
3

I'm assuming you have encountered a ClassNotFound exception because of the question you have referenced. If you were working in Eclipse I would suggest making sure you have checked "is library" on the Google Play Services library project and then making sure this library project is referenced in your app project.

However for Android Studio I suggest you look at this: Android Studio with Google Play Services

The accepted answer looks relevant and presents a more complete procedure than the question you referenced.

Community
  • 1
  • 1
IanB
  • 3,489
  • 1
  • 20
  • 24
  • 1
    This looks good, but after experiencing an error which required to download the required libraries with the Android Studio built-in SDK Manager **and not the standard SDK Manager** which is used by Eclipse, the project compiles again, but i'm still having the same problem. The main difference now is that i have no Google Play Services lib project or jar in my project. Thanks anyway, thanks to you I now know that the built-in SDK Manager is not the same as the standard SDK Manager =) – Jivay Aug 13 '13 at 19:38
  • Is this the one where the lib will not show up in your IDE until you physically import the code into your IDE ? There were a few issues relating to that kicking around a few weeks ago - I just can't see them right now ... How about this - have you deleted the lib from your IDE but not from disk ? http://stackoverflow.com/questions/15742469/android-cant-import-google-play-services – IanB Aug 13 '13 at 20:21
-4

I have a quick tutorial on how to get this working using Eclipse and Android Studio, its a bit lengthy but ive had 100% success rate so far and no errors.

Gradle Library Tutorial: http://www.aetherstudios.net/pages/gradle.html