You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

flutter_background_geolocation发布模式失效问题求助

问题详情

已严格按照flutter_background_geolocation插件官方文档完成全部配置,调试模式下插件在前台、后台、应用被杀死状态下均能正常运行,但发布模式下杀死应用时出现异常。

发布模式杀死应用时的报错日志

E/FlutterGeolocator(24131): Geolocator position updates stopped
D/FlutterGeolocator(24131): Stopping location service.
D/FlutterLocationService(24131): Unbinding from location service.
D/FlutterLocationService(24131): Destroying service.
E/flutter (24131): [ERROR:flutter/shell/common/shell.cc(93)] Dart Error: Dart_LookupLibrary: library 'package:flutter_background_geolocation/flutter_background_geolocation.dart' not found.
E/flutter (24131): [ERROR:flutter/runtime/dart_isolate.cc(668)] Could not resolve main entrypoint function.
E/flutter (24131): [ERROR:flutter/runtime/dart_isolate.cc(167)] Could not run the run main Dart entrypoint.
E/flutter (24131): [ERROR:flutter/runtime/runtime_controller.cc(385)] Could not create root isolate.
E/flutter (24131): [ERROR:flutter/shell/common/shell.cc(604)] Could not launch engine with configuration.

当前AndroidManifest权限配置

<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.FOREGROUND_SERVICE"/>
解决方案

这个错误是因为发布模式下R8/ProGuard混淆优化时,误将flutter_background_geolocation的核心代码移除了,按以下步骤修复:

  1. 在Android项目的android/app/proguard-rules.pro文件中添加以下规则,保护插件代码不被混淆或移除:
-keep class com.transistorsoft.flutter.backgroundgeolocation.** { *; }
-keep class com.transistorsoft.locationmanager.** { *; }
-dontwarn com.transistorsoft.locationmanager.**
  1. 检查android/app/build.gradle的release构建配置,确保开启混淆并引用了上述规则文件:
buildTypes {
    release {
        // 保留原有签名等配置
        minifyEnabled true
        useProguard true
        proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
    }
}
  1. 重新打包发布版本测试即可。

内容的提问来源于stack exchange,提问作者Sheetal Savani

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.19 01:31:35