简体   繁体   中英

Android Google Maps v2: java.lang.NoClassDefFoundError: com.google.android.gms.R$styleable

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:

  • Start a clean project or remove any setting you did following that guide;
  • in the SDK Manager, download from Extras "Android Support Library", "Android Support Repository" and "Google Play Services";
  • 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.+' }

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:

  1. Go to Project Structure -> Import Module "/extras/google/google_play_services/libproject/google-play-services_lib" to your project.

  2. Add Module dependency of the module imported to your main project

  3. 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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM