当前位置: 首页 > 知识库问答 >
问题:

Android : A/libc: 致命信号 11 (SIGSEGV), 代码 1, 故障加法器 0x8 在 tid 18372

沈华晖
2023-03-14

我正在使用mapbox sdk测试一个应用程序,而不是mapbox的位置引擎提供程序,我使用此链接创建了一个名为“GoogleLocationEngine”的类,以跟踪用户位置(Google API):https://github.com/mapbox/mapbox-android-demo/issues/449

但应用程序给了我这个错误(通常是在后台):

A/libc: Fatal signal 11 (SIGSEGV), code 1, fault addr 0x8 in tid 18372

虽然当我使用mapbox sdk时:

LocationEngineProvider(context).obtainBestLocationEngineAvailable() 

方法,错误仍然出现,我不知道如何跟踪它,那么我该如何解决这个问题?我的设备是三星Galaxy Note 4(SM-N900C),这是我的MainActivity.java:

import android.location.Location;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.widget.Toast;

import com.google.android.gms.location.LocationCallback;
import com.google.android.gms.location.LocationResult;
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.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.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 MainActivity extends AppCompatActivity implements
    LocationEngineListener,
    PermissionsListener{

private MapView mapView;
private MapboxMap map;
private PermissionsManager permissionsManager;
private LocationEngine locationEngine;
private Location originLocation;


@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Mapbox.getInstance(this, getString(R.string.access_token));
    setContentView(R.layout.activity_main);
    mapView = findViewById(R.id.mapView);
    mapView.onCreate(savedInstanceState);
    mapView.getMapAsync(mapboxMap -> {
        map = mapboxMap;
        enableLocation();
    });

}

private void enableLocation(){

    if(PermissionsManager.areLocationPermissionsGranted(this)){

        initializeLocationEngine();
        initializeLocationLayer();

    } else {
        permissionsManager = new PermissionsManager(this);
        permissionsManager.requestLocationPermissions(this);
    }
}

@SuppressWarnings("MissingPermission")
private void initializeLocationEngine(){
    locationEngine = GoogleLocationEngine.getLocationEngine(this);
    locationEngine.setPriority(LocationEnginePriority.HIGH_ACCURACY);
    locationEngine.activate();

    Location lastLocation = locationEngine.getLastLocation();

    if(lastLocation != null){
        originLocation = lastLocation;
        setCameraPosition(lastLocation);
    } else {
        locationEngine.addLocationEngineListener(this);
    }
}

@SuppressWarnings("MissingPermission")
private void initializeLocationLayer(){
    LocationLayerPlugin 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));
}

@SuppressWarnings("MissingPermission")
@Override
public void onConnected() {
    Log.d("onConnected" , "is Connected");
    locationEngine.requestLocationUpdates();
}

@Override
public void onLocationChanged(Location location) {
    if(location != null){
        originLocation = location;
        setCameraPosition(location);
    } else
        Toast.makeText(this, "Location is null", Toast.LENGTH_SHORT).show();
}

@Override
public void onExplanationNeeded(List<String> permissionsToExplain) {
    //present a toast or a dialog
    Toast.makeText(this, permissionsToExplain.get(0) , Toast.LENGTH_SHORT).show();
}

@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
public void onStart() {
    super.onStart();
    mapView.onStart();
}

@Override
public void onResume() {
    super.onResume();
    mapView.onResume();
}

@Override
public void onPause() {
    super.onPause();
    mapView.onPause();
}

@Override
public void onStop() {
    super.onStop();
    mapView.onStop();
}

@Override
public void onLowMemory() {
    super.onLowMemory();
    mapView.onLowMemory();
}

@Override
protected void onDestroy() {
    super.onDestroy();
    mapView.onDestroy();
}

@Override
protected void onSaveInstanceState(Bundle outState) {
    super.onSaveInstanceState(outState);
    mapView.onSaveInstanceState(outState);
    }

}

更新:最近我意识到这种方法

locationEngine = new LocationEngineProvider(this).obtainBestLocationEngineAvailable();

不起作用!我认为这种方法对我有用,但当我对它进行评论并再次测试我的应用程序时,它没有显示我的位置,当我使用我的GoogleLocationEngine类时,它有效,但仍然存在相同的错误。亲爱的朋友们,有什么想法吗?

共有1个答案

韩楷
2023-03-14

问题已经解决了!根据本段:

在各自的活动方法中包含位置层 onStart() 和 onStop() 生命周期事件非常重要。这可以防止发生内存泄漏并减少电池消耗。该插件支持新的生命周期观察者API,通过将插件添加为活动中的生命周期观察者,您无需手动处理生命周期。

源链接:mapbox_locationLayer

还有这个mapboxDemo _ locationlayerpluginitivity . Java(GitHub),我应该在我的函数中使用这些方法:

    locationPlugin = new LocationLayerPlugin(mapView, mapboxMap, locationEngine);
    locationPlugin.setLocationLayerEnabled(true);
    locationPlugin.setCameraMode(CameraMode.TRACKING);
    locationPlugin.setRenderMode(RenderMode.COMPASS);
    Lifecycle lifecycle = getLifecycle();
    lifecycle.addObserver(locationPlugin);

在我的onStart()中:

@Override
public void onStart() {
    super.onStart();
    mapView.onStart();
    if(locationEngine != null){
        locationEngine.requestLocationUpdates();
        locationEngine.addLocationEngineListener(this);
    }
}

也在我的 onStop() 中:

@Override
public void onStop() {
    super.onStop();
    mapView.onStop();
    if(locationEngine != null){
        locationEngine.removeLocationEngineListener(this);
        locationEngine.removeLocationUpdates();
    }
}

然后致命信号错误现在消失了。

我必须说谢谢你mapbox支持团队支持我并解决这个问题。

 类似资料: