0

When I try to use the MapFragment based on this tutorial, and I use this layout:

<fragment
        android:name="com.google.android.gms.maps.SupportMapFragment"
        xmlns:map="http://schemas.android.com/apk/res-auto"
        android:id="@+id/map"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

I get the following crash:

10-13 20:08:09.335: ERROR/AndroidRuntime(15556): FATAL EXCEPTION: main
        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:284)
        at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:563)
        at android.view.LayoutInflater.rInflate(LayoutInflater.java:623)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:408)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
        at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:209)
        at android.app.Activity.setContentView(Activity.java:1657)
        at com.example.GoogleMapsTest.MainActivity.onCreate(MainActivity.java:18)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1615)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1667)
        at android.app.ActivityThread.access$1500(ActivityThread.java:117)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:935)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        at android.os.Looper.loop(Looper.java:130)
        at android.app.ActivityThread.main(ActivityThread.java:3687)
        at java.lang.reflect.Method.invokeNative(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:507)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:625)
        at dalvik.system.NativeStart.main(Native Method)

What should I check?

UPDATE:

Here is my manifest:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
          package="com.example.GoogleMapsTest"
          android:versionCode="1"
          android:versionName="1.0">
    <uses-sdk android:minSdkVersion="10" android:targetSdkVersion="16"/>
    <permission
            android:name="com.example.GoogleMapsTest.permission.MAPS_RECEIVE"
            android:protectionLevel="signature" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />


    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />


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


    <application android:label="@string/app_name" android:icon="@drawable/ic_launcher">
        <meta-data
                android:name="com.google.android.maps.v2.API_KEY"
                android:value="AIzaSyDIYvWvkPOFGbyjHYJngvFT85laEhKvz44" />
        <activity android:name="MainActivity"
                  android:label="@string/app_name">
            <intent-filter>
                <action android:name="android.intent.action.MAIN"/>
                <category android:name="android.intent.category.LAUNCHER"/>
            </intent-filter>
        </activity>
    </application>
</manifest>
Nestor
  • 8,194
  • 7
  • 77
  • 156

1 Answers1

1

Include Google Play Services library to your project. Read this Google play services

android_guy
  • 236
  • 1
  • 7
  • 18
  • See this too seems like the same problem as you are facing http://stackoverflow.com/questions/14372391/java-lang-noclassdeffounderror-com-google-android-gms-rstyleable – android_guy Oct 13 '13 at 18:47
  • And also see this one it may help you more http://stackoverflow.com/questions/15760834/android-java-lang-noclassdeffounderror-com-google-android-gms-rstyleable?rq=1 – android_guy Oct 13 '13 at 18:49
  • Yes, they helped to avoid the exception by adding the jar AND the whole project (I personally consider that as bad practice). Now my project starts, but I see only a white surface with the zoom buttons. Any tips why? – Nestor Oct 13 '13 at 19:30
  • have you also tried to change the permission as told in this question answer? http://stackoverflow.com/questions/15760834/android-java-lang-noclassdeffounderror-com-google-android-gms-rstyleable?rq=1 and here told the same http://stackoverflow.com/questions/15656788/google-maps-show-only-a-brown-screen-and-zoom – android_guy Oct 13 '13 at 19:37
  • I created the API key according to the tutorial. My permission looks like this: – Nestor Oct 13 '13 at 19:44
  • have you added this too in your manifest file? `` – android_guy Oct 13 '13 at 20:04
  • Yes, but no effect. The map should show some information about the problem (like the API key is not valid or the phone doesn't support the map). – Nestor Oct 13 '13 at 20:08
  • Ok go through this http://www.androidhive.info/2013/08/android-working-with-google-maps-v2/ and please make sure that you have done each step correctly and download their code to test on your device and after that make your own. – android_guy Oct 13 '13 at 20:08
  • i was the same problem but the reason was API key. – android_guy Oct 13 '13 at 20:09
  • I regenerated the key, but can't follow your tutorial as it works only over API level 12. I used this code: http://blog-emildesign.rhcloud.com/?p=435 – Nestor Oct 13 '13 at 20:20
  • All i have noticed is that there may be a problem of wrong signature or API KEY.If you have used SHA1;com.example.GoogleMapsTest format on google code to create a new key then there shouldn't any error. – android_guy Oct 13 '13 at 20:28
  • I found the problem: in the API console I enabled *Google Maps API v2* and not **Google Maps Android API v2**. Thanks for the tips. – Nestor Oct 13 '13 at 20:30