java.lang.NoClassDefFoundError:解析失败:Lcom/google/android/gms/R$styleable;在谷歌地图集成中

     2023-04-19     130

关键词:

【中文标题】java.lang.NoClassDefFoundError:解析失败:Lcom/google/android/gms/R$styleable;在谷歌地图集成中【英文标题】:java.lang.NoClassDefFoundError: Failed resolution of: Lcom/google/android/gms/R$styleable; in google map integration 【发布时间】:2016-06-07 18:09:36 【问题描述】:

我是 Android 开发的新手。我正在使用 Eclipse 进行开发。现在我正在尝试在我的应用程序中集成谷歌地图 v2。但是我收到一个错误 java.lang.NoClassDefFoundError: Failed resolution of: Lcom/google/android/gms/R$styleable;。我已经使用以下步骤集成了它,

    在https://console.developers.google.com/ 中创建新项目并启用谷歌地图并使用SHA1 指纹生成新的android api 密钥。

    C:\Adt-bundle\sdk\extras\google\google_play_services\libproject\google-play-services_lib导入的google-play-services_lib项目

    已将 google-play-services_lib 库项目添加到我的应用程序中。

    Added Permissions ACCESS_NETWORK_STATE, ACCESS_WIFI_STATE, INTERNET, ACCESS_COARSE_LOCATION, ACCESS_FINE_LOCATION, WRITE_EXTERNAL_STORAGE 在我的清单中还添加了使用我的应用程序包名称进行映射的权限,

**

<permission android:name="myPackageName.permission.MAPS_RECEIVE" android:protectionLevel="signature" />
    <uses-permission android:name="myPackageName.permission.MAPS_RECEIVE" />
    <uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />

**

    在清单上添加了 api 密钥,

    <meta-data android:name="com.google.android.maps.v2.API_KEY"
      android:value="--myapikey--" />
    

当我在布局文件中添加 MapFragment 片段布局时,我收到一个错误 java.lang.NoClassDefFoundError: Failed resolution of: Lcom/google/android/gms/R$styleable; 这是我添加的 MapFragment 片段

> <fragment
>         android:id="@+id/map"
>         android:name="com.google.android.gms.maps.MapFragment"
>         android:layout_
>         android:layout_ />

【问题讨论】:

你在用proguard吗? 我已将 MapFragment 更改为 SupportMapFragment。然后我得到 java.lang.RuntimeException: Unable to start activity ComponentInfocom.shidhi.offerzone/com.shidhi.xxxxxx.HomeScreen: android.view.InflateException: Binary XML file line #29: Error inflating class fragment 【参考方案1】:

如果您使用带有 gradle 的 Android Studio,请在项目的 build.gradle 文件中尝试确保您的 dependencies.... 中存在以下行,以便将相关文件导入您的项目:

compile 'com.google.android.gms:play-services-maps:8.3.0'

【讨论】:

我正在使用 Eclipse 进行开发【参考方案2】:

更换你的

android:name="com.google.android.gms.maps.MapFragment"

android:name="com.google.android.gms.maps.SupportMapFragment"

【讨论】:

我也尝试过 SupportMapFragment 但我遇到了同样的错误。我试过这个教程android-er.blogspot.in/2012/12/… 这最后一次更新是在 2012 年 12 月,google map api 已经改变,找到一篇使用 google map api v3 的新文章。您的问题将得到解决。 我曾尝试过 SupportMapFragment 但我收到此错误 java.lang.RuntimeException: Unable to start activity ComponentInfocom.shidhi.offerzone/com.shidhi.xxxxxx.HomeScreen: android.view. InflateException: Binary XML file line #29: Error inflating class fragment 我正在使用 Eclipse 进行开发 compile fileTree(include: ['*.jar'], dir: 'libs') //testCompile 'junit:junit:4.12' compile 'com.android.support:appcompat-v7:23.1 .1' 编译 'com.android.support:design:23.1.1'