82

I try to do a demo with google maps android v2 with very simple activity, just copy code from google page: https://developers.google.com/maps/documentation/android/start#adding_the_api_key_to_your_application

for activity:

package com.example.mapdemo;

import android.app.Activity;
import android.os.Bundle;

public class MainActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
    }
}

for layout:

<?xml version="1.0" encoding="utf-8"?>
<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.MapFragment"/>

I had apply for a api key according to page and modify my androidmanifest.xml file, just like this:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.wenhai.driverschool"
    android:versionCode="1"
    android:versionName="1.0" >

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

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

    <!-- add for map2 -->
    <permission
        android:name="com.example.mapdemo.permission.MAPS_RECEIVE"
        android:protectionLevel="signature" />

    <uses-permission android:name="com.example.mapdemo.permission.MAPS_RECEIVE" />
    <uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
    <!-- External storage for caching. -->
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

    <!-- Maps API needs OpenGL ES 2.0. -->
    <uses-feature
        android:glEsVersion="0x00020000"
        android:required="true" />

    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <meta-data
            android:name="com.google.android.maps.v2.API_KEY"
            android:value="AIzaSyDVAF4WaVSVRDKJx87It8OSFP5txQcPabc" />

        <activity
            android:name=".MainActivity"
            android:label="@string/title_activity_main" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

I also reference my app to google-play-services_lib in eclipse.

but everytime, error report in logcat like this:

2-05 16:22:53.609: E/AndroidRuntime(21623): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.wenhai.driverschool/com.wenhai.driverschool.MainActivity}: android.view.InflateException: Binary XML file line #2: Error inflating class fragment
12-05 16:22:53.609: E/AndroidRuntime(21623):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1967)
12-05 16:22:53.609: E/AndroidRuntime(21623):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1992)
12-05 16:22:53.609: E/AndroidRuntime(21623):    at android.app.ActivityThread.access$600(ActivityThread.java:127)
12-05 16:22:53.609: E/AndroidRuntime(21623):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1158)
12-05 16:22:53.609: E/AndroidRuntime(21623):    at android.os.Handler.dispatchMessage(Handler.java:99)
12-05 16:22:53.609: E/AndroidRuntime(21623):    at android.os.Looper.loop(Looper.java:137)
12-05 16:22:53.609: E/AndroidRuntime(21623):    at android.app.ActivityThread.main(ActivityThread.java:4441)
12-05 16:22:53.609: E/AndroidRuntime(21623):    at java.lang.reflect.Method.invokeNative(Native Method)
12-05 16:22:53.609: E/AndroidRuntime(21623):    at java.lang.reflect.Method.invoke(Method.java:511)
12-05 16:22:53.609: E/AndroidRuntime(21623):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:823)
12-05 16:22:53.609: E/AndroidRuntime(21623):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:590)
12-05 16:22:53.609: E/AndroidRuntime(21623):    at dalvik.system.NativeStart.main(Native Method)
12-05 16:22:53.609: E/AndroidRuntime(21623): Caused by: android.view.InflateException: Binary XML file line #2: Error inflating class fragment
12-05 16:22:53.609: E/AndroidRuntime(21623):    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:697)
12-05 16:22:53.609: E/AndroidRuntime(21623):    at android.view.LayoutInflater.inflate(LayoutInflater.java:466)
12-05 16:22:53.609: E/AndroidRuntime(21623):    at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
12-05 16:22:53.609: E/AndroidRuntime(21623):    at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
12-05 16:22:53.609: E/AndroidRuntime(21623):    at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:255)
12-05 16:22:53.609: E/AndroidRuntime(21623):    at android.app.Activity.setContentView(Activity.java:1835)
12-05 16:22:53.609: E/AndroidRuntime(21623):    at com.wenhai.driverschool.MainActivity.onCreate(MainActivity.java:11)
12-05 16:22:53.609: E/AndroidRuntime(21623):    at android.app.Activity.performCreate(Activity.java:4465)
12-05 16:22:53.609: E/AndroidRuntime(21623):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
12-05 16:22:53.609: E/AndroidRuntime(21623):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1931)
12-05 16:22:53.609: E/AndroidRuntime(21623):    ... 11 more
12-05 16:22:53.609: E/AndroidRuntime(21623): Caused by: android.app.Fragment$InstantiationException: Unable to instantiate fragment com.google.android.gms.maps.MapFragment: make sure class name exists, is public, and has an empty constructor that is public
12-05 16:22:53.609: E/AndroidRuntime(21623):    at android.app.Fragment.instantiate(Fragment.java:581)
12-05 16:22:53.609: E/AndroidRuntime(21623):    at android.app.Fragment.instantiate(Fragment.java:549)
12-05 16:22:53.609: E/AndroidRuntime(21623):    at android.app.Activity.onCreateView(Activity.java:4235)
12-05 16:22:53.609: E/AndroidRuntime(21623):    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:673)
12-05 16:22:53.609: E/AndroidRuntime(21623):    ... 20 more
12-05 16:22:53.609: E/AndroidRuntime(21623): Caused by: java.lang.ClassNotFoundException: com.google.android.gms.maps.MapFragment
12-05 16:22:53.609: E/AndroidRuntime(21623):    at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61)
12-05 16:22:53.609: E/AndroidRuntime(21623):    at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
12-05 16:22:53.609: E/AndroidRuntime(21623):    at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
12-05 16:22:53.609: E/AndroidRuntime(21623):    at android.app.Fragment.instantiate(Fragment.java:571)
12-05 16:22:53.609: E/AndroidRuntime(21623):    ... 23 more

I don't know the reason for this.

If i add google-play-services.jar into my project, it will report another error:

12-05 16:34:23.269: E/AndroidRuntime(22638): FATAL EXCEPTION: main
12-05 16:34:23.269: E/AndroidRuntime(22638): java.lang.NoClassDefFoundError: com.google.android.gms.R$styleable
12-05 16:34:23.269: E/AndroidRuntime(22638):    at com.google.android.gms.maps.GoogleMapOptions.createFromAttributes(Unknown Source)
12-05 16:34:23.269: E/AndroidRuntime(22638):    at com.google.android.gms.maps.MapFragment.onInflate(Unknown Source)
12-05 16:34:23.269: E/AndroidRuntime(22638):    at android.app.Activity.onCreateView(Activity.java:4242)
12-05 16:34:23.269: E/AndroidRuntime(22638):    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:673)
12-05 16:34:23.269: E/AndroidRuntime(22638):    at android.view.LayoutInflater.inflate(LayoutInflater.java:466)
12-05 16:34:23.269: E/AndroidRuntime(22638):    at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
12-05 16:34:23.269: E/AndroidRuntime(22638):    at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
12-05 16:34:23.269: E/AndroidRuntime(22638):    at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:255)
12-05 16:34:23.269: E/AndroidRuntime(22638):    at android.app.Activity.setContentView(Activity.java:1835)
12-05 16:34:23.269: E/AndroidRuntime(22638):    at com.wenhai.driverschool.MainActivity.onCreate(MainActivity.java:11)
12-05 16:34:23.269: E/AndroidRuntime(22638):    at android.app.Activity.performCreate(Activity.java:4465)
12-05 16:34:23.269: E/AndroidRuntime(22638):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
12-05 16:34:23.269: E/AndroidRuntime(22638):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1931)
12-05 16:34:23.269: E/AndroidRuntime(22638):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1992)
12-05 16:34:23.269: E/AndroidRuntime(22638):    at android.app.ActivityThread.access$600(ActivityThread.java:127)
12-05 16:34:23.269: E/AndroidRuntime(22638):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1158)
12-05 16:34:23.269: E/AndroidRuntime(22638):    at android.os.Handler.dispatchMessage(Handler.java:99)
12-05 16:34:23.269: E/AndroidRuntime(22638):    at android.os.Looper.loop(Looper.java:137)
12-05 16:34:23.269: E/AndroidRuntime(22638):    at android.app.ActivityThread.main(ActivityThread.java:4441)
12-05 16:34:23.269: E/AndroidRuntime(22638):    at java.lang.reflect.Method.invokeNative(Native Method)
12-05 16:34:23.269: E/AndroidRuntime(22638):    at java.lang.reflect.Method.invoke(Method.java:511)
12-05 16:34:23.269: E/AndroidRuntime(22638):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:823)
12-05 16:34:23.269: E/AndroidRuntime(22638):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:590)
12-05 16:34:23.269: E/AndroidRuntime(22638):    at dalvik.system.NativeStart.main(Native Method)

Anyone can help me about this?

Elrond_EGLDer
  • 47,430
  • 25
  • 189
  • 180
mmm2006
  • 1,207
  • 2
  • 11
  • 17
  • 2
    I'm getting the same error with MapView. I added the library and I did everything as described on this page https://developers.google.com/maps/documentation/android/start but all of this was useless for me. – jumper0k Dec 05 '12 at 17:01
  • 1
    Same error.. any solution... – nilkash Jan 03 '13 at 11:42
  • 1
    I'm having the same error and couldn't find any good solution yet :( – Ricardo Otero Jan 04 '13 at 16:56
  • For see these steps as i guess its unresolved yet http://techhomeblog.wordpress.com/2013/02/23/mapfragmentmapsupportfragment/ – Tofeeq Ahmad Feb 25 '13 at 04:14
  • Try right-clicking on your project in Eclipse, select Android Tools > Add Support Library. In my case it was a stale version taken from ActionBarSherlock. – IgorGanapolsky Apr 30 '13 at 19:07
  • http://stackoverflow.com/questions/13691028/noclassdeffounderror-at-google-play-services-v2-library Ramz's answer says it all. Solved it for me! – user821863 May 03 '13 at 05:16

30 Answers30

86

In IntelliJ IDEA (updated for IntelliJ 12):

  1. Create a file ~/android-sdk/extras/google/google_play_services/libproject/google-play-services_lib/src/dummy.java containing class dummy {}.
  2. File->Import Module-> ~/android-sdk/extras/google/google_play_services/libproject/google-play-services_lib
  3. Create Module from Existing Sources
  4. Next->Next->Next->Next->Finish
  5. File->Project Structure->Modules->YourApp
  6. +->Module Dependency->Google-play-services_lib (The + button is in the top right corner of the dialog.)
  7. +->Jars or directories->~/android-sdk/extras/google/google_play_services/libproject/google-play-services_lib/libs/google-play-services.jar
  8. Use the up/down arrows to move <Module source> to the bottom of the list.

You can delete dummy.java if you like.

Edit: After using this for a while I've found that there is a small flaw/bug. IDEA will sometimes complain about not being able to open a .iml project file in the google-play-services_lib directory, despite the fact that you never told it there was a project there. If that happens, rebuilding the project solves the problem, at least until it comes back.

JJD
  • 44,755
  • 49
  • 183
  • 309
Timmmm
  • 68,359
  • 51
  • 283
  • 367
  • 3
    hi, i cannot find the `File > Import Module` option in my `Eclipse IDE`. PLease help me... – Rahmathullah M Mar 04 '13 at 03:54
  • This is for the superior IDE "IntelliJ IDEA". – Timmmm Mar 05 '13 at 11:49
  • 2
    Thanks for your answer! But it was enough for me to add module AND jar dependency in the project and everything worked! – lomza Mar 12 '13 at 14:22
  • For step 6 in Intellij 12, the + button is in the bottom left below the third pane. – Nick Mar 27 '13 at 08:15
  • @Nick: You mean 11? They moved it from there to the top-right in version 12. Check the edit I made to this answer. – Timmmm Mar 27 '13 at 15:31
  • @Timmmm, maybe it's different on the mac. It's just how you described it on my Windows box. – Nick Apr 02 '13 at 17:14
  • This looks interesting but any references on why we need to do this workaround @Timmmm? – ericn Apr 18 '13 at 10:54
  • 3
    You no longer need to add the Dummy file as Google Play Services Library has been updated with an "official dummy file" to support "some IDEs" (i.e. they made a fix for IntelliJ and Android Studio). – Guardius Jun 26 '13 at 02:10
  • This fixed my issue. Copied the google-play-services_lib folder into my projects parent folder and then followed the instructions to set a module dependency. Thanks. The process is really unintuitive. Just about got the hang of it in eclipse before switching; – speedynomads Aug 01 '13 at 10:55
33

Update

Please follow Commonsware MapV2 code snippets to get better understanding.

(It is present in Omnibus edition)

https://github.com/commonsguy/cw-omnibus/tree/master/MapsV2

Following snippet is working fine at my end.I choose to use SupportMapFragment.

Dont forget to add google-play-services.jar into your project.

MainActivity.java

package com.example.newmapview;

import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import com.google.android.gms.maps.SupportMapFragment;

public class MainActivity extends FragmentActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        SupportMapFragment fragment = new SupportMapFragment();
        getSupportFragmentManager().beginTransaction()
                .add(android.R.id.content, fragment).commit();
    }
}

manifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.newmapview"
    android:versionCode="1"
    android:versionName="1.0" >

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

    <permission
        android:name="com.example.newmapview.permission.MAPS_RECEIVE"
        android:protectionLevel="signature" />

    <uses-permission android:name="com.example.newmapview.permission.MAPS_RECEIVE" />
    <uses-permission android:name="android.permission.INTERNET" />
    <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-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="com.example.newmapview.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>

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

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

</manifest>

Here is the result

enter image description here Hope this will help.

Vipul
  • 30,898
  • 7
  • 67
  • 86
  • hi, Vipul Shah, thanks. I fond message from concole:[2012-12-06 10:20:26 - google-play-services_lib] Could not find google-play-services_lib.apk! i don't know whether this apk missing lead to my error. Can you tell me how to reference google-play-services.jar. just add it like below link:http://developer.android.com/intl/zh-CN/tools/projects/projects-eclipse.html#ReferencingLibraryProject. or add it in eclipse like below: Propertyes->java Build Path->Projects, add google-play-services_lib project. which one in your side? thanks. – mmm2006 Dec 06 '12 at 02:27
  • @mmm2006 I am afraid you might be running this application on android emulator.I am not sure but you might be facing this error because there is no play store app on emulator.Try it on actual device. – Vipul Dec 06 '12 at 04:00
  • In fact, i run it in my phone. a sony phone. – mmm2006 Dec 07 '12 at 06:39
  • Hi Vipul, can you tell me, how can I show my markers on map by using MapFragment? I have a list of latitudes and longitudes, I want to show them on map, I tried MapView but didn't work for me so I can't use ItemizedOverlay, MapFragment worked, so how to show multiple markers on MapFragment. If possible, provide me a link that has working code. – Shrikant Dec 13 '12 at 05:36
  • @VipulShah: you are rock.can you tell me why this error come because before some time it work i have developed some tutotial ---> http://dj-android.blogspot.in/2013/02/android-google-map-v2-part-1.html now same code is not working. – Dhaval Parmar Apr 12 '13 at 11:39
  • @Vipul Shah: "Dont forget to add google-play-services.jar into your project." – user3560827 Dec 08 '16 at 21:59
23

Just try to replace your layout with :

<?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="wrap_content"
       android:layout_height="match_parent" />

You need to use the SupportMapFragment for API under 11 !

Aurel

Aurel
  • 444
  • 4
  • 6
  • 3
    sorry for that, but it cannot work too in my place. error report this time:Caused by: android.app.Fragment$InstantiationException: Unable to instantiate fragment com.google.android.gms.maps.SupportMapFragment: make sure class name exists, is public, and has an empty constructor that is public. I can find SupportMapFragment in jar, but it cannot work. i don't know the reason. – mmm2006 Dec 06 '12 at 02:05
  • Hum, it seems that you need to do something like that: 1. Download the Google Play Services SDK on the Android SDK Mananger. 2. Import the project library in Eclipse. 3. Add the library to your project. 4. Be sure to have the android-support-v4.jar in your project (also available in the Android SDK Manager). 5. Create a fragment and add the name (' class="com.google.android.gms.maps.MapFragment"/>' for SDK >= 11 and 'class="com.google.android.gms.maps.MapFragment"/>' for SDK < 11). 6. Don't forget to try the sample code in a device (your app needs Google Play !) – Aurel Dec 06 '12 at 08:48
  • ok.I found i must follow this guide to refer google play service. http://developer.android.com/intl/zh-CN/tools/projects/projects-eclipse.html#ReferencingLibraryProject. but exmaple provied by google can work yet by now. :( – mmm2006 Dec 07 '12 at 06:37
  • any idea whats the View Equivalent to the Framgament to put it inside the fragments xml file ? – Harsha M V Dec 07 '12 at 14:58
  • 1
    @mmm2006: you need to extend "FragmentActivity" & not "Activity" then it should work and will not throw exception.. – Veer Dec 11 '12 at 11:45
  • @Aurel is there i way i can + more than 1 your answer? This is what i was looking for! – Paschalis Apr 03 '13 at 23:38
17

I faced the same problem ant it took me tow days to figure out a solution that worked for me :

  1. Delete the project google-play-services_lib (right click on the project delete )
  2. Delete the project containing the Google maps demo ( MainActivity in my case ) if you have one
  3. Copy the project google-play-services_lib( extras\google\google_play_services\libproject\google-play-services_lib) into your workspace then import it as General project (File->import->existing projects into workspase )
  4. Right click on your project ( in which you want to load the map ) -> Android -> add (under library ) google-play-services_lib

You should see something like this :

notice the

Note : You should not have something like this ( the project should be referred from your workspace ):

enter image description here

I think that the problem is that tow projects are referencing the same library

Community
  • 1
  • 1
zizoujab
  • 7,018
  • 8
  • 35
  • 68
  • I was adding the google play services as a Java build path library, but it needed to be added under Android/Library – marimaf Apr 19 '13 at 04:10
10

try this

http://developer.android.com/tools/projects/projects-eclipse.html#ReferencingLibraryProject

I just added the project of google services and added a reference in my project property->Android

Guilherme Muniz
  • 1,195
  • 10
  • 11
  • 2
    This was the critical fix for me, none of the other answers above helped. The difference here is actually pretty subtle - I was adding it as a dependent project through "Java Build Path", when in fact I should have been doing it through the "Android" menu. I've added that info to one of my other answers: http://stackoverflow.com/questions/13733911/google-maps-android-api-v2-sample-code-crashes/13734564#13734564 – Dan J Dec 06 '12 at 01:43
8
  1. By now, demo can work follow this link:
  2. For example demo, it can work too:

Add two jar in libs directory in your project. Follow below information. In particular, I think you need to:

  • Import the actual source for the "google-play-services_lib" project and link it as an Android library.
    • Do this through Project -> Properties -> Android -> Library, Add -> google-play-services_lib (you can right click on your project and choose Properties, then select Android).
    • Do not add it as a dependent Project through the "Java Build Path" for your project, that didn't work for me.
  • Add the google-play-services.jar and android-support-v4.jar into a "libs" folder in the sample project, and add them as "External External JARs" in "Build Path -> Configure Build Path -> Libraries".

I found this second step was necessary as I was hitting the exact same error as you when trying to use the sample code. The first step was necessary to avoid a NoClassDefFoundError in com.google.android.gms.R$styleable in my real project.

I also needed to do a Clean build and Uninstall the app from the device (from an earlier test attempt) before the sample code worked.

thanks your help very much.

Ivan Nevostruev
  • 26,025
  • 8
  • 61
  • 80
mmm2006
  • 1,207
  • 2
  • 11
  • 17
3

Maybe You must highlight this :

Note: Google Play services is not supported on the Android emulator — to develop using the APIs, you need to provide a development device such as an Android phone or tablet.

http://developer.android.com/google/play-services/setup.html

You must provide a physical development device on which you can run and debug your app. Do not use emulator. Will not working.

chameleon
  • 147
  • 3
  • 6
  • 3
    OMG! Why is this note so little at the mainpage and not big red on every page? I just f*ed almost whole day trying to get that running!!!! – shmoula Feb 19 '13 at 16:27
  • Play Services are now available on emulators running Android v4.2.2 or above. – Brian White Nov 05 '13 at 04:20
2

In your MainActivity (or in each activity you want to put the v2 map) you must extend FragmentActivity or Activity either you want to use SupportMapFragment or just MapFragment. Use MapFragment class only if you are targeting API 12 and above. Otherwise, use SupportMapFragment. It's a subtle difference but it makes the error.

Pete
  • 51,385
  • 23
  • 99
  • 140
Sheddad
  • 21
  • 1
2

As Google map is wrapped under Fragments now, extend your activity from FragmetActivity not just Activity and make sure if you use "supporrtMapFragment" then you are importing Fragment from support package only.

Pratap Singh
  • 4,097
  • 1
  • 20
  • 22
  • Google should really fix the basic example to use the `SupportMapFragment`. Doesn't work without it... – Muzikant Jun 01 '13 at 18:10
1

In my Intellij Idea project I had to add both: google-play-services_lib and google-play-services.jar to the project. And in google-play-services_lib project add google-play-services.jar too. After that, if you did all things, that described here, right, your application should be working.

jumper0k
  • 2,156
  • 2
  • 19
  • 31
  • What category do you use for the directory (classes, jar directory, sources, etc.)? – Timmmm Dec 06 '12 at 13:00
  • 1
    In Intellij Idea I'm adding google-play-services_lib like a module. What is more, Intellij Idea doesn't recognize it like a module, because src folder is empty. You should add a java file with any code into src folder, after that create module from existing sources and add it to the project in project structure. Then clear the java file. – jumper0k Dec 06 '12 at 13:16
1

It was a little difficult because it was different in the previous API, but I found a solution. Google says what to do here; according with the question we need com.google.android.gms classes so it is necessary to setup the google play services, which is just a library that we have to add to our project like this link . It's very important to import the copy of the project library google-play-services_lib not the one that is in the sdk folder. Once that's done, the tutorial from Google goes perfectly.

KatieK
  • 12,546
  • 17
  • 71
  • 84
  • also it´s important too which api you are using, api 10 or less need support library http://developer.android.com/tools/extras/support-library.html exactly wich is you error? – joseph.dev89 Dec 20 '12 at 01:01
1

Apart from many of the things mentioned before, to me it was important to mark the .jar also in Order and Export. As far as I can tell, is not usually mentioned and to me it was crucial.

Mark the lib in Order and Export

AlvaroSantisteban
  • 4,966
  • 4
  • 37
  • 59
1

relate to this suggestion : https://stackoverflow.com/a/20215481/3080835

also i had to add this to Application element in the Manifest:

<meta-data 
           android:name="com.google.android.gms.version" 
           android:value="@integer/google_play_services_version" />

and it worked perfectly.

Community
  • 1
  • 1
1

Add this dependency in build.gradle

compile 'com.google.android.gms:play-services:6.5.87'

Now this works

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <fragment
        android:id="@+id/map"
        android:name="com.google.android.gms.maps.MapFragment"
        android:layout_width="match_parent"
        android:layout_height="388dp"
        android:layout_weight="0.40" />
</LinearLayout>
yubaraj poudel
  • 3,493
  • 1
  • 26
  • 26
0

To take care of the Drive-related imports, you'll need a few jars from the Google Drive SDK. There are a few large ones, so you may want to add them individually to suit your app.

If that doesn't resolve the com.google.android.gms.* imports, the Google Play Services add-on needs to be installed (from Extras -> Google Play Services in the SDK Manager) and google-play-services.jar needs to be added to your build path.

EDIT:

In this case, the following jars were needed:

google-api-services-drive-v2-rev1-1.7.2-beta.jar

google-http-client-1.10.3-beta.jar

google-http-client-android2-1.10.3-beta.jar

google-oauth-client-1.10.1-beta.jar

google-api-client-android2-1.10.3-beta.jar

google-api-client-1.10.3-beta.jar

Bhavesh Patadiya
  • 25,555
  • 14
  • 76
  • 105
0

I had the same problem on my LG-E730 with 2.3.4 Android. The error appears before I've updated Google Play Service on my phone.

Lazy Beard
  • 297
  • 3
  • 10
0

Do not forget to actually build the google-play-services_lib!! That's why it shows the "Could not find google-play....apk". For me, on Eclipse, no other hacks were needed, but to reference the project from the Android submenu, not from Java build path, or Project references or whatever else. No manually placed jars, no nothing were actually needed for me.

annouk
  • 172
  • 2
  • 7
0

In Eclipse, it is necessary to create a separate project for google play services and reference it as a lib from your Android project instead of simply adding the jar to it. In my computer I have imported the google play services Eclipse project directly from D:\adt-bundle-windows-x86-20130219\sdk\extras\google\google_play_services\libproject\google-play-services_lib and set it to Lib project so I could reference it from my Android project.

Piovezan
  • 3,070
  • 1
  • 24
  • 37
0

It is stated on the same tutorial that

Please note that the code below is only useful for testing your settings in an application targeting Android API 12 or later

Just change your min SDK version to 12 and it will works

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

Haven's tried Aurel's workaround for older versions of the API yet.

ericn
  • 10,647
  • 12
  • 60
  • 105
0

I think it is worth mentioning (after I spent over an hour pulling out my hair) that if you are using MapFragment you cannot use FragmentActivity (SupportMapFragment will function fine in this environment). I was just about ready to give up on it.

nicmoon
  • 136
  • 1
  • 7
0

First Step http://developer.android.com/tools/projects/projects-eclipse.html#ReferencingLibraryProject Second Step http://developer.android.com/google/play-services/setup.html On that page it has a NOTE but we didn't pay attention

Note: You should be referencing a copy of the library that you copied to your source tree—you should not reference the library from the Android SDK directory.

But I think it's not a good way of documentation :)

George Nguyen
  • 2,179
  • 1
  • 15
  • 7
0

This might be of help to some. I had two projects, one which was a copy of the demo from Google and that worked fine. Another I copied into an existing project and I could not get it to run at all. And in the second failing one I was getting the error message described above.

My problem was due to a library not enabled, even though I rebuilt, imported multiple times etc. Right-click on the project -> Properties -> Java Build Path -> Order & Export tab. On the failing project the "Android Private Libraries" tab was unchecked.

Once I enabled it the project worked fine.

dubman23
  • 3
  • 3
0

i had everything what everyone above was saying and resolved the error by simply calling the super.onCreate(savedInstanceState); as first instruction in oncreate method; before it was last line in method. :| wasted whole day.

Awais
  • 212
  • 3
  • 14
0

I've this issue i just update Google Play services and make sure that you are adding the google-play-service-lib project as dependency, it's working now without any code change but i still getting "The Google Play services resources were not found. Check your project configuration to ensure that the resources are included." but this only happens when you have setMyLocationEnabled(true), anyone knows why?

eOnOe
  • 2,323
  • 2
  • 10
  • 7
0

I don't get the true solution but I solve it after doing these things:
- Tick 'Copy projects into workspace' when importing google-play-services_lib
- Don't set the minSdkVersion below 13
- If you get error with theme, try changing your layout theme to any system theme
- Re-create your project from scratch or revert everything if you get it from somewhere

Van Hung
  • 114
  • 1
  • 5
0

I got the same problem and just Installed Play Services from SDK and all problems fly away.

Harsha
  • 383
  • 1
  • 8
  • 21
0

I wrote in the activity
import com.google.android.gms.maps.SupportMapFragment;

and Eclipse gave me the red icon > click > fix projec setup.. > add archive google-play-services.jar

And finnaly it worked!!

Holyna
  • 1
0

Add Google Play Services to Your Project

To make the Google Play services APIs available to your app:

follow the steps present in this link : http://developer.android.com/google/play-services/setup.html#Setup

kkk
  • 1,653
  • 1
  • 21
  • 40
0

I faced this issue while using Android SDK for x86 in a Windows 7 64-bit machine. I downloaded the Android SDK 64-bit version, made Eclipse see it in Window > Preferences > Android > SDK location and the issue stopped occurring.

Piovezan
  • 3,070
  • 1
  • 24
  • 37
0

Please read carefully

If everything is woking same as google code then please check manifest file in my case i added geo key and map key that's why exception occurs,

Note - do not add two keys in manifest file remove map key

meta-data
        android:name="com.google.android.maps.v2.API_KEY"
        android:value="@string/google_maps_key"/>

add this code.

 <meta-data
        android:name="com.google.android.geo.API_KEY"
        android:value="@string/auto_location"/>

 <meta-data
        android:name="com.google.android.gms.version"
        android:value="@integer/google_play_services_version"/>
Yogesh Rathi
  • 5,684
  • 4
  • 42
  • 71