Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add Google Play Services to Android Studio using Gradle

Tags:

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:

setContentView(R.layout.activity_mapui);

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

layout file

<fragment xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/map"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:name="com.google.android.gms.maps.MapFragment"/>

But the app crashes on the device

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

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

like image 844
A7madev Avatar asked Nov 01 '13 17:11

A7madev


People also ask

How do I import Google Play Services?

To do this, select File > Import, and then select Android > Existing Android Code into Workspace, and browse to the google-play-services_lib project. After google-play-services_lib is successfully imported into your workspace, it needs to be marked as an Android library project.

Where do I put Google-services JSON?

The google-services. json file is generally placed in the app/ directory (at the root of the Android Studio app module).


2 Answers

Add this line in the dependencies section of your build.gradle file:

compile 'com.google.android.gms:play-services:3.2.+'

You don't need to add a .jar to your libs folder.

Edit

As Varun pointed out, you also need to update the SDK to contain the most recent version of the play services.

You can do this by opening up the Android SDK Manager (under the Window tab) from Eclipse+ADT, checking the box next to Google Play services in the Extras folder, and clicking install.

like image 92
Matt Logan Avatar answered Oct 23 '22 23:10

Matt Logan


enter image description here

enter image description here

Hit check on all tools, to be safe

enter image description here

Hit check on API you are working with

enter image description here

Hit check on all extras to be safe

enter image description here

Go to file -> project structure

enter image description here

enter image description here

enter image description here

Finally go to build at the top of the screen and hit rebuild project

like image 31
AndyRoid Avatar answered Oct 23 '22 21:10

AndyRoid