Browse Your Files with Ease using MK Explorer

Google has made quite an effort in perfecting the powerful and multi-faceted OS that we know as … more

How to Fix the Nexus Available Storage Bug – XDA TV

Is your Nexus device only showing half of the available storage as it should? Many … more

Don’t Forget About Birthdays with Birthday Reminder

A person’s birthday is, without a doubt,one of the most important days in his … more

Don’t Fear Flashing with I Don’t Want You!

The XDA message boards are full of various modifications, with many of these helping … more

Welcome to XDA

Search to go directly to your device's forum

Register an account

Unlock full posting privileges

Ask a question

No registration required
Post Reply

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

OP JoshieGeek

26th August 2013, 06:12 PM   |  #1  
JoshieGeek's Avatar
OP Member
Thanks Meter: 65
 
56 posts
Join Date:Joined: Nov 2011
Donate to Me
More


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: [ View ]
28th August 2013, 12:13 AM   |  #2  
Member
Thanks Meter: 76
 
54 posts
Join Date:Joined: Apr 2011
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!!
28th August 2013, 02:39 AM   |  #3  
JoshieGeek's Avatar
OP Member
Thanks Meter: 65
 
56 posts
Join Date:Joined: Nov 2011
Donate to Me
More
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

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!!

28th August 2013, 04:30 PM   |  #4  
bamsbamx's Avatar
Senior Member
Flag Bilbo
Thanks Meter: 541
 
424 posts
Join Date:Joined: Aug 2011
Donate to Me
More
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
Last edited by bamsbamx; 28th August 2013 at 04:53 PM.
The Following User Says Thank You to bamsbamx For This Useful Post: [ View ]
28th August 2013, 05:02 PM   |  #5  
JoshieGeek's Avatar
OP Member
Thanks Meter: 65
 
56 posts
Join Date:Joined: Nov 2011
Donate to Me
More
Wow! That's a great one tricks.. Thanks for sharing this.

Quote:
Originally Posted by bamsbamx

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: [ View ]
2nd October 2013, 01:51 PM   |  #6  
Junior Member
Thanks Meter: 0
 
1 posts
Join Date:Joined: Oct 2013
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.
2nd October 2013, 10:17 PM   |  #7  
Junior Member
Thanks Meter: 0
 
1 posts
Join Date:Joined: Oct 2013
Quote:
Originally Posted by JoshieGeek


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
Last edited by hasbeantaken; 2nd October 2013 at 10:27 PM. Reason: wrong class

Post Reply Subscribe to Thread

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

Advanced Search
Display Modes