Android 和 google 映射 api v2 清单错误
Android and google maps api v2 manifest error
我正在尝试 运行 带有地图的简单应用程序,这是我的 manifest.xml 代码
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.gpsWakeUpper"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="19"/>
<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="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">
<activity android:name="MyActivity"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
<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="xxx"/>
</activity>
</application>
</manifest>
和我的主要 activity
package com.example.gpsWakeUpper;
import android.app.Activity;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.MapFragment;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.Marker;
import com.google.android.gms.maps.model.MarkerOptions;
public class MyActivity extends FragmentActivity {
static final LatLng WROCLAW = new LatLng(51.06, 17.01);
private GoogleMap map;
/**
* Called when the activity is first created.
*/
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
map = ((MapFragment) getFragmentManager().findFragmentById(R.id.map)).getMap();
if(map!=null)
{
Marker wroclaw = map.addMarker(new MarkerOptions().position(WROCLAW).title("Wroclaw"));
map.moveCamera((CameraUpdateFactory.newLatLngZoom(WROCLAW, 15)));
}
}
}
对我来说,看起来一切正常,但我收到错误
Caused by: java.lang.IllegalStateException: A required meta-data tag in your app's AndroidManifest.xml does not exist. 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" />
所以我想知道我的 androidmanifest 文件有什么问题,有什么想法或线索吗?
您需要将两个与地图相关的 <meta-data>
元素作为 <application>
的直接 "child" - 您将其作为 <activity>
的一部分放置,这太深了而且错误。应该是这样的:
<application android:label="@string/app_name" android:icon="@drawable/ic_launcher">
<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="xxx"/>
<activity android:name="MyActivity"
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.xml
中添加以下行
<application
android:label="@string/app_name"
android:icon="@drawable/ic_launcher">
<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="AIzaSyBzJyhrJbxLDYoBVnWP8P2xrXXXXXXXXXX"/>
...........................
//your activities here
</application >
我正在尝试 运行 带有地图的简单应用程序,这是我的 manifest.xml 代码
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.gpsWakeUpper"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="19"/>
<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="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">
<activity android:name="MyActivity"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
<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="xxx"/>
</activity>
</application>
</manifest>
和我的主要 activity
package com.example.gpsWakeUpper;
import android.app.Activity;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.MapFragment;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.Marker;
import com.google.android.gms.maps.model.MarkerOptions;
public class MyActivity extends FragmentActivity {
static final LatLng WROCLAW = new LatLng(51.06, 17.01);
private GoogleMap map;
/**
* Called when the activity is first created.
*/
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
map = ((MapFragment) getFragmentManager().findFragmentById(R.id.map)).getMap();
if(map!=null)
{
Marker wroclaw = map.addMarker(new MarkerOptions().position(WROCLAW).title("Wroclaw"));
map.moveCamera((CameraUpdateFactory.newLatLngZoom(WROCLAW, 15)));
}
}
}
对我来说,看起来一切正常,但我收到错误
Caused by: java.lang.IllegalStateException: A required meta-data tag in your app's AndroidManifest.xml does not exist. 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" />
所以我想知道我的 androidmanifest 文件有什么问题,有什么想法或线索吗?
您需要将两个与地图相关的 <meta-data>
元素作为 <application>
的直接 "child" - 您将其作为 <activity>
的一部分放置,这太深了而且错误。应该是这样的:
<application android:label="@string/app_name" android:icon="@drawable/ic_launcher">
<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="xxx"/>
<activity android:name="MyActivity"
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.xml
中添加以下行<application
android:label="@string/app_name"
android:icon="@drawable/ic_launcher">
<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="AIzaSyBzJyhrJbxLDYoBVnWP8P2xrXXXXXXXXXX"/>
...........................
//your activities here
</application >