Сбой приложения Flutter для Android при использовании карт Google

#android #flutter #google-maps #plugins #crash

#Android #флаттер #google-карты #Плагины #сбой

Вопрос:

Мое приложение Flutter вылетает при попытке отобразить карту Google с помощью пакета google_maps_flutter из pub.dev. Это журналы

 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,

          ),

        ),

      );
  }
}
 

Я добавил <uses-library android:name="org.apache.http.legacy" android:required="false"/> в AndroidManifest.xml но все равно приложение по-прежнему выходит из строя. Может кто-нибудь мне помочь?

Комментарии:

1. Я использую google_maps_flutter: ^1.0.6 . Спасибо

2. Может быть связано с этим github.com/flutter/flutter/issues/72185 (?)

3. спасибо, я бы проверил это

Ответ №1:

Это работает, если вы измените minSdkVersion на 24 в build.gradle. Пока не удалось выяснить причину.

Кстати, оно работает в java / android studio, даже если minSdkVersion равно 16.

Так что это может быть проблема с конфигурацией flutter.

Комментарии:

1. Я изменил свой minSdkVersion на 24, и он по-прежнему выходит из строя

Ответ №2:

попробуйте версию Gradle 3.5.0 и минимальный SDK 20

сработало для меня