Search code examples
androidgradlemapboxmapbox-android

Mapbox - Failed resolution of LostLocationEngine


When I try to start navigation:

MapboxNavigation navigation = new MapboxNavigation(this, Mapbox.getAccessToken(), options);
navigation.startNavigation(route);

I get the following error on runtime:

java.lang.NoClassDefFoundError: Failed resolution of: Lcom/mapbox/services/android/telemetry/location/LostLocationEngine;
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.mapbox.services.android.telemetry.location.LostLocationEngine"

Indeed I am not able to import the class from that location, however the LocationEngine is available from com.mapbox.services.android.location.LostLocationEngine. I think it might have something to do with the dependencies. This is what I build from mapbox in my Gradle file:

implementation 'com.mapbox.mapboxsdk:mapbox-android-plugin-places:0.3.0'
implementation 'com.mapbox.mapboxsdk:mapbox-android-plugin-locationlayer:0.5.0'
implementation 'com.mapbox.mapboxsdk:mapbox-android-navigation:0.12.0'

How can I solve this so I can start navigation in my app?


Solution

  • TL:DR

    Use the version 0.13.0-SNAPSHOT

    repositories {
        mavenCentral()
        maven { url "http://oss.sonatype.org/content/repositories/snapshots/" }
    }
    
    dependencies {
        implementation'com.mapbox.mapboxsdk:mapbox-android-navigation:0.13.0-SNAPSHOT'
    }    
    

    Explanation

    The problem is that LocationLayer and Places are using Mapbox 6 (LocationLayer 0.5.0, Places 0.3.0), but the navigation is using Mapbox 5 (Navigation 0.12.0).

    When you combine these 3 libraries, Gradle will try to use the latest version of a dependencies when 2 libraries shared the same.

    In our case, the mapbox-android-telemetry will be upgrade from 2.2.10 to 3.0.2. This is why when the nagivation tries to find LostLocationEngine under com.mapbox.services.android.telemetry.location (v2) it fails, because this classed move to com.mapbox.services.android.location (v3).

    If you want to know how to check the dependencies version, look here