Android Automotive ARM模拟器:Fused Location Provider API返回无效位置求解决
Android Automotive Sv2 (API 32, arm64-v8a) 模拟器重启后Fused Location Provider API异常解决办法
问题背景
使用Android Studio中唯一支持ARM架构的Automotive OS镜像——Sv2(API 32,arm64-v8a,带Play Store)时,Fused Location Provider API出现异常:
- 模拟器首次启动时API工作正常
- 停止并重新启动(无论冷/热启动)后,发起位置请求会抛出
location must not have realtime in the future异常 - 尝试手动设置系统时间、冷启动模拟器均无法解决问题
异常日志:
2023-01-02 15:17:59.431 1827-2496 FusedLocation com.google.android.gms.persistent E dropping invalid locations [CONTEXT service_id=6 ] vqy: location must not have realtime in the future at vts.i(:com.google.android.gms@220221082@22.02.21 (060408-428111784):34) at vrd.j(:com.google.android.gms@220221082@22.02.21 (060408-428111784):0) at vrr.i(:com.google.android.gms@220221082@22.02.21 (060408-428111784):1) at vrd.j(:com.google.android.gms@220221082@22.02.21 (060408-428111784):0) at vrl.a(:com.google.android.gms@220221082@22.02.21 (060408-428111784):3) at arsp.d(:com.google.android.gms@220221082@22.02.21 (060408-428111784):10) at arvk.i(:com.google.android.gms@220221082@22.02.21 (060408-428111784):18) at arve.a(:com.google.android.gms@220221082@22.02.21 (060408-428111784):0) at vhn.onLocationChanged(:com.google.android.gms@220221082@22.02.21 (060408-428111784):0) at android.location.LocationListener.onLocationChanged(LocationListener.java:63) at android.location.LocationManager$LocationListenerTransport$1.operate(LocationManager.java:3180) at android.location.LocationManager$LocationListenerTransport$1.operate(LocationManager.java:3177) at com.android.internal.listeners.ListenerExecutor.lambda$executeSafely$0(ListenerExecutor.java:127) at com.android.internal.listeners.ListenerExecutor$$ExternalSyntheticLambda0.run(Unknown Source:8) at android.os.Handler.handleCallback(Handler.java:938) at android.os.Handler.dispatchMessage(Handler.java:99) at android.os.Looper.loopOnce(Looper.java:201) at android.os.Looper.loop(Looper.java:288) at android.os.HandlerThread.run(HandlerThread.java:67)
使用的位置请求代码(Kotlin):
val locationCallback = object : LocationCallback() { override fun onLocationResult(result: LocationResult) { Log.d("GoogleLocationApi", "onLocationResult: ${result.locations}") } } val locationRequest = LocationRequest.Builder(2000) .setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY) .setMinUpdateIntervalMillis(1000) .build() val fusedLocationClient: FusedLocationProviderClient = LocationServices.getFusedLocationProviderClient(context) fusedLocationClient.requestLocationUpdates( locationRequest, locationCallback, Looper.getMainLooper() )
可行解决办法
1. 重置Google Play服务位置缓存
进入模拟器设置 > 应用 > 查看所有应用 > Google Play服务 > 存储与缓存 > 清除缓存,随后重启模拟器。该操作会清除位置服务的旧时间戳缓存,避免未来时间校验失败。
2. 强制同步模拟器与主机时间
通过命令行强制同步系统时间,消除时间差问题:
- 打开终端,连接模拟器:
adb connect localhost:5554(端口根据实际模拟器调整) - 同步时间:
adb shell date -s "$(date +%Y%m%d%H%M.%S)" - 重启Google Play服务:
adb shell am force-stop com.google.android.gms
3. 降级Google Play服务版本
当前报错的Play服务版本为22.02.21,可尝试手动安装适配arm64-v8a架构的旧版本APK:
- 下载对应架构的旧版本Google Play服务APK
- 执行覆盖安装:
adb install -r [APK文件路径] - 重启模拟器后测试位置API
4. 切换到原生LocationManager
若上述方法无效,可暂时使用Android原生LocationManager绕过Play服务的时间校验:
val locationManager = getSystemService(Context.LOCATION_SERVICE) as LocationManager val locationListener = object : LocationListener { override fun onLocationChanged(location: Location) { Log.d("NativeLocation", "onLocationChanged: $location") } } // 请求高精度位置更新 locationManager.requestLocationUpdates( LocationManager.GPS_PROVIDER, 1000, 0f, locationListener, Looper.getMainLooper() )
内容的提问来源于stack exchange,提问作者leonbusse
相关产品推荐
相关产品推荐

