1

I tried to create a basic Android app using Google Maps APIv2. I obtained my API Key on Google website. my project has this Manifest:

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

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


    <permission
            android:name="com.badprog.mygooglemapsapiv2.permission.MAPS_RECEIVE"
            android:protectionLevel="signature"/>
    <uses-permission android:name="com.badprog.mygooglemapsapiv2.permission.MAPS_RECEIVE"/>


           <uses-permission android:name="android.permission.INTERNET"/>
        <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
        <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_COARSE_LOCATION"/>
        <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>


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


    <application
        android:allowBackup="true"
        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="WSzxbPyBxPapkSGwWHy0rN_tUbrstH7Caaa8wNHM"/>          

        <activity
            android:name="com.badprog.mygooglemapsapiv2.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>

The class Activity is :

package com.badprog.mygooglemapsapiv2;

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

public class MainActivity extends Activity {

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

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }

}

My layout is:

<?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"
          android:name="com.google.android.gms.maps.MapFragment"/>

Furthermore, I have included google_play_services_lib library in my project. This app should be easy to do (according to what I have read on the web). But every time, I had the following error:

03-04 12:38:00.695: E/AndroidRuntime(1314): FATAL EXCEPTION: main
03-04 12:38:00.695: E/AndroidRuntime(1314): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.badprog.mygooglemapsapiv2/com.badprog.mygooglemapsapiv2.MainActivity}: android.view.InflateException: Binary XML file line #2: Error inflating class fragment
03-04 12:38:00.695: E/AndroidRuntime(1314):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
03-04 12:38:00.695: E/AndroidRuntime(1314):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
03-04 12:38:00.695: E/AndroidRuntime(1314):     at android.app.ActivityThread.access$600(ActivityThread.java:141)
03-04 12:38:00.695: E/AndroidRuntime(1314):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
03-04 12:38:00.695: E/AndroidRuntime(1314):     at android.os.Handler.dispatchMessage(Handler.java:99)
03-04 12:38:00.695: E/AndroidRuntime(1314):     at android.os.Looper.loop(Looper.java:137)
03-04 12:38:00.695: E/AndroidRuntime(1314):     at android.app.ActivityThread.main(ActivityThread.java:5041)
03-04 12:38:00.695: E/AndroidRuntime(1314):     at java.lang.reflect.Method.invokeNative(Native Method)
03-04 12:38:00.695: E/AndroidRuntime(1314):     at java.lang.reflect.Method.invoke(Method.java:511)
03-04 12:38:00.695: E/AndroidRuntime(1314):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
03-04 12:38:00.695: E/AndroidRuntime(1314):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
03-04 12:38:00.695: E/AndroidRuntime(1314):     at dalvik.system.NativeStart.main(Native Method)
03-04 12:38:00.695: E/AndroidRuntime(1314): Caused by: android.view.InflateException: Binary XML file line #2: Error inflating class fragment
03-04 12:38:00.695: E/AndroidRuntime(1314):     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
03-04 12:38:00.695: E/AndroidRuntime(1314):     at android.view.LayoutInflater.inflate(LayoutInflater.java:466)
03-04 12:38:00.695: E/AndroidRuntime(1314):     at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
03-04 12:38:00.695: E/AndroidRuntime(1314):     at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
03-04 12:38:00.695: E/AndroidRuntime(1314):     at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:270)
03-04 12:38:00.695: E/AndroidRuntime(1314):     at android.app.Activity.setContentView(Activity.java:1881)
03-04 12:38:00.695: E/AndroidRuntime(1314):     at com.badprog.mygooglemapsapiv2.MainActivity.onCreate(MainActivity.java:12)
03-04 12:38:00.695: E/AndroidRuntime(1314):     at android.app.Activity.performCreate(Activity.java:5104)
03-04 12:38:00.695: E/AndroidRuntime(1314):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
03-04 12:38:00.695: E/AndroidRuntime(1314):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
03-04 12:38:00.695: E/AndroidRuntime(1314):     ... 11 more
03-04 12:38:00.695: E/AndroidRuntime(1314): Caused by: java.lang.IllegalStateException: The meta-data tag in your app's AndroidManifest.xml does not have the right value.  Expected 4242000 but found 0.  You must have the following declaration within the <application> element:     <meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" />
03-04 12:38:00.695: E/AndroidRuntime(1314):     at com.google.android.gms.common.GooglePlayServicesUtil.n(Unknown Source)
03-04 12:38:00.695: E/AndroidRuntime(1314):     at com.google.android.gms.common.GooglePlayServicesUtil.isGooglePlayServicesAvailable(Unknown Source)
03-04 12:38:00.695: E/AndroidRuntime(1314):     at com.google.android.gms.maps.internal.q.v(Unknown Source)
03-04 12:38:00.695: E/AndroidRuntime(1314):     at com.google.android.gms.maps.internal.q.u(Unknown Source)
03-04 12:38:00.695: E/AndroidRuntime(1314):     at com.google.android.gms.maps.MapsInitializer.initialize(Unknown Source)
03-04 12:38:00.695: E/AndroidRuntime(1314):     at com.google.android.gms.maps.MapFragment$b.ex(Unknown Source)
03-04 12:38:00.695: E/AndroidRuntime(1314):     at com.google.android.gms.maps.MapFragment$b.a(Unknown Source)
03-04 12:38:00.695: E/AndroidRuntime(1314):     at com.google.android.gms.dynamic.a.a(Unknown Source)
03-04 12:38:00.695: E/AndroidRuntime(1314):     at com.google.android.gms.dynamic.a.onInflate(Unknown Source)
03-04 12:38:00.695: E/AndroidRuntime(1314):     at com.google.android.gms.maps.MapFragment.onInflate(Unknown Source)
03-04 12:38:00.695: E/AndroidRuntime(1314):     at android.app.Activity.onCreateView(Activity.java:4716)
03-04 12:38:00.695: E/AndroidRuntime(1314):     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:680)
03-04 12:38:00.695: E/AndroidRuntime(1314):     ... 20 more

Can anyone suggest me what is the problem? Thank you. Davide

Hungry Blue Dev
  • 1,313
  • 16
  • 30
  • possible duplicate of [After Google Play Service update to version 13 I got an error](http://stackoverflow.com/questions/19723811/after-google-play-service-update-to-version-13-i-got-an-error) – laalto Mar 04 '14 at 13:16

3 Answers3

0

you need this too on manifest file

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

after all activity tag put that

so your manifest file must be like following code:

<application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >



        <activity
            android:name="com.badprog.mygooglemapsapiv2.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.gms.version"
              android:value="@integer/google_play_services_version" />
     <meta-data
            android:name="com.google.android.maps.v2.API_KEY"
            android:value="WSzxbPyBxPapkSG..."/>        
    </application>
Shayan Pourvatan
  • 11,898
  • 4
  • 42
  • 63
0

As the error message in your logcat states:

Caused by: java.lang.IllegalStateException: The meta-data tag in your app's AndroidManifest.xml does not have the right value. Expected 4242000 but found 0. You must have the following declaration within the element:

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

So you need to add this peace of code in your Manifest file:

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

Like so:

 <application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >    

    <activity
        android:name="com.badprog.mygooglemapsapiv2.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="your_api_key"/>  

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

</application>
Emil Adz
  • 40,709
  • 36
  • 140
  • 187
0

The meta data with android.gms.version is wrong... verify it is like this in your manifest :

 <meta-data
        android:name="com.google.android.gms.version"
        android:value="@integer/google_play_services_version" />
    <meta-data
        android:name="com.google.android.maps.v2.API_KEY"
        android:value="your key" />
Decoy
  • 1,598
  • 12
  • 19