2016-02-12 130 views
-2

我正在开发一个使用Google Maps API的应用程序。但是,当我在模拟器上运行应用程序时,出现以下错误:“加载地图模块失败。”谷歌地图Android V2:无法加载地图模块

我确定我从开发者控制台检查了“Google Maps API For Android”。以下是我的配置:

的Manifest.xml:

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

    <!-- 
     The ACCESS_COARSE/FINE_LOCATION permissions are not required to use 
     Google Maps Android API v2, but you must specify either coarse or fine 
     location permissions for the 'MyLocation' functionality. 


    --> 

    <permission android:name="MYPACKAGE.permission.MAPS_RECEIVE" 
    android:protectionLevel="signature"/> 
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> 
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> 
    <uses-permission android:name="android.permission.INTERNET" /> 
    <uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" /> 
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> 
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /> 

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


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

     <!-- 
      The API key for Google Maps-based APIs is defined as a string resource. 
      (See the file "res/values/google_maps_api.xml"). 
      Note that the API key is linked to the encryption key used to sign the APK. 
      You need a different API key for each encryption key, including the release key that is used to 
      sign the APK for publishing. 
      You can define the keys for the debug and release targets in src/debug/ and src/release/. 
     --> 
     <meta-data 
      android:name="com.google.android.geo.API_KEY" 
      android:value="MY_API_KEY"/> 

     <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> 

哪里MY_API_KEY是我从谷歌实际收到的API密钥。

activity_main.xml中:

<fragment xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:map="http://schemas.android.com/apk/res-auto" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:id="@+id/map" 
    android:name="com.google.android.gms.maps.SupportMapFragment" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    tools:context="MYPACKAGE.MainActivity" /> 

MainActivity.java:

package MYPACKAGE; 
import android.graphics.Color; 
import android.support.v4.app.FragmentActivity; 
import android.os.Bundle; 
import com.google.android.gms.maps.CameraUpdateFactory; 
import com.google.android.gms.maps.GoogleMap; 
import com.google.android.gms.maps.OnMapReadyCallback; 
import com.google.android.gms.maps.SupportMapFragment; 
import com.google.android.gms.maps.model.Circle; 
import com.google.android.gms.maps.model.CircleOptions; 
import com.google.android.gms.maps.model.LatLng; 
import com.google.android.gms.maps.model.MarkerOptions; 

public class MainActivity extends FragmentActivity implements OnMapReadyCallback { 

    private GoogleMap mMap; 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_main); 
     // Obtain the SupportMapFragment and get notified when the map is ready to be used. 
     SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager() 
      .findFragmentById(R.id.map); 
     mapFragment.getMapAsync(this); 
    } 

    @Override 
    public void onMapReady(GoogleMap googleMap) { 
     mMap = googleMap; 

     // Add a marker in Sydney and move the camera 
     LatLng sydney = new LatLng(-34, 151); 
     mMap.addMarker(new MarkerOptions().position(sydney).title("Marker in Sydney")); 
     mMap.moveCamera(CameraUpdateFactory.newLatLng(sydney)); 
    } 
} 

的logcat的显示我,当我尝试运行的代码如下:

02-12 03:57:57.370 1261-1261/? D/dalvikvm: Not late-enabling CheckJNI (already on) 
02-12 03:57:59.030 1261-1261/com.be2015.meetupmap I/dalvikvm: Could not find method android.app.Notification$Builder.setLocalOnly, referenced from method com.google.android.gms.common.GooglePlayServicesUtil.zza 
02-12 03:57:59.040 1261-1261/com.be2015.meetupmap W/dalvikvm: VFY: unable to resolve virtual method 240: Landroid/app/Notification$Builder;.setLocalOnly (Z)Landroid/app/Notification$Builder; 
02-12 03:57:59.040 1261-1261/com.be2015.meetupmap D/dalvikvm: VFY: replacing opcode 0x6e at 0x00c8 
02-12 03:57:59.090 1261-1261/com.be2015.meetupmap I/dalvikvm: Could not find method android.content.pm.PackageManager.getPackageInstaller, referenced from method com.google.android.gms.common.GooglePlayServicesUtil.zzh 
02-12 03:57:59.090 1261-1261/com.be2015.meetupmap W/dalvikvm: VFY: unable to resolve virtual method 542: Landroid/content/pm/PackageManager;.getPackageInstaller()Landroid/content/pm/PackageInstaller; 
02-12 03:57:59.100 1261-1261/com.be2015.meetupmap D/dalvikvm: VFY: replacing opcode 0x6e at 0x000b 
02-12 03:57:59.520 1261-1293/com.be2015.meetupmap I/GMPM: App measurement is starting up 
02-12 03:57:59.680 1261-1293/com.be2015.meetupmap E/GMPM: getGoogleAppId failed with status: 10 
02-12 03:57:59.700 1261-1293/com.be2015.meetupmap E/GMPM: Uploading is not possible. App measurement disabled 
02-12 03:58:00.240 1261-1261/com.be2015.meetupmap D/dalvikvm: GC_FOR_ALLOC freed 338K, 12% free 3048K/3452K, paused 171ms, total 213ms 
02-12 03:58:00.250 1261-1261/com.be2015.meetupmap I/zzy: Making Creator dynamically 
02-12 03:58:01.520 1261-1261/com.be2015.meetupmap I/dalvikvm: Could not find method android.app.Notification$Builder.setLocalOnly, referenced from method com.google.android.gms.common.mz.b 
02-12 03:58:01.520 1261-1261/com.be2015.meetupmap W/dalvikvm: VFY: unable to resolve virtual method 141: Landroid/app/Notification$Builder;.setLocalOnly (Z)Landroid/app/Notification$Builder; 
02-12 03:58:01.520 1261-1261/com.be2015.meetupmap D/dalvikvm: VFY: replacing opcode 0x6e at 0x00ce 
02-12 03:58:01.530 1261-1261/com.be2015.meetupmap I/dalvikvm: Could not find method android.content.pm.PackageManager.getPackageInstaller, referenced from method com.google.android.gms.common.nb.a 
02-12 03:58:01.530 1261-1261/com.be2015.meetupmap W/dalvikvm: VFY: unable to resolve virtual method 424: Landroid/content/pm/PackageManager;.getPackageInstaller()Landroid/content/pm/PackageInstaller; 
02-12 03:58:01.530 1261-1261/com.be2015.meetupmap D/dalvikvm: VFY: replacing opcode 0x6e at 0x000d 
02-12 03:58:01.630 1261-1261/com.be2015.meetupmap D/ChimeraCfgMgr: Reading stored module config 
02-12 03:58:01.680 1261-1261/com.be2015.meetupmap W/DynamiteUtils: Failed to load module: module id not found 
02-12 03:58:01.680 1261-1261/com.be2015.meetupmap W/DynamiteUtils: Attempt 1 failed. 
02-12 03:58:02.270 1261-1261/com.be2015.meetupmap W/DynamiteUtils: Failed to load module: module id not found 
02-12 03:58:02.270 1261-1261/com.be2015.meetupmap W/DynamiteUtils: Attempt 2 failed. 
02-12 03:58:02.370 1261-1261/com.be2015.meetupmap W/DynamiteUtils: Failed to load module: module id not found 
02-12 03:58:02.370 1261-1261/com.be2015.meetupmap W/DynamiteUtils: Attempt 3 failed. 
02-12 03:58:02.420 1261-1261/com.be2015.meetupmap D/dalvikvm: DexOpt: couldn't find static field Landroid/os/Build;.SUPPORTED_64_BIT_ABIS 
02-12 03:58:02.430 1261-1261/com.be2015.meetupmap W/dalvikvm: VFY: unable to resolve static field 119 (SUPPORTED_64_BIT_ABIS) in Landroid/os/Build; 
02-12 03:58:02.440 1261-1261/com.be2015.meetupmap D/dalvikvm: VFY: replacing opcode 0x62 at 0x0012 
02-12 03:58:02.440 1261-1261/com.be2015.meetupmap D/dalvikvm: DexOpt: couldn't find static field Landroid/os/Build;.SUPPORTED_32_BIT_ABIS 
02-12 03:58:02.450 1261-1261/com.be2015.meetupmap W/dalvikvm: VFY: unable to resolve static field 118 (SUPPORTED_32_BIT_ABIS) in Landroid/os/Build; 
02-12 03:58:02.450 1261-1261/com.be2015.meetupmap D/dalvikvm: VFY: replacing opcode 0x62 at 0x0021 
02-12 03:58:02.470 1261-1261/com.be2015.meetupmap D/dalvikvm: DexOpt: couldn't find static field Landroid/os/Build;.SUPPORTED_64_BIT_ABIS 
02-12 03:58:02.470 1261-1261/com.be2015.meetupmap W/dalvikvm: VFY: unable to resolve static field 119 (SUPPORTED_64_BIT_ABIS) in Landroid/os/Build; 
02-12 03:58:02.470 1261-1261/com.be2015.meetupmap D/dalvikvm: VFY: replacing opcode 0x62 at 0x0008 
02-12 03:58:02.470 1261-1261/com.be2015.meetupmap D/dalvikvm: DexOpt: couldn't find static field Landroid/os/Build;.SUPPORTED_ABIS 
02-12 03:58:02.480 1261-1261/com.be2015.meetupmap W/dalvikvm: VFY: unable to resolve static field 120 (SUPPORTED_ABIS) in Landroid/os/Build; 
02-12 03:58:02.480 1261-1261/com.be2015.meetupmap D/dalvikvm: VFY: replacing opcode 0x62 at 0x0008 
02-12 03:58:02.480 1261-1261/com.be2015.meetupmap W/DynamiteUtils: Client module failure reason: 11 
02-12 03:58:02.510 1261-1261/com.be2015.meetupmap D/maps.CreatorImpl: Module could not be loaded. 
02-12 03:58:02.570 1261-1261/com.be2015.meetupmap D/maps.CreatorImpl: Failed to load maps module. 
                      android.os.RemoteException 
                     at com.google.android.gms.maps.internal.CreatorImpl.a(SourceFile:76) 
                     at com.google.android.gms.maps.internal.CreatorImpl.b(SourceFile:96) 
                     at com.google.android.gms.maps.internal.ag.onTransact(SourceFile:62) 
                     at android.os.Binder.transact(Binder.java:361) 
                     at com.google.android.gms.maps.internal.zzc$zza$zza.zzt(Unknown Source) 
                     at com.google.android.gms.maps.SupportMapFragment$zzb.zzzh(Unknown Source) 
                     at com.google.android.gms.maps.SupportMapFragment$zzb.zza(Unknown Source) 
                     at com.google.android.gms.dynamic.zza.zza(Unknown Source) 
                     at com.google.android.gms.dynamic.zza.onInflate(Unknown Source) 
                     at com.google.android.gms.maps.SupportMapFragment.onInflate(Unknown Source) 
                     at android.support.v4.app.Fragment.onInflate(Fragment.java:1129) 
                     at android.support.v4.app.FragmentManagerImpl.onCreateView(FragmentManager.java:2283) 
                     at android.support.v4.app.FragmentController.onCreateView(FragmentController.java:111) 
                     at android.support.v4.app.FragmentActivity.dispatchFragmentsOnCreateView(FragmentActivity.java:314) 
                     at android.support.v4.app.BaseFragmentActivityHoneycomb.onCreateView(BaseFragmentActivityHoneycomb.java:31) 
                     at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:79) 
                     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:690) 
                     at android.view.LayoutInflater.inflate(LayoutInflater.java:469) 
                     at android.view.LayoutInflater.inflate(LayoutInflater.java:397) 
                     at android.view.LayoutInflater.inflate(LayoutInflater.java:353) 
                     at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:290) 
                     at android.app.Activity.setContentView(Activity.java:1929) 
                     at com.be2015.meetupmap.MainActivity.onCreate(MainActivity.java:23) 
                     at android.app.Activity.performCreate(Activity.java:5231) 
                     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087) 
                     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2159) 
                     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245) 
                     at android.app.ActivityThread.access$800(ActivityThread.java:135) 
                     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196) 
                     at android.os.Handler.dispatchMessage(Handler.java:102) 
                     at android.os.Looper.loop(Looper.java:136) 
                     at android.app.ActivityThread.main(ActivityThread.java:5017) 
                     at java.lang.reflect.Method.invokeNative(Native Method) 
                     at java.lang.reflect.Method.invoke(Method.java:515) 
                     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779) 
                     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595) 
                     at dalvik.system.NativeStart.main(Native Method) 
02-12 03:58:03.310 1261-1261/com.be2015.meetupmap W/EGL_emulation: eglSurfaceAttrib not implemented 
02-12 03:58:03.350 1261-1261/com.be2015.meetupmap D/OpenGLRenderer: Enabling debug mode 0 

This is what I see in the emulator on opening the app

任何人都可以告诉我发生了什么问题吗?我完全不知道!

+0

1)尽量仿真器与谷歌的API AVD。 2)你是否从Google开发人员控制台启动Google地图API – Ajinkya

回答

0

也许这是你的问题?

int resultCode = GooglePlayServicesUtil.isGooglePlayServicesAvailable(this); 
    if (resultCode != ConnectionResult.SUCCESS) { 
     if (GooglePlayServicesUtil.isUserRecoverableError(resultCode)) { 
      GooglePlayServicesUtil.getErrorDialog(resultCode, this, 
         PLAY_SERVICES_RESOLUTION_REQUEST).show(); 
     } else { 
      Log.i(TAG, "This device is not supported."); 
      finish(); 
     } 
    } 

Android - Google Map v2 - need update google play service on device