0

I have a map_view and using the staticMapURI to display a full view map, but the moment i tap on the map the app crashes with:

  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.

Ive read in other posts that you need to make sure your dependencies match etc but i can seem to get this to work when i try exactly what was shown in linked post.

My current dependencies look like this:

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

Can anyone insight into how to fix this?

Update:

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();
  }
}

in the previous screen where the map is tapped.

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),
);
Wazza
  • 1,725
  • 2
  • 17
  • 49
  • Can you share your code where you create the map_view? And did you add all dependencies in your app gradle and project gradle including classpath? – Bostrot Jun 20 '18 at 21:03
  • Hi i have updated showing how the mapview is called/shown. im not sure whagt you mean about the `app gradle and project gradle including classpath` as this is a flutter app and the dependencies just go in the pubspec.yaml – Wazza Jun 20 '18 at 21:16

1 Answers1

0

Even though Flutter is made for cross platforming not everything is written in Dart. Some parts need platform specific (native) code. So there are some things that needs to be added to your code (see pub.dartlang.org)

Android

You will be making multiple edits to your AndroidManifest.xml file. In your Flutter project, you can find this file location under android/app/src/main

In your AndroidManifest.xml, add the following uses-permission above the tag.

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

In your AndroidManifest.xml, add the following lines inside of the application tag. Be sure to replace your_api_key with the one you generated.

 <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"/>

Add the MapActivity to your AndroidManifest.xml

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

In your android/build.gradle file. Under buildScript dependencies add:

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

Run your application on an Android device or simulator. Confirm that when you display the map you see map detail. If you only see a beige screen it's possible that your API key is incorrect.

iOS

The maps plugin will request your users location when needed. iOS requires that you explain this usage in the Info.plist file Set the NSLocationWhenInUseUsageDescription in ios/Runner/Info.plist. Example:

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

EDIT:

Also you should wrap the MapOptions initialCameraPosition Location in CameraPosition

initialCameraPosition: new CameraPosition(initialPosition)
Bostrot
  • 5,767
  • 3
  • 37
  • 47
  • I had done these things already and the static map shows fine but when tapping it the map crashes – Wazza Jun 20 '18 at 21:45
  • @Wazza you forgot to wrap the Location into a CameraPosition. I edited the answer. – Bostrot Jun 20 '18 at 22:10
  • Im afraid not, :( the initial {Position is already a CameraPosition passed to the CustomMap class. im sure the error is in the dependencies not matching somewhere but i cant see where – Wazza Jun 20 '18 at 22:30
  • Normally you would get an other error when one of the dart dependencies is not matching or correlating with one other. Here is a GitHub issue that looks similar to yours. https://github.com/flutter/flutter/issues/16510 – Bostrot Jun 20 '18 at 22:39