简体   繁体   English

在 Flutter App 中使用谷歌地图时出错

[英]Error while using Google Maps in Flutter App

I try to use google-maps inside my flutter app but, I am getting this error every time I try to debug my code.我尝试在我的 flutter 应用程序中使用 google-maps,但是,每次尝试调试我的代码时都会收到此错误。

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:checkDebugAarMetadata'.
> Could not resolve all files for configuration ':app:debugRuntimeClasspath'.
   > Could not find play-services-maps-17.0.0.aar (com.google.android.gms:play-services-maps:17.0.0).
     Searched in the following locations:
         https://dl.google.com/dl/android/maven2/com/google/android/gms/play-services-maps/17.0.0/play-services-maps-17.0.0.aar

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 39s
Exception: Gradle task assembleDebug failed with exit code 1

Please go to file -> android/app/build.gradle请转到文件 -> android/app/build.gradle

and edit minSdkVersion from 16 to 21并将 minSdkVersion 从 16 编辑为 21

    defaultConfig {
    // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
    applicationId "com.example.google_maps"
    minSdkVersion 21
    targetSdkVersion 30
    versionCode flutterVersionCode.toInteger()
    versionName flutterVersionName
}

According to it's document you should set the minSdkVersion in android/app/build.gradle:根据它的文档,您应该在 android/app/build.gradle 中设置 minSdkVersion:

android {
    defaultConfig {
        minSdkVersion 20
    }
}

Also add this code in the main file :还要在主文件中添加此代码:

void main() {
  if (defaultTargetPlatform == TargetPlatform.android) {
    AndroidGoogleMapsFlutter.useAndroidViewSurface = true;
  }
  runApp(MyApp());
}

Configuartion link : https://pub.dev/packages/google_maps_flutter#android配置链接: https ://pub.dev/packages/google_maps_flutter#android

Note: Please, check your Internet connection and, try a VPN!注意:请检查您的 Internet 连接并尝试使用 VPN!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM