I am trying to integrate navigation on a site map using mapbox but my app crashed when I click on the site map page
E/AndroidRuntime: FATAL EXCEPTION: main Process: com.example.vrtour, PID: 14793 java.lang.NoClassDefFoundError: Failed resolution of: Landroidx/localbroadcastmanager/content/LocalBroadcastManager; at com.mapbox.android.telemetry.TelemetryService.registerLocationReceiver(TelemetryService.java:163) at com.mapbox.android.telemetry.TelemetryService.createLocationReceiver(TelemetryService.java:158) at com.mapbox.android.telemetry.TelemetryService.onCreate(TelemetryService.java:41) at android.app.ActivityThread.handleCreateService(ActivityThread.java:3532) at android.app.ActivityThread.access$1300(ActivityThread.java:199) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1666) at android.os.Handler.dispatchMessage(Handler.java:106) at android.os.Looper.loop(Looper.java:193) at android.app.ActivityThread.main(ActivityThread.java:6669) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858) Caused by: java.lang.ClassNotFoundException: Didn't find class "androidx.localbroadcastmanager.content.LocalBroadcastManager" on path: DexPathList[[zip file "/data/app/com.example.vrtour-7_IWX5sSQKzHKJREz6hETw==/base.apk"],nativeLibraryDirectories=[/data/app/com.example.vrtour-7_IWX5sSQKzHKJREz6hETw==/lib/x86, /data/app/com.example.vrtour-7_IWX5sSQKzHKJREz6hETw==/base.apk!/lib/x86, /system/lib]] at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:134) at java.lang.ClassLoader.loadClass(ClassLoader.java:379) at java.lang.ClassLoader.loadClass(ClassLoader.java:312) at com.mapbox.android.telemetry.TelemetryService.registerLocationReceiver(TelemetryService.java:163) at com.mapbox.android.telemetry.TelemetryService.createLocationReceiver(TelemetryService.java:158) at com.mapbox.android.telemetry.TelemetryService.onCreate(TelemetryService.java:41) at android.app.ActivityThread.handleCreateService(ActivityThread.java:3532) at android.app.ActivityThread.access$1300(ActivityThread.java:199) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1666) at android.os.Handler.dispatchMessage(Handler.java:106) at android.os.Looper.loop(Looper.java:193) at android.app.ActivityThread.main(ActivityThread.java:6669) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
My main activity code
package com.example.vrtour;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import android.location.Location;
import android.os.Bundle;
import android.os.PersistableBundle;
import com.mapbox.android.core.location.LocationEngine;
import com.mapbox.android.core.location.LocationEngineListener;
import com.mapbox.android.core.location.LocationEnginePriority;
import com.mapbox.android.core.location.LocationEngineProvider;
import com.mapbox.android.core.permissions.PermissionsListener;
import com.mapbox.android.core.permissions.PermissionsManager;
import com.mapbox.mapboxsdk.Mapbox;
import com.mapbox.mapboxsdk.camera.CameraUpdateFactory;
import com.mapbox.mapboxsdk.geometry.LatLng;
import com.mapbox.mapboxsdk.maps.MapView;
import com.mapbox.mapboxsdk.maps.MapboxMap;
import com.mapbox.mapboxsdk.maps.OnMapReadyCallback;
import com.mapbox.mapboxsdk.plugins.locationlayer.LocationLayerPlugin;
import com.mapbox.mapboxsdk.plugins.locationlayer.modes.CameraMode;
import com.mapbox.mapboxsdk.plugins.locationlayer.modes.RenderMode;
import java.util.List;
public class SiteMap extends AppCompatActivity implements OnMapReadyCallback, LocationEngineListener, PermissionsListener {
private MapView mapView;
private MapboxMap map;
private PermissionsManager permissionsManager;
private LocationEngine locationEngine;
private LocationLayerPlugin locationLayerPlugin;
private Location originLocation;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Mapbox.getInstance(this,getString(R.string.access_token));
setContentView(R.layout.activity_site_map);
mapView = (MapView) findViewById(R.id.mapView);
mapView.onCreate(savedInstanceState);
mapView.getMapAsync(this);
}
@Override
public void onMapReady(MapboxMap mapboxMap) {
map= mapboxMap;
enableLocation();
}
private void enableLocation(){
if (PermissionsManager.areLocationPermissionsGranted(this)){
initializeLocationEngine();
initializeLocationLayer();
}else {
permissionsManager = new PermissionsManager(this);
permissionsManager.requestLocationPermissions(this);
}
}
private void initializeLocationEngine(){
locationEngine = new LocationEngineProvider(this).obtainBestLocationEngineAvailable();
locationEngine.setPriority(LocationEnginePriority.HIGH_ACCURACY);
locationEngine.activate();
Location lastLocation = locationEngine.getLastLocation();
if (lastLocation !=null){
originLocation = lastLocation;
setCameraPosition(lastLocation);
}else{
locationEngine.addLocationEngineListener(this);
}
}
private void initializeLocationLayer(){
locationLayerPlugin = new LocationLayerPlugin(mapView,map,locationEngine);
locationLayerPlugin.setLocationLayerEnabled(true);
locationLayerPlugin.setCameraMode(CameraMode.TRACKING);
locationLayerPlugin.setRenderMode(RenderMode.NORMAL);
}
private void setCameraPosition(Location location){
map.animateCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(location.getLatitude(),
location.getLongitude()), 13.0 ));
}
@Override
public void onConnected() {
locationEngine.requestLocationUpdates();
}
@Override
public void onLocationChanged(Location location) {
if (location != null){
originLocation=location;
setCameraPosition(location);
}
}
@Override
public void onExplanationNeeded(List<String> permissionsToExplain) {
//present toast or dialog
}
@Override
public void onPermissionResult(boolean granted) {
if (granted){
enableLocation();
}
}
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
permissionsManager.onRequestPermissionsResult(requestCode, permissions, grantResults);
}
@Override
protected void onStart() {
super.onStart();
if (locationEngine !=null){
locationEngine.requestLocationUpdates();
}
if (locationLayerPlugin !=null){
locationLayerPlugin.onStart();
}
mapView.onStart();
}
@Override
protected void onResume() {
super.onResume();
mapView.onResume();
}
@Override
protected void onPause() {
super.onPause();
mapView.onPause();
}
@Override
protected void onStop() {
super.onStop();
if (locationEngine != null){
locationEngine.removeLocationUpdates();
}
if (locationLayerPlugin != null){
locationLayerPlugin.onStop();
}
mapView.onStop();
}
@Override
public void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
mapView.onSaveInstanceState(outState);
}
@Override
public void onLowMemory() {
super.onLowMemory();
mapView.onLowMemory();
}
@Override
protected void onDestroy() {
super.onDestroy();
if ( locationEngine != null){
locationEngine.deactivate();
}
mapView.onDestroy();
}
}
My xml code
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:mapbox="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".SiteMap">
<com.mapbox.mapboxsdk.maps.MapView
android:id="@+id/mapView"
android:layout_width="match_parent"
android:layout_height="match_parent"
mapbox:mapbox_cameraTargetLat= "3.0246"
mapbox:mapbox_cameraTargetLng="101.5161"
mapbox:mapbox_styleUrl="mapbox://styles/mapbox/streets-v10"
mapbox:mapbox_cameraZoom="12">
</com.mapbox.mapboxsdk.maps.MapView>
</androidx.constraintlayout.widget.ConstraintLayout>