[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):
List myDependencies = ["com.android.support:appcompat-v7:18.0.+"]
//moved into List above, so there'll be nothing here.
- Also add your Google Play Library in your dependency. We'll use fileTree(). Example:
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:
List myDependencies = ["com.android.support:appcompat-v7:18.0.+",
fileTree (dir: 'E://Android/Development/Lib', includes: ['*.jar'])]
- 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.