2013-01-16 107 views
1

我一直在尝试将应用程序从旧版Google Maps API转换为新的Google Maps API版本2,并且已经遇到了一些令人沮丧的障碍。我目前正在试图找出的错误是这样的:无法找到Google Maps API v2 API密钥;使用ABS

01-16 14:59:38.414: E/AndroidRuntime(29059): Caused by: java.lang.RuntimeException: API key not found. Check that <meta-data android:name="com.google.android.maps.v2.API_KEY" android:value="your API key"/> is in the <application> element of AndroidManifest.xml 
01-16 14:59:38.414: E/AndroidRuntime(29059): at maps.y.z.a(Unknown Source) 
01-16 14:59:38.414: E/AndroidRuntime(29059): at maps.y.z.a(Unknown Source) 
01-16 14:59:38.414: E/AndroidRuntime(29059): at maps.y.z.a(Unknown Source) 
01-16 14:59:38.414: E/AndroidRuntime(29059): at maps.y.ae.a(Unknown Source) 
01-16 14:59:38.414: E/AndroidRuntime(29059): at maps.y.bu.a(Unknown Source) 
01-16 14:59:38.414: E/AndroidRuntime(29059): at maps.y.p.onCreateView(Unknown Source) 
01-16 14:59:38.414: E/AndroidRuntime(29059): at com.google.android.gms.maps.internal.IMapFragmentDelegate$Stub.onTransact(IMapFragmentDelegate.java:107) 
01-16 14:59:38.414: E/AndroidRuntime(29059): at android.os.Binder.transact(Binder.java:279) 
01-16 14:59:38.414: E/AndroidRuntime(29059): at com.google.android.gms.maps.internal.IMapFragmentDelegate$a$a.onCreateView(Unknown Source) 
01-16 14:59:38.414: E/AndroidRuntime(29059): at com.google.android.gms.maps.SupportMapFragment$a.onCreateView(Unknown Source) 
01-16 14:59:38.414: E/AndroidRuntime(29059): at com.google.android.gms.internal.d$4.a(Unknown Source) 
01-16 14:59:38.414: E/AndroidRuntime(29059): at com.google.android.gms.internal.d.a(Unknown Source) 
01-16 14:59:38.414: E/AndroidRuntime(29059): at com.google.android.gms.internal.d.onCreateView(Unknown Source) 
01-16 14:59:38.414: E/AndroidRuntime(29059): at com.google.android.gms.maps.SupportMapFragment.onCreateView(Unknown Source) 

这有我完成百思不得其解,因为我很清楚在我的清单“元数据”块是正确的格式。这里是我的清单的相关部分:

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

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

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

<uses-permission android:name="com.example.mapdemo.permission.MAPS_RECEIVE" /> 
<uses-permission android:name="android.permission.INTERNET" /> 
<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-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> 

<application 
    android:allowBackup="false" 
    android:icon="@drawable/icon" 
    android:label="@string/app_name" 
    android:theme="@style/Theme.Styled" > 
    <meta-data 
     android:name="com.google.android.maps.API_KEY" 
     android:value="my api key" /> 
    (activities and stuff) 
</application> 

我已经检查和双重检查,根据我所使用的API密钥是已在谷歌控制台中生成的一个,我有“谷歌地图Android版v2“服务打开,并且我使用正确的SHA-1作为我的调试密钥。

这让我觉得它可能与ABS不适合用新的API v2有关。这看起来不太可能,因为我已经使用ABS创建了一个不会遇到此错误的测试项目。这里是我的活动我的.xml布局文件:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" > 

    <fragment 
     android:id="@+id/map_fragment" 
     android:name="(mypackage).MapFragment" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" /> 

</RelativeLayout> 

从我的包,我引用的MapFragment是因为在这个问题上所述构建定制的片断:Using ActionBarSherlock With the New SupportMapFragment。正如我前面提到的,我使用这种方法创建了一个不会遇到上述错误的测试项目。

我在项目中引用了ABS 4.2.0和google_play_services_lib作为库。我也在我的libs /文件夹以及我的Java构建路径中使用了google_play_services.jar作为外部JAR。

我一直在寻找解决方案,但遇到此错误的每个人都只是简单地放错了他们的“元数据”块或将错误的SHA-1哈希用作其调试密钥。这似乎不是我的情况。有没有人有任何线索可以导致这个问题?

+0

(Sheepishly shuffle back)没关系的家伙;我发现了这个问题。我将名称作为“com.google.android.maps.API_KEY”而不是“com.google.android.maps.v2.API_KEY”放在“元数据”块中。 – JavaSplice

回答

0

检查

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

是在AndroidManifest.xml

的元素

更改此:

<meta-data 
     android:name="**com.google.android.maps.API_KEY**" 
     android:value="my api key" /> 

这样:

<meta-data 
     android:name="**com.google.android.maps.v2.API_KEY**" 
     android:value="my api key" /> 

希望它有帮助。

+0

此外,请确保它位于元素中。 –