首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >NoClassDefFoundError: com.google.android.gms.R$styleable

NoClassDefFoundError: com.google.android.gms.R$styleable
EN

Stack Overflow用户
提问于 2014-02-23 15:11:42
回答 1查看 109关注 0票数 0

我有这个错误

代码语言:javascript
复制
NoClassDefFoundError: com.google.android.gms.R$styleable

我读了很多教程,但对我没有帮助。

  1. 项目结构->导入模块-> google服务库
  2. 我的项目->模块依赖项->添加google服务库
  3. 添加google服务jar文件。

我的xml文件:

代码语言:javascript
复制
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent" >
<fragment
        android:id="@+id/map"
        android:name="com.google.android.gms.maps.MapFragment"
        android:layout_width="match_parent"
        android:layout_height="match_parent"/>
</RelativeLayout>

我的活动是:

代码语言:javascript
复制
public class FlatOnMap extends Activity {
private GoogleMap googleMap;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.map_activity);
    try {
        initilizeMap();
    } catch (Exception e) {
        e.printStackTrace();
    }
}
private void initilizeMap() {
    if (googleMap == null) {
        googleMap = ((MapFragment) getFragmentManager().findFragmentById(
                R.id.map)).getMap();
        if (googleMap == null) {
            Toast.makeText(getApplicationContext(),
                    "Sorry! unable to create maps", Toast.LENGTH_SHORT)
                    .show();
        }
    }
}
@Override
protected void onResume() {
    super.onResume();
    initilizeMap();
}
}

我的声明是:

代码语言:javascript
复制
<?xml version="1.0" encoding="utf-8"?>

代码语言:javascript
复制
<uses-sdk
        android:minSdkVersion="7"
        android:targetSdkVersion="17"/>
<permission
        android:name="ua.khuta.ALHANAi.permission.MAPS_RECEIVE"
        android:protectionLevel="signature"/>

<uses-feature
        android:glEsVersion="0x00020000"
        android:required="true"/>

<uses-permission android:name="ua.khuta.ALHANAi.permission.MAPS_RECEIVE"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.GET_ACCOUNTS"/>
<uses-permission android:name="android.permission.CALL_PHONE"/>

<application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        >
    <activity android:name=".MyActivity"
              android:label="@string/app_name"
              android:theme="@style/Theme.AppCompat.Light.DarkActionBar"
              android:screenOrientation="portrait"
            >
        <meta-data
                android:name="android.app.default_searchable"
                android:value=".SearchResultsActivity"/>

        <intent-filter>
            <action android:name="android.intent.action.MAIN"/>
            <category android:name="android.intent.category.LAUNCHER"/>
        </intent-filter>
        <intent-filter>
            <action android:name="android.intent.action.MAIN"/>
            <category android:name="android.intent.category.LAUNCHER"/>
        </intent-filter>
    </activity>
    <activity android:name=".SearchResultsActivity"
              android:screenOrientation="portrait"
              android:theme="@style/Theme.AppCompat.Light.DarkActionBar"
            >
        <intent-filter>
            <action android:name="android.intent.action.SEARCH"/>
        </intent-filter>
        <meta-data
                android:name="android.app.searchable"
                android:resource="@xml/searchable"/>
    </activity>
    <activity android:name=".FlatInfo"/>
    <activity android:name=".FlatOnMap"/>
    <meta-data
            android:name="com.google.android.maps.v2.API_KEY"
            android:value="myApiKey"/>
</application>

</manifest>

我的解决方案:我已经更新了我的google服务,并再次导入它,但我没有添加.jar文件。1.导入模块-> google_play_servises_lib项目2. +添加库-> google_play_servises_lib

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-02-23 15:36:26

我看到一些潜在的问题:

  1. 您可能在代码中的某个地方导入了com.google.android.gms.R,而不是您的应用程序中的那个。
  2. 清单上的<permission>已经过时,不再需要了。
  3. <uses-permission android:name="ua.khuta.ALHANAi.permission.MAPS_RECEIVE"/>过时了
  4. 你在你的<application>里错过了这个
  5. 您已经将Activity (MyActivity)声明为MAIN,并在AndroidManifest中将LAUNCHER声明了两次;移除其中一个<intent-filter>...</intent-filter>
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/21970015

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档