mapbox / mapbox-navigation-android

Mapbox Navigation SDK for Android
https://docs.mapbox.com/android/navigation/overview/
Other
622 stars 319 forks source link

Mapbox Android: Binary XML file line #21: Error inflating class com.mapbox.services.android.navigation.ui.v5.instruction.InstructionView #2290

Closed matteobelluzzo closed 4 years ago

matteobelluzzo commented 4 years ago

Hello, I'm developing an android app that integrates map and mapbox navigation, but my program crashes when i click on "navigationStartButton".

In my Activity:

` @Override public void onMapReady(@NonNull final MapboxMap mapboxMap) { this.mapboxMap = mapboxMap;

    mapboxMap.setStyle(Style.SATELLITE_STREETS, new Style.OnStyleLoaded() {

        @Override
        public void onStyleLoaded(@NonNull Style style) {

            addGeoJsonSourceOnMap(style, createGeoJsonSource(SOURCE_GEOJSON, jsonResponseSchedule));
            addGeoJsonSourceOnMap(style, createEmptyGeoJsonSource(SOURCE_EDITED));
            setUpImage(style);

            addOtherLayer(style);
            addPointsLayerAndSetFilter(style);
            addLinesLayerAndSetFilter(style);

            enableLocationComponent(style);

            mapboxMap.addOnMapClickListener(MapActivity.this);

            navigationStartButton.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    boolean simulateRoute = true;
                    NavigationLauncherOptions options = NavigationLauncherOptions.builder()
                            .directionsRoute(currentRoute)
                            .shouldSimulateRoute(simulateRoute)
                            .build();
                    // Call this method with Context from within an Activity
                    NavigationLauncher.startNavigation(MapActivity.this, options);

                }
            });

        }
    });`

build.gradle (Module: app)

`

apply plugin: 'com.android.application'

android { compileSdkVersion 29 buildToolsVersion "29.0.2" defaultConfig { applicationId "com.dw.ImcAppAndroid" minSdkVersion 21 targetSdkVersion 29 versionCode 1 versionName "1.0" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" } buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'

    }
}
compileOptions {
    sourceCompatibility = 1.8
    targetCompatibility = 1.8
}

} `

dependencies { implementation fileTree(include: ['*.jar'], dir: 'libs')

implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'com.google.android.material:material:1.0.0'
implementation 'androidx.annotation:annotation:1.1.0'

implementation 'androidx.lifecycle:lifecycle-extensions:2.1.0'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'

//noinspection GradleCompatible
implementation 'androidx.coordinatorlayout:coordinatorlayout:1.0.0'
implementation 'androidx.cardview:cardview:1.0.0'

// Json Mapping
implementation 'com.google.code.gson:gson:2.8.6'

// Connection
implementation 'com.squareup.okhttp3:okhttp:3.11.0'

// Mapbox
implementation 'com.mapbox.mapboxsdk:mapbox-android-sdk:8.6.0-alpha.1'
implementation 'com.mapbox.mapboxsdk:mapbox-android-plugin-locationlayer:0.11.0'
implementation 'com.mapbox.mapboxsdk:mapbox-android-plugin-markerview-v8:0.3.0'
implementation 'com.mapbox.mapboxsdk:mapbox-android-plugin-localization-v8:0.11.0'
implementation 'com.mapbox.mapboxsdk:mapbox-android-navigation-ui:0.42.4'

//Butterknife
implementation 'com.jakewharton:butterknife:10.2.0'
annotationProcessor 'com.jakewharton:butterknife-compiler:10.2.0'

}`

Android API: compileSdkVersion 29, minSdkVersion 21, tested on 24 Mapbox Navigation SDK version: 8.6.0-alpha.1 **Mapbox Navigation UI version: 0.42.4

Expected behavior:

Start Navigation

Actual behavior :

java.lang.RuntimeException: Unable to start activity ComponentInfo{com.app/com.mapbox.services.android.navigation.ui.v5.MapboxNavigationActivity}: android.view.InflateException: Binary XML file line #21: Binary XML file line #21: Error inflating class com.mapbox.services.android.navigation.ui.v5.instruction.InstructionView at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2957) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3032) at android.app.ActivityThread.-wrap11(Unknown Source:0) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1696) at android.os.Handler.dispatchMessage(Handler.java:105) at android.os.Looper.loop(Looper.java:164) at android.app.ActivityThread.main(ActivityThread.java:6944) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:327) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1374) Caused by: android.view.InflateException: Binary XML file line #21: Binary XML file line #21: Error inflating class com.mapbox.services.android.navigation.ui.v5.instruction.InstructionView Caused by: android.view.InflateException: Binary XML file line #21: Error inflating class com.mapbox.services.android.navigation.ui.v5.instruction.InstructionView Caused by: java.lang.reflect.InvocationTargetException

Guardiola31337 commented 4 years ago

@abhishek1508 @JunDai Is this still an issue in 1.0?

Also this references to https://github.com/mapbox/mapbox-navigation-android/issues/3034

RingerJK commented 4 years ago

add to project's Application.class initialisation of Mapbox like

class MyApplication : Application() {
  override fun onCreate() {
        super.onCreate()
        Mapbox.getInstance(applicationContext, "access_token")
  }
}
najam-amfnrh9 commented 10 months ago

@RingerJK but this method causing to much crashes in crash report about Mapbox initialization.