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

Search This thread

JoshieGeek

Senior Member
Nov 4, 2011
56
67
logo.JPG


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?
which-build-gradle.JPG


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

lotdrops

Senior Member
Apr 23, 2011
131
264
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

Senior Member
Nov 4, 2011
56
67
You're welcome. And if you don't mind, please share this to your fellow developers. So that they can get benefits too.

Cheers
:highfive:

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

Senior Member
Aug 2, 2011
572
591
Bilbo
livenfun.com
there is an easier way to do this:


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

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:
  • Like
Reactions: JoshieGeek

friis1978

New member
Oct 2, 2013
1
0
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

New member
Oct 2, 2013
1
0
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:

Top Liked Posts

  • There are no posts matching your filters.
  • 18
    logo.JPG


    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?
    which-build-gradle.JPG


    - 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.
    1
    there is an easier way to do this:


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

    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
    1
    Wow! That's a great one tricks.. Thanks for sharing this.

    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