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+
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.
The google-services. json file is generally placed in the app/ directory (at the root of the Android Studio app module).
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.
Hit check on all tools, to be safe
Hit check on API you are working with
Hit check on all extras to be safe
Go to file -> project structure
Finally go to build
at the top of the screen and hit rebuild project
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With