I am following the tutorial for creating a MapBox navigation application. When I get to the point to get a Route, I copy the entire code section, and I check the currentRoute class to see if I indeed get a route, and it returns a direction and other calls to the DirectionsRoute class so I assume I have a route ready to be added. Everything seems to be fine, until I try to add the currentRoute to NavigationMapRoute. Then I get an error java.lang.NoSuchMethodError: No direct method <init>(Ljava/lang/String;Lcom/mapbox/services/commons/geojson/FeatureCollection;Lcom/mapbox/mapboxsdk/style/sources/GeoJsonOptions;)V in class Lcom/mapbox/mapboxsdk/style/sources/GeoJsonSource; or its super classes (declaration of 'com.mapbox.mapboxsdk.style.sources.GeoJsonSource' appears in /data/app/MyApp-IHmaY_75jKlOywZrW4r3Ow==/base.apk)
I'm confused because I wasn't expecting to fail a call in the tutorial section when I have everything set up. What am I missing here? (Code taken from https://www.mapbox.com/help/android-navigation-sdk/#calculate-and-draw-route) `
private void getRoute(com.mapbox.geojson.Point origin, com.mapbox.geojson.Point destination) {
NavigationRoute.builder()
.accessToken(Mapbox.getAccessToken())
.origin(origin)
.destination(destination)
.build()
.getRoute(new Callback<DirectionsResponse>() {
@Override
public void onResponse(Call<DirectionsResponse> call, Response<DirectionsResponse> response) {
// You can get the generic HTTP info about the response
Log.d(TAG, "Response code: " + response.code());
if (response.body() == null) {
Log.e(TAG, "No routes found, make sure you set the right user and access token.");
return;
} else if (response.body().routes().size() < 1) {
Log.e(TAG, "No routes found");
return;
}
currentRoute = response.body().routes().get(0);
// Draw the route on the map
if (navigationMapRoute != null) {
navigationMapRoute.removeRoute();
} else {
navigationMapRoute = new NavigationMapRoute(null, mapView, mapboxMap, R.style.NavigationMapRoute);
}
navigationMapRoute.addRoute(currentRoute);
}
@Override
public void onFailure(Call<DirectionsResponse> call, Throwable throwable) {
Log.e(TAG, "Error: " + throwable.getMessage());
}
});
}
This code is in my onCreate()
destinationPosition = com.mapbox.geojson.Point.fromLngLat(-122.269532,37.879842);
originPosition = com.mapbox.geojson.Point.fromLngLat(-122.258875, 37.865593);
getRoute(originPosition, destinationPosition);
Build.Gradle file:
apply plugin: 'com.android.application'
android {
compileSdkVersion 26
defaultConfig {
applicationId "MyApp"
minSdkVersion 22
targetSdkVersion 26
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
repositories {
mavenCentral()
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:26.1.0'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
implementation 'com.google.android.gms:play-services-location:11.0.4'
implementation 'com.mapbox.mapboxsdk:mapbox-android-sdk:5.5.1'
implementation "com.mapzen.android:lost:3.0.2"
implementation ('com.mapbox.mapboxsdk:mapbox-android-sdk:6.0.1@aar') {
transitive=true
}
implementation 'com.mapbox.mapboxsdk:mapbox-android-navigation:0.12.0'
implementation ('com.mapbox.mapboxsdk:mapbox-android-navigation-ui:0.12.0') {
transitive = true
}
implementation 'com.android.support:design:26.1.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
}
Full error:
java.lang.NoSuchMethodError: No direct method <init>(Ljava/lang/String;Lcom/mapbox/services/commons/geojson/FeatureCollection;Lcom/mapbox/mapboxsdk/style/sources/GeoJsonOptions;)V in class Lcom/mapbox/mapboxsdk/style/sources/GeoJsonSource; or its super classes (declaration of 'com.mapbox.mapboxsdk.style.sources.GeoJsonSource' appears in /data/app/Me.MyApp-ALhfKnyL4l3OfYHrn1IyAQ==/base.apk)
at com.mapbox.services.android.navigation.ui.v5.utils.MapUtils.updateMapSourceFromFeatureCollection(MapUtils.java:43)
at com.mapbox.services.android.navigation.ui.v5.route.NavigationMapRoute.drawRoutes(NavigationMapRoute.java:307)
at com.mapbox.services.android.navigation.ui.v5.route.NavigationMapRoute.addRoutes(NavigationMapRoute.java:244)
at com.mapbox.services.android.navigation.ui.v5.route.NavigationMapRoute.addRoute(NavigationMapRoute.java:226)
at Me.MyApp.MainActivity$1.onResponse(MainActivity.java:231)
at com.mapbox.api.directions.v5.MapboxDirections$1.onResponse(MapboxDirections.java:167)
at retrofit2.ExecutorCallAdapterFactory$ExecutorCallbackCall$1$1.run(ExecutorCallAdapterFactory.java:70)
at android.os.Handler.handleCallback(Handler.java:790)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6494)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)