Closed Plovotok closed 4 months ago
Changing style only after onStyleLoaded or onMapLoaded callback also crashes the app
@Plovotok thanks, we will take a look if we could reproduce this one.
App usually crashes after some action with camera like MapViewportState#flyTo or MapViewportState#easeTo. If camera state changes cause of user interaction, application works normally
@Plovotok we tried to reproduce the issue, but we weren't successful. Could you please try v11.5.0-beta.1? If the issue persists, we would appreciate if you could provide minimum working example to us.
seems like problem reproducable if I change maps style and call
MapEffect(showTraffic) {
it.location.apply {
enabled = true
puckBearingEnabled = true
showAccuracyRing = true
locationPuck = createDefault2DPuck(true)
}
it.mapboxMap.style?.setStyleLayerProperty(
"traffic",
"visibility",
Value.valueOf(if (showTraffic) "visible" else "none")
)
}
I have own style with traffic layer and change it by toggling button. If I don't call setStyleLayerProperty, everything works fine
@Plovotok I tried following sample which sets style layer property but did not observe any crash. If you could provide an example project where this issue is reproducible, we could investigate the issue further. Here is the code where I tried to reproduce the issue (Following example updates changes style and sets visibility of layer that is common for given styles):
import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Refresh
import androidx.compose.material3.FloatingActionButton
import androidx.compose.material3.Icon
import androidx.compose.material3.Scaffold
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import com.mapbox.common.MapboxOptions
import com.mapbox.geojson.Point
import com.mapbox.maps.MapboxExperimental
import com.mapbox.maps.Style
import com.mapbox.maps.coroutine.awaitStyle
import com.mapbox.maps.extension.compose.MapEffect
import com.mapbox.maps.extension.compose.MapboxMap
import com.mapbox.maps.extension.compose.animation.viewport.rememberMapViewportState
import com.mapbox.maps.extension.compose.style.MapStyle
import com.mapbox.maps.extension.compose.style.layers.generated.Visibility
import com.mapbox.maps.plugin.locationcomponent.createDefault2DPuck
import com.mapbox.maps.plugin.locationcomponent.location
@OptIn(MapboxExperimental::class)
class MainActivity : ComponentActivity() {
private val styles = arrayOf(
Style.STANDARD,
Style.LIGHT,
Style.DARK,
Style.MAPBOX_STREETS,
Style.TRAFFIC_DAY,
Style.TRAFFIC_NIGHT,
Style.OUTDOORS,
Style.SATELLITE_STREETS,
)
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
MapboxOptions.accessToken = Constants.MAPBOX_ACCESS_TOKEN
setContent {
var showStyleLayer by remember { mutableStateOf(false) }
var styleIndex by remember { mutableStateOf(0) }
Scaffold(
floatingActionButton = {
FloatingActionButton(onClick = {
showStyleLayer = !showStyleLayer
styleIndex += 1
}) {
Icon(Icons.Filled.Refresh, "Change style")
}
}
) { padding ->
MapboxMap(
Modifier
.fillMaxSize()
.padding(padding),
mapViewportState = rememberMapViewportState {
setCameraOptions {
zoom(9.0)
center(Point.fromLngLat(24.941526986277893, 60.17099952463323))
}
},
style = {
MapStyle(style = styles[styleIndex % styles.size])
}
) {
MapEffect(showStyleLayer) {
it.location.apply {
enabled = true
puckBearingEnabled = true
showAccuracyRing = true
locationPuck = createDefault2DPuck(true)
}
val style = it.mapboxMap.awaitStyle()
val visibility =
if (showStyleLayer) Visibility.VISIBLE.value else Visibility.NONE.value
style.setStyleLayerProperty(
"mapbox-location-indicator-layer",
"visibility",
visibility
)
}
}
}
}
}
}
@jush I've been consistently encountering the same crash logs on Google Play, but the issue has never been reproducible until recently when a user reported it to us and even provided a screen recording of the problem. Whenever this user opens a page that uses the Mapbox map, the app crashes. However, after restarting the phone, the issue no longer occurs.
libc++_shared
in another AAR file, we added a series of configurations such as pickFirst '**/**/libc++_shared.so'
in our packagingOptions. I'm unsure if this has any impact.@CCCCauchy this explains the crashes. All the libraries with native code must be aligned. Mapbox Maps v11 is built with NDK 23. We do not support multiple NDK builds (as of now) so the solution will be try to align another library that's also built with NDK (most likely it's NDK 21 or lower).
@kiryldz May i can downgrade mapbox below v11 to solve this issue?
@CCCCauchy firstly you have to understand what NDK is used for your another 3d party library with C++. If you will confirm it's NDK 21 - our Maps v10 are built with NDK 21 so downgrade will help in that case.
@CCCCauchy firstly you have to understand what NDK is used for your another 3d party library with C++. If you will confirm it's NDK 21 - our Maps v10 are built with NDK 21 so downgrade will help in that case.
After investigating, we found that most of the third-party libraries in our app use NDK lower than 23. Last week, we downgraded Mapbox to V10, and this issue has significantly decreased on Google Play. Thank you for your help.
Environment
Problem
Code