2gis / mobile-sdk-android-demo

BSD 2-Clause "Simplified" License
16 stars 15 forks source link

Ошибка при показе DefaultNavigationControls #175

Closed 1encore closed 1 year ago

1encore commented 1 year ago

версия SDK 2.8.2

Я пишу плагин для того, чтобы использовать SDK через Flutter фреймворк, там при работе с нативом не поддерживаются layouts, приходится обходиться с addView(). В итоге получился такой код:

rootView = FrameLayout(context).apply {
            layoutParams = fullLayoutParams
        }

        mapView = MapView(context, MapOptions().apply {
            position = CameraPosition(
                    point = GeoPoint(
                            latitude = Latitude(creationParams?.get("latitude") as Double),
                            longitude = Longitude(creationParams["longitude"] as Double)),
                    zoom = Zoom((creationParams["zoom"] as Double).toFloat()),
                    tilt = Tilt((creationParams["tilt"] as Double).toFloat()),
                    bearing = Bearing((creationParams["bearing"] as Double)),
            );
        })

        navigationView = NavigationView(context).apply {
            layoutParams = FrameLayout.LayoutParams(
                    FrameLayout.LayoutParams.MATCH_PARENT,
                    FrameLayout.LayoutParams.MATCH_PARENT
            )
        }

        val defaultNavigationControls = DefaultNavigationControls(context).apply {
            layoutParams = FrameLayout.LayoutParams(
                    FrameLayout.LayoutParams.MATCH_PARENT,
                    FrameLayout.LayoutParams.MATCH_PARENT
            )
        }

        navigationView.navigationManager = navigationManager
        navigationView.addView(defaultNavigationControls)
        mapView.addView(navigationView)

        mapView.useDefaultGestureRecognitionEngine()
        rootView.addView(mapView)

текст ошибки при запуске:

[ERROR:flutter/fml/platform/android/jni_util.cc(204)] android.view.InflateException: Binary XML file line #22 in com.example.project:layout/dgis_default_navigation_controls: Binary XML file line #22 in com.example.project:layout/dgis_default_navigation_controls: Error inflating class ru.dgis.sdk.navigation.NextManeuverControl
    Caused by: android.view.InflateException: Binary XML file line #22 in com.example.project:layout/dgis_default_navigation_controls: Error inflating class ru.dgis.sdk.navigation.NextManeuverControl
    Caused by: java.lang.reflect.InvocationTargetException
        at java.lang.reflect.Constructor.newInstance0(Native Method)
        at java.lang.reflect.Constructor.newInstance(Constructor.java:343)
        at android.view.LayoutInflater.createView(LayoutInflater.java:852)
        at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:1004)
        at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:959)
        at android.view.LayoutInflater.rInflate(LayoutInflater.java:1121)
        at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:1082)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:680)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:532)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:479)
        at android.view.View.inflate(View.java:28552)
        at ru.dgis.sdk.navigation.DefaultNavigationControls.inflateLayout(DefaultNavigationControls.kt:76)
        at ru.dgis.sdk.navigation.DefaultNavigationControls.onAttachedToWindow(DefaultNavigationControls.kt:107)
        at android.view.View.dispatchAttachedToWindow(View.java:22010)
        at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:4291)
        at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:4298)
        at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:4298)
        at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:4298)
        at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:4298)
        at android.view.ViewGroup.addViewInner(ViewGroup.java:6108)
        at android.view.ViewGroup.addView(ViewGroup.java:5884)
        at android.view.ViewGroup.addView(ViewGroup.java:5824)
        at android.view.ViewGroup.addView(ViewGroup.java:5796)
        at io.flutter.plugin.platform.PlatformViewsController.initializePlatformViewIfNeeded(PlatformViewsController.java:1030)
        at io.flutter.plugin.platform.PlatformViewsController.onDisplayPlatformView(PlatformViewsController.java:1060)
        at io.flutter.embedding.engine.FlutterJNI.onDisplayPlatformView(FlutterJNI.java:1380)
        at android.os.MessageQueue.nativePollOnce(Native Method)
        at android.os.MessageQueue.next(MessageQueue.java:335)
        at android.os.Looper.loop(Looper.java:206)
        at android.app.ActivityThread.main(ActivityThread.java:8633)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:602)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1130)
     Caused by: android.view.InflateException: Binary XML file line #2 in com.example.project:layout/dgis_navigator_next_maneuver_control: Binary XML file line #2 in com.example.project:layout/dgis_navigator_next_maneuver_control: Error inflating class <unknown>
     Caused by: android.view.InflateException: Binary XML file line #2 in com.example.project:layout/dgis_navigator_next_maneuver_control: Error inflating class <unknown>
     Caused by: java.lang.reflect.InvocationTargetException
        at java.lang.reflect.Constructor.newInstance0(Native Method)
        at java.lang.reflect.Constructor.newInstance(Constructor.java:343)
        at android.view.LayoutInflater.createView(LayoutInflater.java:852)
        at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:1004)
        at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:959)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:657)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:532)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:479)
E/flutter:     at android.view.View.inflate(View.java:28552)
        at ru.dgis.sdk.navigation.NextManeuverControl.<init>(NextManeuverControl.kt:39)
        at ru.dgis.sdk.navigation.NextManeuverControl.<init>(NextManeuverControl.kt:18)
        at ru.dgis.sdk.navigation.NextManeuverControl.<init>(Unknown Source:6)
        at java.lang.reflect.Constructor.newInstance0(Native Method)
        at java.lang.reflect.Constructor.newInstance(Constructor.java:343)
        at android.view.LayoutInflater.createView(LayoutInflater.java:852)
        at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:1004)
        at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:959)
        at android.view.LayoutInflater.rInflate(LayoutInflater.java:1121)
        at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:1082)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:680)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:532)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:479)
        at android.view.View.inflate(View.java:28552)
        at ru.dgis.sdk.navigation.DefaultNavigationControls.inflateLayout(DefaultNavigationControls.kt:76)
        at ru.dgis.sdk.navigation.DefaultNavigationControls.onAttachedToWindow(DefaultNavigationControls.kt:107)
        at android.view.View.dispatchAttachedToWindow(View.java:22010)
        at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:4291)
        at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:4298)
        at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:4298)
        at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:4298)
        at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:4298)
        at android.view.ViewGroup.addViewInner(ViewGroup.java:6108)
        at android.view.ViewGroup.addView(ViewGroup.java:5884)
        at android.view.ViewGroup.addView(ViewGroup.java:5824)
        at android.view.ViewGroup.addView(ViewGroup.java:5796)
        at io.flutter.plugin.platform.PlatformViewsController.initializePlatformViewIfNeeded(PlatformViewsController.java:1030)
        at io.flutter.plugin.platform.PlatformViewsController.onDisplayPlatformView(PlatformViewsController.java:1060)
        at io.flutter.embedding.engine.FlutterJNI.onDisplayPlatformView(FlutterJNI.java:1380)
        at android.os.MessageQueue.nativePollOnce(Native Method)
        at android.os.MessageQueue.next(MessageQueue.java:335)
        at android.os.Looper.loop(Looper.java:206)
        at android.app.ActivityThread.main(ActivityThread.java:8633)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:602)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1130)
     Caused by: java.lang.UnsupportedOperationException: Failed to resolve attribute at index 13: TypedValue{t=0x2/d=0x7f030159 a=-1}
        at android.content.res.TypedArray.getDrawableForDensity(TypedArray.java:997)
        at android.content.res.TypedArray.getDrawable(TypedArray.java:981)
        at android.view.View.<init>(View.java:5954)
        at android.view.ViewGroup.<init>(ViewGroup.java:715)
        at android.view.ViewGroup.<init>(ViewGroup.java:711)
        at android.view.ViewGroup.<init>(ViewGroup.java:707)
        at androidx.constraintlayout.widget.ConstraintLayout.<init>(ConstraintLayout.java:587)
            ... 45 more
A/flutter: [FATAL:flutter/shell/platform/android/platform_view_android_jni_impl.cc(1466)] Check failed: fml::jni::CheckException(env). 
A/libc: Fatal signal 6 (SIGABRT), code -1 (SI_QUEUE) in tid 9005 (com.example.project), pid 9005 (com.example.project)
lagner commented 1 year ago

Привет.

Не совсем в тему, но важная информация. Ты используешь SDK версии 2.8.2, это старая версия, она уже заморожена и совсем скоро перестанет обновляться совсем. Т.ч. важно переходить на более современный релиз, тем более для нового кода.

Можешь проверить есть ли такая ошибка на более свежем релизе (последний на данный момент 5.0.1) и если есть поделиться демо проектом где баг воспроизводится?