Skip to content
This repository was archived by the owner on Jul 16, 2023. It is now read-only.

Exception in NavigationLauncher.StartNavigation method #4

Open
InnovativeTechies opened this issue Apr 8, 2018 · 17 comments
Open

Exception in NavigationLauncher.StartNavigation method #4

InnovativeTechies opened this issue Apr 8, 2018 · 17 comments

Comments

@InnovativeTechies
Copy link

Dear team,

I have cloned the latest navigationui code form githiub and when i run i am getting below exception:
"No virtual method locale()Ljava/util/Locale; in class Lcom/mapbox/services/android/navigation/v5/navigation/MapboxNavigationOptions; or its super classes (declaration of 'com.mapbox.services.android.navigation.v5.navigation.MapboxNavigationOptions' appears in /data/app/net.naxam.NavigationQs-1/base.apk:classes2.dex)"

I have attached the screen shot for the same.

Kindly help me out as i am using this for one of the client delivery.
screen shot 2018-04-08 at 11 25 24 pm

@tuyen-vuduc
Copy link
Contributor

@InnovativeTechies Which solution have you run? Plz try out mapboxnavigationui-droid.sln.

@InnovativeTechies
Copy link
Author

Dear Sir,

I am using Same solution. Please find my use case below:

  1. I am using google maps for selecting the Origin and Destination.
  2. I pass these values to Navigationlauncher of mapBox and below is the code

using System;
using System.Threading.Tasks;
using Android;
using Android.App;
using Android.Content.PM;
using Android.Locations;
using Android.OS;
using Android.Runtime;
using Android.Support.V4.App;
using Com.Mapbox.Api.Directions.V5.Models;
using Com.Mapbox.Geojson;
using Com.Mapbox.Mapboxsdk;
using Com.Mapbox.Services.Android.Navigation.V5.Navigation;
using Java.Lang;
using Square.Retrofit2;
using Com.Mapbox.Services.Android.Navigation.V5.Offroute;
using Com.Mapbox.Services.Android.Navigation.UI.V5;
using Plugin.CurrentActivity;

namespace CycloPath.Droid
{
[Activity(Label = "NewMap", ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation, ScreenOrientation = ScreenOrientation.Portrait)]
public class NewMap : Activity,ICallback, ILocationListener,INavigationEventListener,IOffRouteListener
{
double currentLat;
double currentLng;
double destLat;
double desLng;
LocationManager locationManager;
private DirectionsRoute route;

    readonly string[] PermissionsLocation =
            {
                    Manifest.Permission.AccessCoarseLocation,
                    Manifest.Permission.AccessFineLocation,
                    Manifest.Permission.AccessLocationExtraCommands,
                    Manifest.Permission.AccessMockLocation,
                    Manifest.Permission.AccessNetworkState,
                    Manifest.Permission.AccessWifiState,
                    Manifest.Permission.Internet,
                };
    const int RequestLocationId = 0;
    string mapboxAccessToken = "pk.eyJ1IjoiZGVzYWlwdXJwbGVzZW5zZSIsImEiOiJjajk1amY2MXUxaWd0MnFtdzR3ZG9zMm4xIn0.5X_DkAbGHK2VaMJPVo0SdQ";

    protected override void OnCreate(Bundle savedInstanceState)
    {
        //SetTheme(Resource.Style.NavigationViewLight);
        base.OnCreate(savedInstanceState);

        currentLat = Intent.Extras.GetDouble("key");
        currentLng = Intent.Extras.GetDouble("key1");
        destLat = Intent.Extras.GetDouble("key2");
        desLng = Intent.Extras.GetDouble("key3");

        // routetype = Intent.Extras.GetString("key4");

        if ((int)Build.VERSION.SdkInt > 22)
        {
            if (CheckSelfPermission(PermissionsLocation[0]) != (int)Permission.Granted || CheckSelfPermission(PermissionsLocation[1]) != (int)Permission.Granted)
            {
                ActivityCompat.RequestPermissions(this, PermissionsLocation, RequestLocationId);
            }
        }

        if (string.IsNullOrWhiteSpace(mapboxAccessToken))
        {
            throw new InvalidOperationException("Please configure your Mapbox access token");
        }

       // Mapbox.GetInstance(ApplicationContext, mapboxAccessToken);
        // GetLocation();
        LaunchNavigationWithRoute();
       

    }



    public override void OnRequestPermissionsResult(int requestCode, string[] permissions, Permission[] grantResults)
    {
        try
        {
            for (int i = 0; i < grantResults.Length; i++)
            {
                if (grantResults[i] == Permission.Denied)
                {
                    if (i == 0 || i == 1)
                    {

                        AlertDialog.Builder alert = new AlertDialog.Builder(this);
                        alert.SetTitle("Message");
                        alert.SetMessage("The location access is disabled.Please enable location source in system settings or by restart");
                        alert.SetPositiveButton("OK", (senderAlert, args) =>
                        {
                            Android.OS.Process.KillProcess(Android.OS.Process.MyPid());
                        });

                        RunOnUiThread(() =>
                        {
                            alert.Show();
                        });
                    }
                }

            }

        }
        catch (System.Exception ex)
        {

        }


    }

    private async void LaunchNavigationWithRoute()
    {
        await FetchRoute();

        //try
        //{
        //    NavigationViewOptions options = NavigationViewOptions.InvokeBuilder()
        //                                                         .Origin(Point.FromLngLat(currentLng, currentLat))
        //                                                         .Destination(Point.FromLngLat(desLng, destLat))
        //                                                         .AwsPoolId(null)
        //                                                         .ShouldSimulateRoute(false)
        //                                                         .DirectionsProfile("walking")
        //                                                         .Build();

        //    NavigationLauncher.StartNavigation((Activity)Xamarin.Forms.Forms.Context, options);
        //}
        //catch (System.Exception ex)
        //{

        //}

    }

    private async Task FetchRoute()
    {
       
        NavigationRoute
        .GetBuilder()
        .AccessToken(mapboxAccessToken)
          .Origin(Point.FromLngLat(currentLng, currentLat))
          .Destination(Point.FromLngLat(desLng, destLat))
        .Profile("walking")
        .Alternatives(new Java.Lang.Boolean(true))
        .Build()
        .GetRoute(this);
    }



    //public void OnFailure(ICall call, Throwable err)
    //{
    //          Toast.MakeText(this, "failed to get routes" + err.Message, ToastLength.Short).Show();
    //}

    //public void OnResponse(ICall call, Response response)
    //{
    //  if (ValidRouteResponse(response))
    //  {
    //      // HideLoading();
    //      var directions = Android.Runtime.Extensions.JavaCast<DirectionsResponse>(response.Body());

    //      route = directions.Routes()[0];
    //      var distance = route.Distance();

    //      NavigationViewOptions.Builder optionsBuilder = NavigationViewOptions
    //                  .InvokeBuilder()

    //      .ShouldSimulateRoute(true);

    //      if (route != null)
    //      {
    //          optionsBuilder.DirectionsRoute(route);
    //                  NavigationLauncher.StartNavigation((FormsAppCompatActivity)Xamarin.Forms.Forms.Context, optionsBuilder.Build());
    //      }
    //  }
    //}

    private bool ValidRouteResponse(Response response)
    {
      var directions = Android.Runtime.Extensions.JavaCast<DirectionsResponse>(response.Body());

      return directions != null
              && directions.Routes() != null
              && directions.Routes().Count > 0;
    }

 

    public void OnLocationChanged(Location location)
    {
        currentLat = location.Latitude;
        currentLng = location.Longitude;
    }

    public void OnProviderDisabled(string provider)
    {

    }

    public void OnProviderEnabled(string provider)
    {

    }

    public void OnStatusChanged(string provider, [GeneratedEnum] Availability status, Bundle extras)
    {

    }

    public void OnFailure(ICall p0, Throwable p1)
    {
        
    }

    public void OnResponse(ICall call, Response response)
    {
          if (ValidRouteResponse(response))
          {
            // HideLoading();
            var directions = Android.Runtime.Extensions.JavaCast<DirectionsResponse>(response.Body());

              route = directions.Routes()[0];
              var distance = route.Distance();


           // Com.Mapbox.Services.Android.Navigation.V5.Navigation.MapboxNavigation mapboxNavigation = new MapboxNavigation((Activity)Xamarin.Forms.Forms.Context, mapboxAccessToken);



              if (route != null)
              {
                NavigationViewOptions.Builder optionsBuilder = NavigationViewOptions
                        .InvokeBuilder()

            .ShouldSimulateRoute(false);
                optionsBuilder.DirectionsRoute(route);
                NavigationLauncher.StartNavigation(CrossCurrentActivity.Current.Activity, optionsBuilder.Build());
              }
          }
    }

    public void OnRunning(bool p0)
    {
        
    }

    public void UserOffRoute(Location p0)
    {
        
    }
}

}

On StartNavigationMethod the app crashes and Navigation UI wont open up. Kindly advice

@tuyen-vuduc
Copy link
Contributor

Plz folk this rep and put your changes there. I will try to look at.

@viktorgt
Copy link

viktorgt commented Apr 9, 2018

Facing the same issue if I run the NavigationQs demo from mapboxnavigationui-droid solution. The app starts and while the first example (Navigation Views) works for me, the Waypoint Navigation crashes with

04-09 20:34:43.550 I/MonoDroid(31241): UNHANDLED EXCEPTION:
04-09 20:34:43.583 I/MonoDroid(31241): Android.Views.InflateException: Binary XML file line #1: Binary XML file line #1: Error inflating class com.mapbox.services.android.navigation.ui.v5.NavigationView ---> Android.Views.InflateException: Binary XML file line #1: Error inflating class com.mapbox.services.android.navigation.ui.v5.NavigationView ---> Java.Lang.Reflect.InvocationTargetException: Exception of type 'Java.Lang.Reflect.InvocationTargetException' was thrown. ---> Android.Views.InflateException: Binary XML file line #1: Binary XML file line #1: Error inflating class com.mapbox.services.android.navigation.ui.v5.summary.SummaryBottomSheet ---> Android.Views.InflateException: Binary XML file line #1: Error inflating class com.mapbox.services.android.navigation.ui.v5.summary.SummaryBottomSheet ---> Java.Lang.Reflect.InvocationTargetException: Exception of type 'Java.Lang.Reflect.InvocationTargetException' was thrown. ---> Java.Lang.NoClassDefFoundError: Failed resolution of: Lcom/mapbox/services/android/navigation/v5/utils/LocaleUtils;

@InnovativeTechies
Copy link
Author

Hi sir,

I have forked and link is
https://github.com/InnovativeTechies/mapboxnavigationui-android-binding.

I have not made any changes just running demo app it crashes on Navigation Dropin ui

@viktorgt
Copy link

viktorgt commented Apr 9, 2018

Also facing the same bevahior in my own project. Here is a minimal reproducible of my project, which is nearly the same like the WaypointNavigationActivity from the demo.

https://github.com/viktorgt/MapboxTest

@InnovativeTechies
Copy link
Author

@viktorgt Hi Sir could you help me by sending the NavigationView source as i am facing issue over there?

@viktorgt
Copy link

@InnovativeTechies the mentioned NavigationView is from the mapboxnavigationui-android-binding demo without changes.

@osca
Copy link

osca commented Apr 14, 2018

+1
Same problem for me on Pixel 2, Android 8.1

@BradKwon
Copy link

+1
Same error message. I cannot find the locale method in the MapboxNavigationOptions class.
Also, I downloaded the latest, V11, mapboxnavigation-droid.sln and compiled the Naxam.MapboxNavigation.Droid. But I got some errors in extension classes in the Additions folder.

I think this might have led locale method to be hid although I could see this method in the MapboxNavigationOptions class that generated from Java code in the debug folder.

This locale() method seems to be added from Mapbox Navigation SDK v0.10.0.
You can check this in the release note link here:
https://github.com/mapbox/mapbox-navigation-android/releases/tag/v0.10.0

@martijnlentink
Copy link

I am facing the exact same issue. Any updates on this @tuyen-vuduc ?

@JFDionne
Copy link

JFDionne commented Jun 4, 2018

Someone found a work around for this?

@martijnlentink
Copy link

Sadly, no. Still no luck.

@JFDionne
Copy link

@tuyen-vuduc Since it appears to be a "bug" from the version of mapbox you used into this package, do you have any plan to use the lasted version of mapbox?

@tuyen-vuduc
Copy link
Contributor

Updating mapbox packages takes a lot of time. I don't have free time to work on it.

You guys has chance to use in your project, so there are efforts to get it upgraded.

I will then be very happy to merge the PR.

Cheers.

@JFDionne
Copy link

Perfect, I'm not an expert on that, but I'll try it :)

@BradKwon
Copy link

BradKwon commented Jul 26, 2018

@tuyen-vuduc Hey, I am Brad from the MindTags company and I tried to make a pull request but as I don't know how to use the cake build tool yet, I just uploaded binding libraries to my repo. Once I learn the cake build tool, I will try to make a pull request again. In the meantime, you can refer my repo to update yours. Cheers!

https://github.com/BradKwon/Xamarin.Android.Binding.Mapbox.Android.Navigation.UI

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants