FORUMS

XDA Recap: This Week In Android (Apr 18 – 25)

Here in the digital XDA newsroom, we spend our days pouring over an average of … more

Sunday Debate: Custom ROMs vs. Modular Tweaks

Join us in a fun Sunday Debate on Mods and ROMs. Come with your opinions and feel free to … more

AOSP 5.1 Lollipop for Nexus Q

Google Nexus Q is an intriguing device released with Android 4.0 Ice Cream Sandwich. It was abandoned by … more

XDA Picks: Best Apps of the Week (Apr 17 – 24)

Apps are at the front and center of any smartphone experience, and with over a … more
Post Reply Subscribe to Thread Email Thread

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

26th August 2013, 05:12 PM |#1  
JoshieGeek's Avatar
OP Member
Thanks Meter: 66
 
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 ]
 
 
27th August 2013, 11:13 PM |#2  
Member
Thanks Meter: 104
 
More
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, 01:39 AM |#3  
JoshieGeek's Avatar
OP Member
Thanks Meter: 66
 
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, 03:30 PM |#4  
bamsbamx's Avatar
Senior Member
Flag Bilbo
Thanks Meter: 550
 
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 03:53 PM.
The Following User Says Thank You to bamsbamx For This Useful Post: [ View ]
28th August 2013, 04:02 PM |#5  
JoshieGeek's Avatar
OP Member
Thanks Meter: 66
 
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, 12:51 PM |#6  
Junior Member
Thanks Meter: 0
 
More
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, 09:17 PM |#7  
Junior Member
Thanks Meter: 0
 
More
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 09: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