flutter google 地图在调试和发布版本中工作,但在发布到 Playstore 后无法工作

问题描述 投票:0回答:1

谷歌地图在调试和发布版本中工作,但在发布到 Playstore 后无法工作。

我已经添加了 sha1 调试和 sha1 版本。我构建了调试版本和发布版本,如果我安装在手机中,它就可以工作。但为什么在我使用 Android App Bundle (.aab) 发布到 Playstore 后,地图无法正常工作?

注意更新:

  • 当我使用 android studio 构建 apk 版本时,然后安装,地图会显示,但是如果我使用命令“flutter build apk --release”构建 apk 版本,则地图不会显示

这是我的代码

@override
  Widget build(BuildContext context) {
    return  Scaffold(
      appBar: AppBar(
        title:
        Text("aaaa", style: const TextStyle(color: Colors.white)),
        backgroundColor: Palette.color_primary,
        iconTheme: const IconThemeData(
          color: Colors.white, //change your color here
        ),
      ),
      body:
      FutureBuilder(
          future: Future.delayed(const Duration(milliseconds: 500), () {}),
    builder: (ctx, snapshot) {
      if (snapshot.connectionState == ConnectionState.done) {
        return GoogleMap(
          myLocationEnabled: true,
          myLocationButtonEnabled: true,
          zoomControlsEnabled: false,
          mapType: MapType.normal,
          //initialCameraPosition: _initialCameraPosition,
          initialCameraPosition: CameraPosition(target: LatLng(latitude.toDouble(), longitude.toDouble()),zoom: 15.5),
          onMapCreated: (controller) => _googleMapController = controller,
          /*onMapCreated: (GoogleMapController controller){
          _controller.complete(controller);
        },*/

          markers: markers.map((e) => e).toSet(),

        );
      }
      return Container();
    }
    ),
    );
  }
flutter google-maps
1个回答
0
投票

我遇到了类似的问题,我的使用 Google 地图的 Flutter 应用程序在调试版本和发布版本中都运行良好,但在发布到 Play 商店后停止运行。

这对我有用:

最初,我仅将调试和发布 SHA-1 证书密钥添加到 Android 地图限制中。

遇到问题后,我通过将应用程序签名密钥证书(SHA-1证书指纹)添加到地图限制中来解决它。

解决步骤:

  1. 转到 Google Cloud Console
  2. 导航至
    APIs & Services > Credentials
    部分。
  3. 找到您的 API 密钥并单击
    Edit
    (铅笔)图标。
  4. Application restrictions
    部分下,确保添加:
    • 调试密钥的 SHA-1 证书指纹。
    • 您的发布密钥的 SHA-1 证书指纹。
    • 应用程序签名密钥证书(SHA-1 证书指纹),可以在 Play 管理中心的
      Release > Setup > App integrity
      下找到。

通过添加应用程序签名密钥证书,我能够让 Google 地图在 Play 商店上发布的版本中运行。

© www.soinside.com 2019 - 2024. All rights reserved.