打开静态uri时flutter map_view崩溃

时间:2018-06-20 19:04:03

标签: flutter

我有一个map_view,并使用staticMapURI来显示完整视图的地图,但是当我点击地图时,应用崩溃了:

  I/zygote  (11465): Rejecting re-init on previously-failed class java.lang.Class<com.google.android.gms.maps.model.CameraPosition>: java.lang.NoClassDefFoundError: Failed resolution of: Lcom/google/android/gms/common/internal/safeparcel/zza;
  I/zygote  (11465):   at void com.apptreesoftware.mapview.MapViewPlugin.<clinit>() (MapViewPlugin.kt:-1)
  I/zygote  (11465):   at void com.apptreesoftware.mapview.MapViewPlugin.registerWith(io.flutter.plugin.common.PluginRegistry$Registrar) (MapViewPlugin.kt:-1)
  I/zygote  (11465):   at void io.flutter.plugins.GeneratedPluginRegistrant.registerWith(io.flutter.plugin.common.PluginRegistry) (GeneratedPluginRegistrant.java:32)
  I/zygote  (11465):   at void com.rumblewayne.scottandvikiapp.MainActivity.onCreate(android.os.Bundle) (MainActivity.java:12)
  I/zygote  (11465):   at void android.app.Activity.performCreate(android.os.Bundle, android.os.PersistableBundle) (Activity.java:7009)
  I/zygote  (11465):   at void android.app.Activity.performCreate(android.os.Bundle) (Activity.java:7000)
  I/zygote  (11465):   at void android.app.Instrumentation.callActivityOnCreate(android.app.Activity, android.os.Bundle) (Instrumentation.java:1214)
  I/zygote  (11465):   at android.app.Activity android.app.ActivityThread.performLaunchActivity(android.app.ActivityThread$ActivityClientRecord, android.content.Intent) (ActivityThread.java:2731)
  I/zygote  (11465):   at void android.app.ActivityThread.handleLaunchActivity(android.app.ActivityThread$ActivityClientRecord, android.content.Intent, java.lang.String) (ActivityThread.java:2856)
  I/zygote  (11465):   at void android.app.ActivityThread.-wrap11(android.app.ActivityThread, android.app.ActivityThread$ActivityClientRecord, android.content.Intent, java.lang.String) (ActivityThread.java:-1)
  I/zygote  (11465):   at void android.app.ActivityThread$H.handleMessage(android.os.Message) (ActivityThread.java:1589)
  I/zygote  (11465):   at void android.os.Handler.dispatchMessage(android.os.Message) (Handler.java:106)
  I/zygote  (11465):   at void android.os.Looper.loop() (Looper.java:164)
  I/zygote  (11465):   at void android.app.ActivityThread.main(java.lang.String[]) (ActivityThread.java:6494)
  I/zygote  (11465):   at java.lang.Object java.lang.reflect.Method.invoke(java.lang.Object, java.lang.Object[]) (Method.java:-2)
  I/zygote  (11465):   at void com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run() (RuntimeInit.java:438)
  I/zygote  (11465):   at void com.android.internal.os.ZygoteInit.main(java.lang.String[]) (ZygoteInit.java:807)
  I/zygote  (11465): Caused by: java.lang.ClassNotFoundException: Didn't find class "com.google.android.gms.common.internal.safeparcel.zza" on path: DexPathList[[zip file "/data/app/com.rumblewayne.scottandvikiapp-GNTruwp_-c2PU_b1tngU3w==/base.apk"],nativeLibraryDirectories=[/data/app/com.rumblewayne.scottandvikiapp-GNTruwp_-c2PU_b1tngU3w==/lib/x86, /data/app/com.rumblewayne.scottandvikiapp-GNTruwp_-c2PU_b1tngU3w==/base.apk!/lib/x86, /system/lib, /vendor/lib]]
  I/zygote  (11465):   at java.lang.Class dalvik.system.BaseDexClassLoader.findClass(java.lang.String) (BaseDexClassLoader.java:125)
  I/zygote  (11465):   at java.lang.Class java.lang.ClassLoader.loadClass(java.lang.String, boolean) (ClassLoader.java:379)
  I/zygote  (11465):   at java.lang.Class java.lang.ClassLoader.loadClass(java.lang.String) (ClassLoader.java:312)
  I/zygote  (11465):   at void com.apptreesoftware.mapview.MapViewPlugin.<clinit>() (MapViewPlugin.kt:-1)
  I/zygote  (11465):   at void com.apptreesoftware.mapview.MapViewPlugin.registerWith(io.flutter.plugin.common.PluginRegistry$Registrar) (MapViewPlugin.kt:-1)
  I/zygote  (11465):   at void io.flutter.plugins.GeneratedPluginRegistrant.registerWith(io.flutter.plugin.common.PluginRegistry) (GeneratedPluginRegistrant.java:32)
  I/zygote  (11465):   at void com.rumblewayne.scottandvikiapp.MainActivity.onCreate(android.os.Bundle) (MainActivity.java:12)
  I/zygote  (11465):   at void android.app.Activity.performCreate(android.os.Bundle, android.os.PersistableBundle) (Activity.java:7009)
  I/zygote  (11465):   at void android.app.Activity.performCreate(android.os.Bundle) (Activity.java:7000)
  I/zygote  (11465):   at void android.app.Instrumentation.callActivityOnCreate(android.app.Activity, android.os.Bundle) (Instrumentation.java:1214)
  I/zygote  (11465):   at android.app.Activity android.app.ActivityThread.performLaunchActivity(android.app.ActivityThread$ActivityClientRecord, android.content.Intent) (ActivityThread.java:2731)
  I/zygote  (11465):   at void android.app.ActivityThread.handleLaunchActivity(android.app.ActivityThread$ActivityClientRecord, android.content.Intent, java.lang.String) (ActivityThread.java:2856)
  I/zygote  (11465):   at void android.app.ActivityThread.-wrap11(android.app.ActivityThread, android.app.ActivityThread$ActivityClientRecord, android.content.Intent, java.lang.String) (ActivityThread.java:-1)
  I/zygote  (11465):   at void android.app.ActivityThread$H.handleMessage(android.os.Message) (ActivityThread.java:1589)
  I/zygote  (11465):   at void android.os.Handler.dispatchMessage(android.os.Message) (Handler.java:106)
  I/zygote  (11465):   at void android.os.Looper.loop() (Looper.java:164)
  I/zygote  (11465):   at void android.app.ActivityThread.main(java.lang.String[]) (ActivityThread.java:6494)
  I/zygote  (11465):   at java.lang.Object java.lang.reflect.Method.invoke(java.lang.Object, java.lang.Object[]) (Method.java:-2)
  I/zygote  (11465):   at void com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run() (RuntimeInit.java:438)
  I/zygote  (11465):   at void com.android.internal.os.ZygoteInit.main(java.lang.String[]) (ZygoteInit.java:807)
  I/zygote  (11465):
  F/flutter (11465): [FATAL:flutter/shell/platform/android/platform_view_android_jni.cc(60)] Check failed: CheckException(env).
  F/libc    (11465): Fatal signal 6 (SIGABRT), code -6 in tid 11465 (scottandvikiapp), pid 11465 (scottandvikiapp)
  *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
  Build fingerprint: 'google/sdk_gphone_x86/generic_x86:8.1.0/OSM1.180201.021/4741582:userdebug/dev-keys'
  Revision: '0'
  ABI: 'x86'
  pid: 11465, tid: 11465, name: scottandvikiapp  >>> com.rumblewayne.scottandvikiapp <<<
  signal 6 (SIGABRT), code -6 (SI_TKILL), fault addr --------
  Abort message: '[FATAL:flutter/shell/platform/android/platform_view_android_jni.cc(60)] Check failed: CheckException(env). 
  '
  eax 00000000  ebx 00002cc9  ecx 00002cc9  edx 00000006
  esi f29abd10  edi 00002cc9
  xcs 00000023  xds 0000002b  xes 0000002b  xfs 0000006b  xss 0000002b
  eip f720aaf0  ebp aca5a3d9  esp ff86e8b8  flags 00000296
  backtrace:
  #00 pc 00000af0  [vdso:f720a000] (__kernel_vsyscall+16)
  #01 pc 0001edf8  /system/lib/libc.so (syscall+40)
  #02 pc 0001f073  /system/lib/libc.so (abort+115)
  #03 pc 00330ffe  /data/app/com.rumblewayne.scottandvikiapp-GNTruwp_-c2PU_b1tngU3w==/lib/x86/libflutter.so
  #04 pc 00331733  /data/app/com.rumblewayne.scottandvikiapp-GNTruwp_-c2PU_b1tngU3w==/lib/x86/libflutter.so
  #05 pc 00083d2a  /data/app/com.rumblewayne.scottandvikiapp-GNTruwp_-c2PU_b1tngU3w==/lib/x86/libflutter.so
  #06 pc 000821fe  /data/app/com.rumblewayne.scottandvikiapp-GNTruwp_-c2PU_b1tngU3w==/lib/x86/libflutter.so
  #07 pc 000d2993  /data/app/com.rumblewayne.scottandvikiapp-GNTruwp_-c2PU_b1tngU3w==/lib/x86/libflutter.so
  #08 pc 0009329c  /data/app/com.rumblewayne.scottandvikiapp-GNTruwp_-c2PU_b1tngU3w==/lib/x86/libflutter.so
  #09 pc 00092e5a  /data/app/com.rumblewayne.scottandvikiapp-GNTruwp_-c2PU_b1tngU3w==/lib/x86/libflutter.so
  #10 pc 00097a76  /data/app/com.rumblewayne.scottandvikiapp-GNTruwp_-c2PU_b1tngU3w==/lib/x86/libflutter.so
  #11 pc 00014af7  /system/lib/libutils.so (android::SimpleLooperCallback::handleEvent(int, int, void*)+39)
  #12 pc 00015936  /system/lib/libutils.so (android::Looper::pollInner(int)+982)
  #13 pc 000154d6  /system/lib/libutils.so (android::Looper::pollOnce(int, int*, int*, void**)+118)
  #14 pc 000e262b  /system/lib/libandroid_runtime.so (android::android_os_MessageQueue_nativePollOnce(_JNIEnv*, _jobject*, long long, int)+59)
  #15 pc 007d5428  /system/framework/x86/boot-framework.oat (offset 0x606000) (android.app.NativeActivity.onWindowFocusChangedNative [DEDUPED]+136)
  #16 pc 0000371e  /dev/ashmem/dalvik-jit-code-cache (deleted)
  #17 pc 4f293241  <unknown>
  #18 pc 0d3fffff  /dev/ashmem/dalvik-main space (region space) (deleted)
  #19 pc 0d3fffff  /dev/ashmem/dalvik-main space (region space) (deleted)
  Lost connection to device.

我已经读过其他posts,您需要确保您的依赖项匹配等,但是当我尝试完全按照链接文章中的内容进行操作时,我似乎可以正常工作。

我当前的依赖项如下:

dependencies:
  map_view: ^0.0.12
  image_picker: ^0.4.1
  url_launcher: ^3.0.0
  firebase_storage: ^0.3.7
  firebase_database: ^1.0.1
  shared_preferences: ^0.4.1
  transparent_image: ^0.1.0
  chewie: ^0.6.0
  camera: ^0.2.1
  video_player: ^0.6.0
  path_provider: ^0.4.0
  connectivity: ^0.3.1
  zoomable_image: ^1.2.0
  json_annotation: ^0.2.4
  firebase_messaging: ^1.0.2
  image: ^1.1.33
  path: ^1.5.1
  uuid: ^1.0.0
  flutter:
    sdk: flutter
  flutter_localizations:
          sdk: flutter

dev_dependencies:
  build_runner: ^0.8.0
  json_serializable: ^0.5.2
  flutter_launcher_icons: ^0.3.2
  flutter_test:
    sdk: flutter

任何人都可以深入了解如何解决此问题吗?

更新:

import 'package:map_view/map_view.dart';
import 'CompositionSubscription.dart';
import 'package:flutter/material.dart';

class CustomMap extends StatefulWidget {
  String mapTitle;
  List markers;
  CameraPosition initialPosition;

  CustomMap(this.mapTitle, this.markers, this.initialPosition);

  @override
  CustomMapState createState() => new CustomMapState(this.mapTitle, this.markers, this.initialPosition);
}

class CustomMapState extends State<CustomMap>  {

  final String mapTitle;
  final List<Marker> markers;
  final CameraPosition initialPosition;

  CustomMapState(this.mapTitle, this.markers, this.initialPosition);

  MapView mapView = new MapView();
  var compositeSubscription = new CompositeSubscription();

  @override Widget build(BuildContext context) {

    mapView.show(
        new MapOptions(
            mapViewType: MapViewType.normal,
            showUserLocation: true,
            initialCameraPosition: initialPosition,
            title: mapTitle),
        toolbarActions: [new ToolbarAction("Back", 1)]
    );

    var setMarkers = mapView.onMapReady.listen((_) {
      mapView.setMarkers(markers);
      mapView.zoomToFit(padding: 100);
    });
    compositeSubscription.add(setMarkers);

    var toolbarAction = mapView.onToolbarAction.listen((id) {
      if (id == 1) {
        Navigator.pop(context);
        mapView.dismiss();
        compositeSubscription.cancel();
      }
    });
    compositeSubscription.add(toolbarAction);

    return new Scaffold();
  }
}

在点击地图的上一个屏幕中。

var churchStaticMarkers = [ new Marker("Church", "St Dunstan's Church", 51.0206245,0.2605629, color: Colors.red)];
var churchLocation = new Location(51.0206245, 0.2605629);
var staticMapProvider = new StaticMapProvider("XXXXX");

var churchStaticMapUri = staticMapProvider.getStaticUriWithMarkers(
    churchStaticMarkers,
    maptype: StaticMapViewType.roadmap,
    center: churchLocation
);

var churchMapContainer = new Container(
  child: new InkWell(
    child: new Stack(
      children: <Widget>[
        new Container(
          child: new Center(
            child: new CircularProgressIndicator(),
          ),
          padding: new EdgeInsets.all(16.0),
        ),
        new Center(
          child: new FadeInImage.memoryNetwork(
            placeholder: kTransparentImage,
            image: churchStaticMapUri.toString(),
          ),
        ),
      ],
    ),
    onTap: () {
      Navigator.push(
        context,
        new MaterialPageRoute(builder: (context) => new CustomMap(churchMapTitle, churchMapMarkers, churchPosition)),
      );
    },
  ),
  margin: new EdgeInsets.only(left: 8.0, top: 8.0, right: 8.0),
);

1 个答案:

答案 0 :(得分:0)

即使Flutter是为跨平台开发的,但并非所有内容都是用Dart编写的。有些部分需要platform specific (native) code。因此,您需要在代码中添加一些内容(请参见pub.dartlang.org

Android

您将对AndroidManifest.xml文件进行多次编辑。在Flutter项目中,您可以在android / app / src / main

下找到此文件位置

在您的AndroidManifest.xml中,在代码上方添加以下使用权限。

 <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
 <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>

在您的AndroidManifest.xml中,在application标记内添加以下行。确保用您生成的密钥替换your_api_key。

 <meta-data android:name="com.google.android.maps.v2.API_KEY" android:value="your_api_key"/>
 <meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version"/>

将MapActivity添加到您的AndroidManifest.xml

 <activity android:name="com.apptreesoftware.mapview.MapActivity" android:theme="@style/Theme.AppCompat.Light.DarkActionBar"/>

在您的android / build.gradle文件中。在buildScript依赖项下添加:

 classpath 'org.jetbrains.kotlin:kotlin-gradle-plugin:1.1.2-4'

在Android设备或模拟器上运行您的应用程序。确认显示地图时您会看到地图详细信息。如果您仅看到米色屏幕,则可能是您的API密钥不正确。

iOS

地图插件将在需要时请求您的用户位置。 iOS要求您在Info.plist文件中解释此用法 在ios / Runner / Info.plist中设置NSLocationWhenInUseUsageDescription。 示例:

<key>NSLocationWhenInUseUsageDescription</key>
<string>Using location to display on a map</string>

编辑:

此外,您还应该将MapOptions initialCameraPosition位置包装在CameraPosition中

initialCameraPosition: new CameraPosition(initialPosition)