I'm using Maps v2 API in my Android app. Maps used to work fine, but apparently something in the project settings changed and now I get the following error every time I launch the view with the map:
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.SupportMapFragment.onInflate(Unknown Source)
at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:269)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:685)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
I'm using Android Studio and I followed this guide to set up the library. http://forum.xda-developers.com/showthread.php?t=2328738
What am I missing?
Your setup looks like wrong so you're getting that exception because at runtime it's not possible to retrieve that resource that is part of the Google Play Services library. Basically because that guide is not update and you set a lot of stuff when you could actually avoid it.
My suggestion is:
in your build.gradle file add the dependencies to the Google Play Services Library and Support Library (this one only if you need it, it's not mandatory). Example:
buildscript { repositories { mavenCentral() } dependencies { classpath 'com.android.tools.build:gradle:0.6.1' } } apply plugin: 'android'
repositories { mavenCentral() }
android { compileSdkVersion 17 buildToolsVersion "18.0.1"
defaultConfig { minSdkVersion 10 targetSdkVersion 17 }
}
dependencies { compile 'com.android.support:support-v4:18.0.0' compile 'com.google.android.gms:play-services:3.1.+' }
follow the official guide to setup Google Maps v2 for Android: https://developers.google.com/maps/documentation/android/start#getting_the_google_maps_android_api_v2
check the new Location API to get your position: https://developer.android.com/google/play-services/location.html
I had the same problem too, apparently if you're just importing the google play service .jar file Android Studio will fail in locating the necessary resource files. Given that, I resolved it by importing both the GooglePlayService project module and the .jar file:
Go to Project Structure -> Import Module "/extras/google/google_play_services/libproject/google-play-services_lib" to your project.
Add Module dependency of the module imported to your main project
Add library 'google-play-services'(appear after importing the module) to your main project
Rebuild and it shall work fine
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.