Jivay
Jivay

Reputation: 1034

Including Google Play Services to Android Studio project

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.

Upvotes: 7

Views: 19677

Answers (4)

Dan J
Dan J

Reputation: 25673

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. :-)

Upvotes: 7

Jivay
Jivay

Reputation: 1034

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.

Upvotes: 10

Jasper Hughes
Jasper Hughes

Reputation: 9

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

Upvotes: -4

IanB
IanB

Reputation: 3489

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.

Upvotes: 3

Related Questions