You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Flutter开发:Android模拟器无法显示Google Maps问题求助

问题:Flutter中GoogleMap组件空白,模拟器自带Google Maps无法加载

环境信息

  • Flutter版本:3.16.1(稳定通道)
  • 测试环境:Android 11(API 30)Pixel 7 Pro模拟器

问题现象

切换到map_page.dart页面时,GoogleMap组件显示空白;模拟器自带的Google Maps应用同样无法正常加载。

已完成的排查

  • 确认模拟器支持Google Play Services
  • AndroidManifest.xml已配置Google Maps API_KEY及必要权限(位置权限、网络权限等)
  • 更换过其他可正常运行Google Maps的模拟器
  • 重新生成过API_KEY
  • 模拟器网络访问正常,但怀疑公司VPN可能阻断相关连接

相关信息

Flutter Doctor 输出

$ flutter doctor -v
[√] Flutter (Channel stable, 3.16.1, on Microsoft Windows [Version 10.0.19045.3693], locale en-US)
    • Flutter version 3.16.1 on channel stable at C:\SW\flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 7f20e5d18c (9 days ago), 2023-11-27 09:47:30 -0800
    • Engine revision 22b600f240
    • Dart version 3.2.1
    • DevTools version 2.28.3

[√] Windows Version (Installed version of Windows is version 10 or higher)

[√] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
    • Android SDK at C:\Users\carlo.benussi\AppData\Local\Android\sdk
    • Platform android-34, build-tools 34.0.0
    • Java binary at: C:\Program Files\Android\Android Studio\jbr\bin\java
    • Java version OpenJDK Runtime Environment (build 17.0.6+0-b2043.56-10027231)
    • All Android licenses accepted.

[√] Chrome - develop for the web
    • Chrome at C:\Program Files\Google\Chrome\Application\chrome.exe

[!] Visual Studio - develop Windows apps (Visual Studio Team Explorer 2017 15.9.58)
    • Visual Studio at C:\Program Files (x86)\Microsoft Visual Studio\2017\TeamExplorer
    • Visual Studio Team Explorer 2017 version 15.9.34118.181
    • Windows 10 SDK version 10.0.17763.0
    X Visual Studio 2019 or later is required.
      Download at https://visualstudio.microsoft.com/downloads/.
      Please install the "Desktop development with C++" workload, including all of its default components

[√] Android Studio (version 2022.3)
    • Android Studio at C:\Program Files\Android\Android Studio
    • Flutter plugin can be installed from:
       https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
       https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 17.0.6+0-b2043.56-10027231)

[√] VS Code (version 1.84.2)
    • VS Code at C:\Users\carlo.benussi\AppData\Local\Programs\Microsoft VS Code
    • Flutter extension version 3.78.0

[√] Connected device (4 available)
    • sdk gphone x86 (mobile) • emulator-5554 • android-x86    • Android 11 (API 30) (emulator)
    • Windows (desktop)       • windows       • windows-x64    • Microsoft Windows [Version 10.0.19045.3693]
    • Chrome (web)            • chrome        • web-javascript • Google Chrome 119.0.6045.200
    • Edge (web)              • edge          • web-javascript • Microsoft Edge 119.0.2151.97

[√] Network resources
    • All expected network resources are available.

! Doctor found issues in 1 category.

map_page.dart 代码片段

child: SafeArea(
        child: Scaffold(
          extendBodyBehindAppBar: true,
          drawer: const ChocoTurDrawer(),
          body: Stack(
            children: [
              GoogleMap(
                mapType: MapType.normal,
                initialCameraPosition: (_cameraPosition != null)
                    ? _cameraPosition!
                    : const CameraPosition(
                        target: Coordinates.turinCenter,
                        zoom: 14.4746,
                      ),
                myLocationEnabled: true,
                myLocationButtonEnabled: false,
                zoomControlsEnabled: false,
                compassEnabled: true,
                onMapCreated: (GoogleMapController controller) {
                  _controller.complete(controller);
                },
                onCameraMove: (CameraPosition position) {
                  _cameraPosition = position;
                },
                markers: _markers,
              ),
              Positioned(
                right: 15,
                bottom: 85,
                child: FloatingActionButton(
                  onPressed: () {},
                  child: const FaIcon(Icons.tour_outlined),
                ),
              ),
            ],
          ),
          floatingActionButton: FloatingActionButton(
            onPressed: () async {
              Coordinates.getUserPosition().then((value) async {
                LatLng latLngValue = LatLng(value.latitude, value.longitude);
                _updateUserLocationMarker(latLngValue);
                _moveCameraToCoordinates(latLngValue);
              }).onError((error, stackTrace) async {
                LoggerInstance.logger.e("Error getting user position.");
              });
            },
            child: const FaIcon(Icons.my_location_rounded),
          ),
        ),
      ),

日志信息

W/ample.*******( 5200): Unsupported class loader
I/Google Maps Android API( 5200): Google Play services client version: 18020000
D/MapsInitializer( 5200): loadedRenderer: LEGACY
D/zzcc    ( 5200): preferredRenderer: null
I/Google Maps Android API( 5200): Google Play services package version: 201817022
I/TetheringManager( 5200): registerTetheringEventCallback:com.example.choco_tur
I/PlatformViewsController( 5200): Using hybrid composition for platform view: 0
D/EGL_emulation( 5200): eglMakeCurrent: 0xeafe0300: ver 2 0 (tinfo 0xeb31ce90) (first time)
W/Gralloc4( 5200): allocator 3.x is not supported
E/EGL_emulation( 5200): eglQueryContext 32c0  EGL_BAD_ATTRIBUTE
E/EGL_emulation( 5200): tid 5200: eglQueryContext(2019): error 0x3004 (EGL_BAD_ATTRIBUTE)
D/HostConnection( 5200): HostConnection::get() New Host Connection established 0xeafe7370, tid 5335
D/HostConnection( 5200): HostComposition ext ANDROID_EMU_CHECKSUM_HELPER_v1 ANDROID_EMU_native_sync_v2 ANDROID_EMU_native_sync_v3 ANDROID_EMU_native_sync_v4 ANDROID_EMU_dma_v1 ANDROID_EMU_direct_mem ANDROID_EMU_vulkan ANDROID_EMU_deferred_vulkan_commands ANDROID_EMU_vulkan_null_optional_strings ANDROID_EMU_vulkan_create_resources_with_requirements ANDROID_EMU_YUV_Cache ANDROID_EMU_vulkan_ignored_handles ANDROID_EMU_has_shared_slots_host_memory_allocator ANDROID_EMU_vulkan_free_memory_sync ANDROID_EMU_vulkan_shader_float16_int8 ANDROID_EMU_vulkan_async_queue_submit ANDROID_EMU_sync_buffer_data ANDROID_EMU_vulkan_async_qsri ANDROID_EMU_read_color_buffer_dma GL_OES_vertex_array_object GL_KHR_texture_compression_astc_ldr ANDROID_EMU_host_side_tracing ANDROID_EMU_gles_max_version_2 
D/EGL_emulation( 5200): eglCreateContext: 0xeafc93f0: maj 1 min 0 rcv 1
2
D/EGL_emulation( 5200): eglMakeCurrent: 0xeafc93f0: ver 1 0 (tinfo 0xce641990) (first time)
W/DynamiteModule( 5200): Local module descriptor class for com.google.android.gms.googlecertificates not found.
I/DynamiteModule( 5200): Considering local module com.google.android.gms.googlecertificates:0 and remote module com.google.android.gms.googlecertificates:4
I/DynamiteModule( 5200): Selected remote version of com.google.android.gms.googlecertificates, version >= 4
2
W/ample.******( 5200): Unsupported class loader

AndroidManifest.xml 配置

<manifest xmlns:android="http://schemas.android.com/apk/res/android">
    <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_BACKGROUND_LOCATION"/>
    <uses-permission android:name="android.permission.INTERNET"/>
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>

    <application
        android:label="choco_tur"
        android:name="${applicationName}"
        android:icon="@mipmap/launcher_icon">
        <activity
            android:name=".MainActivity"
            android:exported="true"
            android:launchMode="singleTop"
            android:theme="@style/LaunchTheme"
            android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
            android:hardwareAccelerated="true"
            android:windowSoftInputMode="adjustResize">
            <!-- Specifies an Android theme to apply to this Activity as soon as
                 the Android process has started. This theme is visible to the user
                 while the Flutter UI initializes. After that, this theme continues
                 to determine the Window background behind the Flutter UI. -->
            <meta-data
              android:name="io.flutter.embedding.android.NormalTheme"
              android:resource="@style/NormalTheme"
              />
            <intent-filter>
                <action android:name="android.intent.action.MAIN"/>
                <category android:name="android.intent.category.LAUNCHER"/>
            </intent-filter>
        </activity>
        <!-- Don't delete the meta-data below.
             This is used by the Flutter tool to generate GeneratedPluginRegistrant.java -->
        <meta-data
            android:name="flutterEmbedding"
            android:value="2" />

        <meta-data
            android:name="com.google.android.geo.API_KEY"
            android:value="@secrets/google_maps_api_key"/>
    </application>
</manifest>

排查方向及解决建议

  1. VPN网络验证:完全关闭公司VPN,重启模拟器后测试自带Google Maps和Flutter应用的地图加载情况。若恢复正常,说明VPN拦截了Google Maps相关域名,需联系IT部门添加白名单。
  2. Google Play Services版本适配:日志显示客户端版本与包版本差距较大,存在兼容性风险。打开模拟器的Google Play商店,进入设置检查并安装Google Play Services最新版本,重启模拟器后测试。
  3. API_KEY权限验证:确认Google Cloud控制台中API_KEY已启用Maps SDK for Android服务,且限制条件正确(需添加模拟器的SHA-1指纹和应用包名)。
  4. 模拟器代理检查:进入模拟器设置-网络和互联网-代理,设置为“无”,避免代理导致的网络访问异常。
  5. 切换地图渲染模式:在AndroidManifest.xml的application标签内添加以下配置,强制使用最新渲染器:
    <meta-data
        android:name="com.google.android.gms.maps.engine"
        android:value="true" />
    
    或在Flutter代码初始化时设置:
    await MapsInitializer.initialize(MapsInitializer.Renderer.latest);
    
  6. 清除模拟器缓存:进入模拟器设置-应用,找到Google Maps和Google Play Services,清除缓存和数据后重启测试。

内容的提问来源于stack exchange,提问作者Carlo Benussi

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.04 13:07:34