Attend XDA's Second Annual Developer Conference, XDA:DevCon 2014!
5,770,637 Members 40,070 Now Online
XDA Developers Android and Mobile Development Forum

[GUIDE][HOW-TO]How to use Google Play Services library with Android Studio

Tip us?
 
JoshieGeek
Old
#1  
JoshieGeek's Avatar
Member - OP
Thanks Meter 65
Posts: 56
Join Date: Nov 2011

 
DONATE TO ME
Post [GUIDE][HOW-TO]How to use Google Play Services library with Android Studio



One thing that's actually annoying for some developers that trying to migrate to Android Studio, is when they want to referring an external libraries (for example, Google Play Services library) to their app. Android Studio is based on Gradle-build, so it's quite different. I'm experimenting this trouble for some time, and now I have the answer based on my experience and research.

Before we start, are you still a new with Android Studio? Please refer to my great getting started guide that you can find here. That guide is also posted in XDA-University. And please click "Thanks" if you found my article is helpful.

Let's get started! How to use Google Play Services library with Android Studio?

- First, open your build.gradle file. Which build.gradle file should I use?


- Copy google-play-services.jar from $ANDROID-SDK/extras/google/google_play_services/libproject/google-play-services_lib/libs to a location. Let's call this location -> $GOOGLE_PLAY_LIB

- If you have already use another dependencies (for example: Android Support library), we'll use a list. Move your "compile" part from "dependencies" to this list.
Example (I used Google Support v7):

Code:
List myDependencies = ["com.android.support:appcompat-v7:18.0.+"]

dependencies {
	//moved into List above, so there'll be nothing here.
}
- Also add your Google Play Library in your dependency. We'll use fileTree(). Example:

Code:
List myDependencies = ["com.android.support:appcompat-v7:18.0.+", fileTree (dir: '$GOOGLE_PLAY_LIB', includes: ['*.jar'])]
- Don't forget to change $GOOGLE_PLAY_LIB into your real location. Example: 'E://Android/Development/Lib'

- Now change the dependencies part:

Code:
List myDependencies = ["com.android.support:appcompat-v7:18.0.+",
        fileTree (dir: 'E://Android/Development/Lib', includes: ['*.jar'])]

dependencies {
    compile myDependencies
}
- Just wait when it compiling and making the project. And you're ready to go!

I use this tricks in my project to use Google Android Map v2, and it worked. But if you have any trouble in applying this, please tell me.
The Following 17 Users Say Thank You to JoshieGeek For This Useful Post: [ Click to Expand ]
 
lotdrops
Old
#2  
Junior Member
Thanks Meter 25
Posts: 23
Join Date: Apr 2011
Default great tutorial

Hi,
Thanks! After some hours of searching how to use a library on android studio, this tutorial is the only one which has allowed me to compile the project!!
 
JoshieGeek
Old
#3  
JoshieGeek's Avatar
Member - OP
Thanks Meter 65
Posts: 56
Join Date: Nov 2011

 
DONATE TO ME
You're welcome. And if you don't mind, please share this to your fellow developers. So that they can get benefits too.

Cheers


Quote:
Originally Posted by lotdrops View Post
Hi,
Thanks! After some hours of searching how to use a library on android studio, this tutorial is the only one which has allowed me to compile the project!!
 
bamsbamx
Old
(Last edited by bamsbamx; 28th August 2013 at 03:53 PM.)
#4  
bamsbamx's Avatar
Senior Member
Thanks Meter 532
Posts: 416
Join Date: Aug 2011
Location: Bilbo

 
DONATE TO ME
there is an easier way to do this:


Just download Google Repository & Google Play Services from SDK and put this in build.gradle:

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

repositories {
mavenCentral()
}

android {
compileSdkVersion 17
buildToolsVersion "17.0.0"

defaultConfig {
minSdkVersion 8
targetSdkVersion 18
}
}


dependencies {
compile('com.android.support:appcompat-v7:18.0.+')
compile('com.android.support:support-v4:13.0.0')
compile ('com.google.android.gms:play-services:3.2.25')
}
NOTE: if dont work, try clicking the button to the left of AVD Manager
The Following User Says Thank You to bamsbamx For This Useful Post: [ Click to Expand ]
 
JoshieGeek
Old
#5  
JoshieGeek's Avatar
Member - OP
Thanks Meter 65
Posts: 56
Join Date: Nov 2011

 
DONATE TO ME
Wow! That's a great one tricks.. Thanks for sharing this.

Quote:
Originally Posted by bamsbamx View Post
there is an easier way to do this:


Just download Google Repository & Google Play Services from SDK and put this in build.gradle:



NOTE: if dont work, try clicking the button to the left of AVD Manager
The Following User Says Thank You to JoshieGeek For This Useful Post: [ Click to Expand ]
 
friis1978
Old
#6  
Junior Member
Thanks Meter 0
Posts: 1
Join Date: Oct 2013
Default Other way of copiling Google Play library

Hey

What about this way, think this might work as well, just writing

compile files('libs/google-play-services.jar')

in dependencies. You should of course copi the jar file into your libs folder in the project.
 
hasbeantaken
Old
(Last edited by hasbeantaken; 2nd October 2013 at 09:27 PM.) Reason: wrong class
#7  
Junior Member
Thanks Meter 0
Posts: 1
Join Date: Oct 2013
Quote:
Originally Posted by JoshieGeek View Post

One thing that's actually annoying for some developers that trying to migrate to Android Studio, is when they want to referring an external libraries (for example, Google Play Services library) to their app. Android Studio is based on Gradle-build, so it's quite different. I'm experimenting this trouble for some time, and now I have the answer based on my experience and research.

[...]

I use this tricks in my project to use Google Android Map v2, and it worked. But if you have any trouble in applying this, please tell me.
That works, but only for compiling. At runtime NoClassDefFoundError is thrown. For 'SupportMapFragment' in my case

Tags
android studio, google play services, gradle, guide, how to
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes