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

Flutter Google Maps:配置Cloud Map ID却始终用Legacy Renderer的问题

Flutter Cloud Map ID不生效:Legacy Renderer问题排查

问题描述

在Flutter中尝试通过Cloud Map ID使用自定义地图样式,已在Google Maps组件中定义Cloud Map ID,但始终显示默认样式。控制台日志显示系统持续使用Legacy Renderer,导致Cloud Map ID配置无法生效:

D/MapsInitializer(32388): preferredRenderer: LATEST
D/zzcc    (32388): preferredRenderer: LATEST
I/zzcc    (32388): Making Creator dynamically
2
W/ziparchive(32388): Unable to open '/data/user_de/0/com.google.android.gms/app_chimera/m/00000002/DynamiteLoader.dm': No such file or directory
I/DynamiteModule(32388): Considering local module com.google.android.gms.maps_core_dynamite:0 and remote module com.google.android.gms.maps_core_dynamite:203115000
I/DynamiteModule(32388): Selected remote version of com.google.android.gms.maps_core_dynamite, version >= 203115000
V/DynamiteModule(32388): Dynamite loader version >= 2, using loadModule2NoCrashUtils
2
W/ziparchive(32388): Unable to open '/data/user_de/0/com.google.android.gms/app_chimera/m/00000006/MapsDynamite.dm': No such file or directory
I/Google Maps Android API(32388): Google Play services client version: 18020000
I/Google Maps Android API(32388): Google Play services package version: 231818044
I/Google Maps Android API(32388): Google Play services maps renderer version(legacy): 203115000
D/MapsInitializer(32388): loadedRenderer: LEGACY
W/Google Maps Android API(32388): MapId is not supported with the legacy renderer.
I/PlatformViewsController(32388): Hosting view in a virtual display for platform view: 0
E/FrameEvents(32388): updateAcquireFence: Did not find frame.
E/BufferQueueProducer(32388): [SurfaceTexture-0-32388-0](id:7e8400000002,api:1,p:32388,c:32388) connect: already connected (cur=1 req=1)
I/GoogleMapController(32388): No TextureView found. Likely using the LEGACY renderer.
E/OpenGLRenderer(32388): Unable to match the desired swap behavior.

当前已尝试的初始化代码:

final GoogleMapsFlutterPlatform mapsImplementation =
      GoogleMapsFlutterPlatform.instance;
  if (mapsImplementation is GoogleMapsFlutterAndroid) {
    WidgetsFlutterBinding.ensureInitialized();
    mapRenderer = await mapsImplementation
        .initializeWithRenderer(AndroidMapRenderer.latest);
  }

问题原因

初始化渲染器的代码执行时机过晚,Google Maps组件已经提前初始化并使用了Legacy Renderer,此时再调用initializeWithRenderer不会生效。

解决方案

1. 调整初始化时机到runApp之前

必须在runApp执行前完成渲染器初始化,且先调用WidgetsFlutterBinding.ensureInitialized()以支持异步操作:

void main() async {
  // 先初始化WidgetsBinding,确保异步调用正常执行
  WidgetsFlutterBinding.ensureInitialized();
  
  final GoogleMapsFlutterPlatform mapsImplementation = GoogleMapsFlutterPlatform.instance;
  if (mapsImplementation is GoogleMapsFlutterAndroid) {
    await mapsImplementation.initializeWithRenderer(AndroidMapRenderer.latest);
  }

  runApp(const MyApp());
}

2. 额外检查项

  • 确认设备上的Google Play Services版本足够新(日志中版本为231818044,已满足要求;若版本过低会自动 fallback到Legacy)
  • 执行flutter clean清理项目缓存后重新构建
  • 检查AndroidManifest.xml,确保没有添加强制使用Legacy渲染器的配置:
    <!-- 若存在此标签请删除 -->
    <meta-data
        android:name="com.google.android.gms.maps.renderer"
        android:value="legacy"/>
    

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.03 08:35:37