Unable instantiate android.gms.maps.MapFragment
Asked Answered
T

30

83

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?

Thermomotor answered 5/12, 2012 at 8:46 Comment(6)
I'm getting the same error with MapView. I added the library and I did everything as described on this page developers.google.com/maps/documentation/android/start but all of this was useless for me.Protozoal
Same error.. any solution...Overcurious
I'm having the same error and couldn't find any good solution yet :(Androw
For see these steps as i guess its unresolved yet techhomeblog.wordpress.com/2013/02/23/…Centi
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.Selfaddressed
#13691528 Ramz's answer says it all. Solved it for me!Vehicle
C
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.

Clyde answered 6/12, 2012 at 13:35 Comment(9)
hi, i cannot find the File > Import Module option in my Eclipse IDE. PLease help me...Bankhead
This is for the superior IDE "IntelliJ IDEA".Clyde
Thanks for your answer! But it was enough for me to add module AND jar dependency in the project and everything worked!Reddy
For step 6 in Intellij 12, the + button is in the bottom left below the third pane.Prostate
@Nick: You mean 11? They moved it from there to the top-right in version 12. Check the edit I made to this answer.Clyde
@Timmmm, maybe it's different on the mac. It's just how you described it on my Windows box.Prostate
This looks interesting but any references on why we need to do this workaround @Timmmm?Abie
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).Drawtube
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;Matter
B
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.

Bulley answered 5/12, 2012 at 11:8 Comment(6)
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:developer.android.com/intl/zh-CN/tools/projects/…. or add it in eclipse like below: Propertyes->java Build Path->Projects, add google-play-services_lib project. which one in your side? thanks.Thermomotor
@Thermomotor 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.Bulley
In fact, i run it in my phone. a sony phone.Thermomotor
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.Inclinometer
@VipulShah: you are rock.can you tell me why this error come because before some time it work i have developed some tutotial ---> dj-android.blogspot.in/2013/02/… now same code is not working.Nuptial
@Bulley Shah: "Dont forget to add google-play-services.jar into your project." <--- this saved me, 11:58PM, I almost carried this problem into the next day, thank you!Reggi
I
24

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

Isoline answered 5/12, 2012 at 10:42 Comment(6)
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.Thermomotor
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 !)Isoline
ok.I found i must follow this guide to refer google play service. developer.android.com/intl/zh-CN/tools/projects/…. but exmaple provied by google can work yet by now. :(Thermomotor
any idea whats the View Equivalent to the Framgament to put it inside the fragments xml file ?Piet
@mmm2006: you need to extend "FragmentActivity" & not "Activity" then it should work and will not throw exception..Astute
@Isoline is there i way i can + more than 1 your answer? This is what i was looking for!Bonnet
T
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

Trude answered 2/3, 2013 at 21:3 Comment(1)
I was adding the google play services as a Java build path library, but it needed to be added under Android/LibraryBayles
S
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

Sunup answered 5/12, 2012 at 19:14 Comment(1)
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: #13734411Goldbrick
T
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.

Thermomotor answered 7/12, 2012 at 7:49 Comment(0)
I
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.

Incurrence answered 17/2, 2013 at 8:55 Comment(2)
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!!!!Schwaben
Play Services are now available on emulators running Android v4.2.2 or above.Pollute
R
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.

Revivify answered 28/1, 2013 at 9:21 Comment(0)
H
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.

Hau answered 4/5, 2013 at 8:26 Comment(1)
Google should really fix the basic example to use the SupportMapFragment. Doesn't work without it...Olaolaf
P
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.

Protozoal answered 6/12, 2012 at 12:6 Comment(2)
What category do you use for the directory (classes, jar directory, sources, etc.)?Clyde
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.Protozoal
A
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.

Amulet answered 18/12, 2012 at 16:36 Comment(1)
also it´s important too which api you are using, api 10 or less need support library developer.android.com/tools/extras/support-library.html exactly wich is you error?Amulet
T
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

Thedrick answered 9/7, 2013 at 15:16 Comment(0)
B
1

relate to this suggestion : https://mcmap.net/q/95376/-android-maps-v2-app-crashing

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.

Berndt answered 6/2, 2014 at 18:22 Comment(0)
D
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>
Diastase answered 19/8, 2015 at 19:23 Comment(0)
A
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

Anuradhapura answered 6/12, 2012 at 13:43 Comment(0)
T
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.

Threefold answered 9/12, 2012 at 16:25 Comment(0)
A
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.

Armindaarming answered 28/3, 2013 at 1:7 Comment(0)
G
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.

Gentleman answered 17/4, 2013 at 12:2 Comment(0)
A
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.

Abie answered 18/4, 2013 at 10:53 Comment(0)
M
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.

Mcclelland answered 25/4, 2013 at 0:32 Comment(0)
C
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 :)

Chauvin answered 2/5, 2013 at 23:26 Comment(0)
W
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.

Wilbertwilborn answered 4/6, 2013 at 14:31 Comment(0)
C
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.

Carlist answered 3/9, 2013 at 16:6 Comment(0)
E
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?

Eruct answered 4/9, 2013 at 14:34 Comment(0)
L
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

Lieu answered 17/1, 2014 at 6:7 Comment(0)
D
0

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

Dermot answered 13/6, 2014 at 16:49 Comment(0)
A
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!!

Anabantid answered 27/1, 2015 at 17:17 Comment(0)
R
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

Roesler answered 10/3, 2015 at 0:50 Comment(0)
G
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.

Gentleman answered 26/3, 2015 at 11:49 Comment(0)
S
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"/>
Spectator answered 10/1, 2017 at 6:41 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.