【问题标题】:NoClassDefFoundError: com.google.android.gms.R$styleableNoClassDefFoundError: com.google.android.gms.R$styleable
【发布时间】:2014-02-24 00:23:31
【问题描述】:

我遇到了这个错误

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

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

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

我的 xml 文件:

<?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>

我的活动是:

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();
}
}

我的清单是:

<?xml version="1.0" encoding="utf-8"?>

<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 play 服务,并再次导入它,但我没有添加 .jar 文件。 1. 导入模块 -> google_play_servises_lib 项目 2. + 添加库 -> google_play_servises_lib

【问题讨论】:

  • 你在使用 Android Studio 吗?

标签: android google-maps google-maps-api-2


【解决方案1】:

我发现了一些潜在的问题:

  1. 你可能在你的某个地方导入了com.google.android.gms.R 代码,而不是属于您的应用的代码。
  2. 清单上的&lt;permission&gt; 已过时;不再需要了。
  3. &lt;uses-permission android:name="ua.khuta.ALHANAi.permission.MAPS_RECEIVE"/&gt; 已过时
  4. 您的&lt;application&gt; 中缺少此内容:

     <meta-data
        android:name="com.google.android.gms.version"
        android:value="@integer/google_play_services_version" />
    
  5. 您已在您的AndroidManifest 中将Activity (MyActivity) 声明为MAINLAUNCHER 两次;删除&lt;intent-filter&gt;...&lt;/intent-filter&gt; 之一:

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

【讨论】:

  • Android 资源打包:\AndroidManifest.xml:63:错误:错误:未找到与给定名称匹配的资源(在“值”处,值为“@integer/google_play_services_version”)。但是当我按下 cntrl 和“google_play_services_version”时 - 我打开了这个文件
  • 那我认为这肯定意味着您没有正确导入库。
  • 我的问题的第一部分是关于我如何导入库的。请检查一下
  • 我没有使用IntelliJ,所以不知道库是如何导入的。对不起。
  • 我觉得和android studio中的方式一样
猜你喜欢
  • 1970-01-01
  • 2013-03-31
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多