A7maDev A7maDev - 1 year ago 166
Android Question

Add Google Play Services to Android Studio using Gradle

Im working on simple map app, I added google-play-services.jar and its reference to gradle

dependencies {
compile files('libs/android-support-v4.jar', 'libs/google-play-services.jar')

The main activity:


GoogleMap map = ((MapFragment) getFragmentManager().findFragmentById(R.id.map)).getMap();

layout file

<fragment xmlns:android="http://schemas.android.com/apk/res/android"

But the app crashes on the device

E/AndroidRuntime﹕ FATAL EXCEPTION: main
java.lang.NoClassDefFoundError: com.google.android.gms.R$styleable at
Source) at com.google.android.gms.maps.MapFragment.onInflate(Unknown

I tried several ways, same issue, I just want to add google services to Android Studio 0.3 with Gradle 0.6+

Answer Source

As @Matt said, it is correct, I am here covered also which I did not find in the answer.

To add the Google Play Service library in your application project, follow below steps :-

1) Open the build.gradle file of your application module directory. See screenshot


2) Add new in your dependecies, here you to update the version number whenever you update the Google Play Service.

dependencies {
    compile 'com.google.android.gms:play-services:4.2.42'
    compile files('src/main/libs/gson-2.2.4.jar')


3) Now Lastly important save your file and click on Sync with Gradle Files Iconin the toolbar.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download