1

As many I get the following error: java.lang.noclassdeffounderror: com.google.android.gms.R$styleable when trying to implement Maps for Android V2.

Somehow I must be missing what I exactly am doing wrong, since it's not working. What I tried first is to copy the google-play-services.lib into the lib folder, but I saw somewhere I shouldn't do this.

Then I tried to import addon-google_apis-google-8 as a project, but the project gives the error The import com.google cannot be resolved.

I'm following the Vogella Tutorial:

Activity:

SupportMapFragment fm = (SupportMapFragment)   getSupportFragmentManager().findFragmentById(R.id.map);
        map = fm.getMap();

         //map = ((MapFragment) getFragmentManager().findFragmentById(R.id.map)).getMap();
                Marker hamburg = map.addMarker(new MarkerOptions().position(HAMBURG)
                    .title("Hamburg"));
                Marker kiel = map.addMarker(new MarkerOptions()
                    .position(KIEL)
                    .title("Kiel")
                    .snippet("Kiel is cool")
                    .icon(BitmapDescriptorFactory
                        .fromResource(R.drawable.btn_logo)));

                // Move the camera instantly to hamburg with a zoom of 15.
                map.moveCamera(CameraUpdateFactory.newLatLngZoom(HAMBURG, 15));

                // Zoom in, animating the camera.
                map.animateCamera(CameraUpdateFactory.zoomTo(10), 2000, null);

Manifest:

 <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="17" />

    <permission
        android:name="com.testmap.test.permission.MAPS_RECEIVE"
        android:protectionLevel="signature" />

    <uses-permission android:name="com.testmap.test.permission.MAPS_RECEIVE" />
    <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_FINE_LOCATION"/>
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>  
    <uses-permission android:name="android.permission.WRITE_SETTINGS" />
   uses-permission android:name="android.permission.INTERNET" />
   <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
     <uses-feature
        android:glEsVersion="0x00020000"
        android:required="true" />

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

I retrieved a_real_api_key by entering the SHA1 retrieved by installing the keytool plugin.. http://keytool.sourceforge.net/update fingerprint;com.testmap.test in the google console.

And xml:

 <fragment
        android:id="@+id/map"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        class="com.google.android.gms.maps.SupportMapFragment" />

I have the feeling I need to import the google-play-services library, can somebody tell me step by step how to do this in Eclipse, I've followed many answers, but I seem to do something wrong every time.

4

1 回答 1

11

是的你是对的。您需要google_play_services_lib将其作为库导入并添加到您的项目中。

为此,您需要:

  1. Google Play Services从 Android SDK 管理器下载

  2. 通过“导入现有的 Android 代码库”将其添加为项目。转到 ~/<android_sdk>/extras/google/google_play_services/libproject并将其添加到您的工作区。

  3. 将此项目添加到您的工作区后,右键单击它,转到“属性”,然后转到“Android”选项卡并将其标记为库。

  4. 转到您的应用程序,然后右键单击以转到“属性”并转到“Android”选项卡,然后在“库”窗格中单击“添加库”。这应该向您展示该google_play_services 项目。将此添加为对您的项目的引用。

  5. 另一个要求是右键单击您的项目并转到“Android 工具”选项和“添加支持库...”。

这应该让地图运行。

注意:我们必须将 Google Play 服务添加为“现有 Android 代码库”项目,而不是 JAR。

于 2013-08-20T00:52:22.590 回答