-1

I am attempting to implement a navigation component to my application following this MapBox guide:

https://docs.mapbox.com/help/tutorials/android-navigation-sdk/

When I attempt to call .startNavigation(...) I get an unexpected error:

2020-03-08 19:51:45.786 11394-11394/com.example.mapboxnav A/libc: Fatal signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0x8 in tid 11394 (mple.mapboxnav), pid 11394 (mple.mapboxnav)

Since the application I'm creating features many buttons, I've implemented View.OnClickListener and am calling the Navigation interface when a user presses the navigation button (R.id.startNav). However, as soon as a user presses the button the application crashes.

The currentRoute is working and shown on the map upon calling getRoute, like the example. I have verified that currentRoute is definitely not null. I have also attempted to start navigation with different coordinates without any luck.

currentRoute contains a route from the user's current/last known location to a specified destination. For reference, the line is set/generated with the following method:

public void initLine(Double lng, Double lat) {
        Location lastKnownLocation = mapboxMap.getLocationComponent().getLastKnownLocation();
        Point origin = Point.fromLngLat(lastKnownLocation.getLongitude(), lastKnownLocation.getLatitude());
        Point destination = Point.fromLngLat(lng, lat);
        getRoute(origin, destination);

    }

onClick:

public void onClick(View v) {
        switch (v.getId()) {
            ...

            case R.id.startNav:

                boolean simulateRoute = true;

                NavigationLauncherOptions options = NavigationLauncherOptions.builder()
                        .directionsRoute(currentRoute)
                        .shouldSimulateRoute(simulateRoute)
                        .build();
                NavigationLauncher.startNavigation(MainActivity.this, options); // Causes Crash

        }
    }
Enigmatic
  • 3,902
  • 6
  • 26
  • 48
  • What other info is there about the crash? There should be more information in the Android Studio logcat when the app crashes. Search for the word `FATAL` and/or `Mbgl`. – langsmith Mar 09 '20 at 16:31
  • @langsmith There is no more information. The error I specified is the only one that appears. – Enigmatic Mar 09 '20 at 23:38
  • Can you edit your question with your build.gradle (app)? – Robert Mar 11 '20 at 23:48

3 Answers3

1

I spend two and a half days over this until I discovered that the problem is that we need to set the location Engine before calling :

NavigationLauncher.startNavigation(MainActivity.this, options);

so your code should look like this and it should work:

NavigationLauncherOptions options = NavigationLauncherOptions.builder()
                            .directionsRoute(currentRoute)
                            .shouldSimulateRoute(simulateRoute)
                            .build();
    
    
// Just add these three lines
MapboxNavigation navigation = new MapboxNavigation(DriveActivity.this, getString(R.string. mapbox_access_token));
navigation.setLocationEngine(locationEngine);              mapboxMap.getLocationComponent().setLocationComponentEnabled(true);


NavigationLauncher.startNavigation(MainActivity.this, options);

Let me know how it goes

Criss

Criss Gibran
  • 104
  • 2
  • 5
0

Hmm, very strange. I still feel like there's gotta be more info buried in the logcat. Maybe well above the Fatal signal 11 line? Maybe, just maybe, it's related to Location lastKnownLocation = mapboxMap.getLocationComponent().getLastKnownLocation();. Add a null check for lastKnownLocation and put

    Point origin = Point.fromLngLat(lastKnownLocation.getLongitude(), lastKnownLocation.getLatitude());
    Point destination = Point.fromLngLat(lng, lat);
    getRoute(origin, destination);

inside of the null check block?

Maybe you're using the wrong classes? Look at the Nav SDK's NavigationLauncher test app activity: https://github.com/mapbox/mapbox-navigation-android/blob/master/app/src/main/java/com/mapbox/services/android/navigation/testapp/activity/navigationui/NavigationLauncherActivity.java#L342-L347. It's using NavigationLauncherOptions.Builder, whereas you aren't.

https://github.com/mapbox/mapbox-navigation-android/blob/master/app/src/main/java/com/mapbox/services/android/navigation/testapp/activity/navigationui/NavigationLauncherActivity.java#L365

langsmith
  • 2,529
  • 1
  • 11
  • 13
  • Thanks for your suggestions however I still have no luck. In regards to the error, unfortunately that it still the only one that appears. I have thoroughly looked through the logcat – Enigmatic Mar 10 '20 at 15:42
  • So strange. Do you see what I mean about different builder classes being used when comparing test app to your code? Have you looked into that? Try copying over what's in the test app to your code... – langsmith Mar 10 '20 at 22:25
  • I see what you mean. However I'm pretty sure that's the old version of the dependency. Utilising the object has changed as far as I'm aware. – Enigmatic Mar 11 '20 at 04:15
-1

A SIGSEGV error is thrown when you attempt to access memory incorrectly or are accessing a piece of memory that is not allotted for your use. See What causes a SIGSEGV for more information on this.

The fact that the error occurs on the line below,

NavigationLauncher.startNavigation(MainActivity.this, options);

leads me to believe that NavigationLauncherOptions options is not being assigned correctly and is possibly NULL causing you to derefrence a null pointer.

I know this isn't a perfect answer and doesn't really provide a solution to your problem, but I hope it helps bring you closer to finding an answer.

Here are some links that may help(including documentation): https://github.com/mapbox/mapbox-navigation-android/issues/1529 https://docs.mapbox.com/android/navigation/overview/

noahjillson
  • 122
  • 7