【问题标题】:Flutter Android App crashes when uing google mapsFlutter Android App 在使用谷歌地图时崩溃
【发布时间】:2021-03-24 08:09:40
【问题描述】:

尝试使用 pub.dev 中的 google_maps_flutter 包显示谷歌地图时,我的 Flutter 应用程序崩溃。这些是日志

Running with unsound null safety
For more information see https://dart.dev/null-safety/unsound-null-safety
I/zzbz    (31588): Making Creator dynamically
D/        (31588): HostConnection::get() New Host Connection established 0x7f2a9c00, tid 31603
W/zygote  (31588): Unsupported class loader
W/zygote  (31588): Skipping duplicate class check due to unsupported classloader
I/DynamiteModule(31588): Considering local module com.google.android.gms.maps_dynamite:0 and remote module com.google.android.gms.maps_dynamite:203112999
I/DynamiteModule(31588): Selected remote version of com.google.android.gms.maps_dynamite, version >= 203112999
V/DynamiteModule(31588): Dynamite loader version >= 2, using loadModule2NoCrashUtils
D/        (31588): HostConnection::get() New Host Connection established 0x89c0fc00, tid 31625
W/ResourceType(31588): ResTable_typeSpec entry count inconsistent: given 67, previously 69
W/ResourceType(31588): ResTable_typeSpec entry count inconsistent: given 5399, previously 5400
W/zygote  (31588): Unsupported class loader
W/zygote  (31588): Skipping duplicate class check due to unsupported classloader
I/Google Maps Android API(31588): Google Play services client version: 12451000
I/Google Maps Android API(31588): Google Play services package version: 204516022
I/zygote  (31588): Do partial code cache collection, code=29KB, data=24KB
I/zygote  (31588): After code cache collection, code=29KB, data=24KB
I/zygote  (31588): Increasing code cache capacity to 128KB
W/DynamiteModule(31588): Local module descriptor class for com.google.android.gms.googlecertificates not found.
I/DynamiteModule(31588): Considering local module com.google.android.gms.googlecertificates:0 and remote module com.google.android.gms.googlecertificates:6
I/DynamiteModule(31588): Selected remote version of com.google.android.gms.googlecertificates, version >= 6
W/zygote  (31588): Unsupported class loader
W/zygote  (31588): Skipping duplicate class check due to unsupported classloader
Lost connection to device.

这是 AndroidManifest.xml

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.myapp">
   <application
        android:label="myapp"
        android:icon="@mipmap/ic_launcher">
        <uses-library android:name="org.apache.http.legacy" android:required="false"/>
         <meta-data 
         android:name="com.google.android.geo.API_KEY"
            android:value="AIzaSyBx5Lp3oc-aTekzyLykT858a_ECRSEicAU"/>
        <activity
            android:name=".MainActivity"
            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"
              />
            <!-- Displays an Android View that continues showing the launch screen
                 Drawable until Flutter paints its first frame, then this splash
                 screen fades out. A splash screen is useful to avoid any visual
                 gap between the end of Android's launch screen and the painting of
                 Flutter's first frame. -->
            <meta-data
              android:name="io.flutter.embedding.android.SplashScreenDrawable"
              android:resource="@drawable/launch_background"
              />
            <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" />
    </application>
</manifest>

我尝试使用它来显示它

class _MyHomePageState extends State<MyHomePage> {
 
  Completer<GoogleMapController> _controller = Completer();



static const LatLng _center = const LatLng(45.521563, -122.677433);
 void _onMapCreated(GoogleMapController controller) {

_controller.complete(controller);

}



  @override
  Widget build(BuildContext context) {
    // This method is rerun every time setState is called, for instance as done
    // by the _incrementCounter method above.
    //
    // The Flutter framework has been optimized to make rerunning build methods
    // fast, so that you can just rebuild anything that needs updating rather
    // than having to individually change instances of widgets.
    return Scaffold(

         appBar: AppBar(

           title: Text('Maps Sample App'),

           backgroundColor: Colors.green[700],

           ),

           body: GoogleMap(

             onMapCreated: _onMapCreated,

             initialCameraPosition: CameraPosition(

               target: _center,

               zoom: 11.0,

          ),

        ),

      );
  }
}

我在 AndroidManifest.xml 中添加了&lt;uses-library android:name="org.apache.http.legacy" android:required="false"/&gt;,但应用程序仍然崩溃。有人可以帮帮我吗?

【问题讨论】:

标签: android flutter google-maps plugins crash


【解决方案1】:

如果您在 build.gradle 中将 minSdkVersion 更改为 24,它会起作用。 还没有找到原因。

顺便说一句,即使 minSdkVersion 为 16,它也可以在 java/android studio 中运行。

所以这可能是一个颤振配置问题。

【讨论】:

  • 我将 minSdkVersion 更改为 24,但它仍然崩溃
【解决方案2】:

尝试 Gradle 版本 3.5.0 和最小 SDK 20

为我工作

【讨论】:

    猜你喜欢
    • 2020-01-26
    • 1970-01-01
    • 1970-01-01
    • 2021-02-17
    • 2020-03-01
    • 1970-01-01
    • 1970-01-01
    • 2017-10-28
    • 2015-06-10
    相关资源
    最近更新 更多