Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android - Google Maps API v2 - SupportMapFragment Errors

I am trying to get one of my apps back up and running with the Google Maps API v2 for the first time. I created a key for my app in my keystore, extracted the SHA1 hash, acquired an API key, then did the following in-app... I included:

google-play-services.jar

as well as importing the GooglePlayServices libraryand adding it as a reference to the project. In my Java code I simply just load the layout resource.

public class Times extends Activity{
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.map);
    }
}

In the layout (res/layout/map.xml) that I am trying to instantiate I have:

<?xml version="1.0" encoding="utf-8"?>
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/map"
    android:name="com.google.android.gms.maps.SupportMapFragment"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" />

I also have the following declared in my manifest:

<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<uses-permission android:name="tinyTech.us.ua.busschedule.permission.MAPS_RECEIVE" />

<permission
    android:name="tinyTech.us.ua.busschedule.permission.MAPS_RECEIVE"
    android:protectionLevel="signature" />

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

And declared in the Application tag of the manifest:

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

When the activity is loaded, it crashes with the following errors in LogCat:

FATAL EXCEPTION: main
java.lang.NoClassDefFoundError: com.google.android.gms.R$styleable
    at com.google.android.gms.maps.GoogleMapOptions.createFromAttributes(Unknown Source)

I have attempted to research the problem, however I have been unable to find what I am looking for. Any and all help is greatly appreciated.

like image 907
Matt Clark Avatar asked Dec 05 '12 15:12

Matt Clark


5 Answers

I think i had the same problem it seems that newer versions you have to add this line at the manifest

<meta-data
    android:name="com.google.android.gms.version"
    android:value="@integer/google_play_services_version" />
like image 171
fire_at_rivky Avatar answered Oct 01 '22 08:10

fire_at_rivky


You need to extend FragmentActivity if you are using SupportMapFragment. If you are using the MapFragment you can extend Activity.

like image 31
Paul Wein Avatar answered Nov 01 '22 04:11

Paul Wein


In your layout, use

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

instead of

...    
android:name="com.google.android.gms.maps.SupportMapFragment"
...
like image 11
Rodion Altshuler Avatar answered Nov 01 '22 04:11

Rodion Altshuler


You must do this:

public class MainActivity extends android.support.v4.app.FragmentActivity{

}
like image 7
Jovan Avatar answered Nov 01 '22 03:11

Jovan


This worked for me: https://stackoverflow.com/a/13744765/1215098

Seems like you have to add Google Play services as module, not just as .jar

like image 5
uncle Lem Avatar answered Nov 01 '22 04:11

uncle Lem