我一直在尝试将应用程序从旧的 Google Maps API 转换为新的 Google Maps API v2,并且遇到了几个令人沮丧的障碍。我目前试图弄清楚的错误是:
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 密钥是在 Google 控制台中生成的那个,我已经检查了“Google Maps 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 哈希作为他们的调试密钥。这似乎不是我的情况。有没有人知道什么可能导致这个问题?