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

Flutter Upgrader插件失效:Play Store无法匹配应用ID及强制更新问题

解决Upgrader插件在Google Play测试阶段无法检测应用的问题

问题根源

Google Play内部/封闭测试阶段的应用信息不会对外公开,Upgrader默认依赖的Play Store公开API无法抓取到应用的版本数据,因此会抛出“Can't find an app in the Play Store with the id”的错误。

解决方案

针对测试阶段的强制更新需求,推荐以下两种可行方案:

1. 本地硬编码强制更新规则

直接跳过Play Store的远程检查,手动设置最低要求版本并禁用跳过/稍后按钮,完全满足强制更新的需求。

示例代码:

import 'package:package_info_plus/package_info_plus.dart';
import 'package:upgrader/upgrader.dart';

class MyApp extends StatefulWidget {
  @override
  State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  late PackageInfo _packageInfo;

  @override
  void initState() {
    super.initState();
    _initPackageInfo();
  }

  Future<void> _initPackageInfo() async {
    final info = await PackageInfo.fromPackageInfo();
    setState(() => _packageInfo = info);
  }

  @override
  Widget build(BuildContext context) {
    if (!mounted) return const SizedBox();

    final upgrader = Upgrader(
      configuration: UpgraderConfiguration(
        // 设置强制更新的最低版本
        minimumAppVersion: '1.1.0',
        // 禁用忽略和稍后按钮
        showIgnore: false,
        showLater: false,
        // 跳过远程Appcast检查,使用本地配置
        appcastConfig: AppcastConfiguration(url: ''),
      ),
    );

    return UpgradeAlert(
      upgrader: upgrader,
      child: Scaffold(
        appBar: AppBar(title: const Text('My App')),
        body: const Center(child: Text('App Content')),
      ),
    );
  }
}

2. 自定义Appcast版本源

如果需要更灵活的版本控制(比如后续调整强制更新规则无需发版),可以自己搭建一个公开可访问的Appcast XML文件,让Upgrader从该地址拉取版本信息。

首先创建一个appcast.xml文件:

<rss version="2.0" xmlns:sparkle="http://www.andymatuschak.org/xml-namespaces/sparkle">
  <channel>
    <item>
      <title>版本 1.1.0</title>
      <description>修复已知问题,新增核心功能</description>
      <pubDate>2024-05-20T14:00:00Z</pubDate>
      <enclosure 
        url="https://play.google.com/store/apps/details?id=com.your.package.id" 
        sparkle:version="1.1.0" 
        sparkle:shortVersionString="1.1.0" 
      />
    </item>
  </channel>
</rss>

然后修改Upgrader配置,指定自定义Appcast地址:

final upgrader = Upgrader(
  configuration: UpgraderConfiguration(
    showIgnore: false,
    showLater: false,
    appcastConfig: AppcastConfiguration(url: 'https://your-server.com/appcast.xml'),
  ),
);

调试与验证

  • 确认当前应用的包名和版本号与Google Play控制台一致,可通过以下代码打印:
    final info = await PackageInfo.fromPackageInfo();
    print('包名: ${info.packageName}');
    print('当前版本: ${info.version}');
    
  • 转为封闭测试后,若仍无法通过Play Store检测版本,可继续使用上述方案,直到应用正式发布后再切换回默认的Play Store检查逻辑。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.14 02:52:22