启用 Proguard 时 Mapbox 的 LocationLayerPlugin 不更新位置

Mapbox's LocationLayerPlugin not updating location when Proguard is enabled

我正在使用启用了 Proguard 的 Mapbox LocationLayerPlugin v0.6.0。

在发布版本中,位置层不请求位置更新:在前台时没有 GPS 使用图标,并且位置在第一次启动后几秒钟变得陈旧并且永远不会更新。我在不提供 LocationEngine 的情况下使用 public LocationLayerPlugin(MapView mapView, MapboxMap mapboxMap).

构建插件

它不会发生在调试版本中(没有 Proguard)或者如果我在发布版本中明确禁用 Proguard (minifyEnabled=false)。 proguard-rules.pro 文件没有针对 Mapbox(SDK 和插件)的任何特定规则,我尝试添加来自 https://github.com/mapbox/mapbox-plugins-android/blob/master/app/proguard-rules.pro 的规则,但问题仍然存在。

是否还有其他规则要添加?我在文档中找不到任何内容。

如果您正在使用google播放位置服务,并且GoogleLocationEngine,您可以尝试添加

-keep class com.google.android.gms.** { *; }
-dontwarn com.google.android.gms.**

到您的 proguard-rules.pro 文件。

我能够重现该问题并且以上设置有所帮助。

但是,如果您只使用 AndroidLocationEngine 该引擎最近出现了一些问题,您可以关注 issue tracker 以获取更多信息。

有关更多上下文,如果您不手动将 google 播放位置服务依赖项添加到您的项目中,default constructor 使用的 LocationEngineProvider#obtainBestLocationEngineAvailable 将 return AndroidLocationEngine,否则会return GoogleLocationEngine.