简体   繁体   English

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

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

I'm using Maps v2 API in my Android app. 我在Android应用中使用Maps v2 API。 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. 我正在使用Android Studio,并且按照本指南设置了库。 http://forum.xda-developers.com/showthread.php?t=2328738 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. 您的设置看起来像是错误的,因此您会遇到该异常,因为在运行时无法检索属于Google Play服务库的资源。 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"; 在SDK管理器中,从Extras下载“ Android支持库”,“ Android支持存储库”和“ Google Play服务”;
  • 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). 在build.gradle文件中,将依赖项添加到Google Play服务库和支持库(仅在需要时使用此库,这不是必需的)。 Example: 例:

    buildscript { repositories { mavenCentral() } dependencies { classpath 'com.android.tools.build:gradle:0.6.1' } } apply plugin: 'android' buildscript {仓库{mavenCentral()}依赖项{classpath'com.android.tools.build:gradle:0.6.1'}} Apply插件:'android'

    repositories { mavenCentral() } 存储库{mavenCentral()}

    android { compileSdkVersion 17 buildToolsVersion "18.0.1" 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.+' } 依赖项{编译'com.android.support:support-v4:18.0.0'编译'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. 我也遇到了同样的问题,显然,如果您只是导入google play服务.jar文件,Android Studio将无法找到所需的资源文件。 Given that, I resolved it by importing both the GooglePlayService project module and the .jar file: 鉴于此,我通过导入GooglePlayService项目模块和.jar文件来解决该问题:

  1. Go to Project Structure -> Import Module "/extras/google/google_play_services/libproject/google-play-services_lib" to your project. 转到项目结构->导入模块“ / extras / google / google_play_services / libproject / google-play-services_lib”到您的项目。

  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 将库“ google-play-services”(在导入模块后显示)添加到您的主项目

Rebuild and it shall work fine 重建,它将正常工作

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 运行时错误:java.lang.NoClassDefFoundError:com.google.android.gms.R $ styleable - Run Time Error : java.lang.NoClassDefFoundError: com.google.android.gms.R$styleable java.lang.noclassdeffounderror:com.google.android.gms.R $ styleable没什么帮助我的 - java.lang.noclassdeffounderror: com.google.android.gms.R$styleable nothing helped me Android错误:SDK23 v SDK19-java.lang.NoClassDefFoundError:com.google.android.gms.R $ string - Android Error: SDK23 v SDK19 - java.lang.NoClassDefFoundError: com.google.android.gms.R$string Android错误:java.lang.NoClassDefFoundError:com.google.android.gms.R $ string - Android error: java.lang.NoClassDefFoundError: com.google.android.gms.R$string java.lang.NoClassDefFoundError: com.google.android.gms.R$字符串 - java.lang.NoClassDefFoundError: com.google.android.gms.R$string java.lang.NoClassDefFoundError:com.google.android.gms.gcm.GoogleCloudMessaging使用java.lang.NoClassDefFoundError: - java.lang.NoClassDefFoundError: com.google.android.gms.gcm.GoogleCloudMessaging using java.lang.NoClassDefFoundError: java.lang.NoSuchFieldError:com.google.android.gms.R $ string.location_client_powered_by_google - java.lang.NoSuchFieldError: com.google.android.gms.R$string.location_client_powered_by_google Google AdMob java.lang.NoClassDefFoundError:com.google.android.gms.ads.AdView - Google AdMob java.lang.NoClassDefFoundError: com.google.android.gms.ads.AdView Android)java.lang.NoClassDefFoundError:com.google.android.gms.internal.zzno - Android ) java.lang.NoClassDefFoundError: com.google.android.gms.internal.zzno java.lang.NoClassDefFoundError:com.google.android.gms.common.internal.zzbo - java.lang.NoClassDefFoundError: com.google.android.gms.common.internal.zzbo
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM