Skip to content

fix(android): 适配 Flutter 3.29+,用 FlutterLoader 替换已移除的 FlutterMain#2261

Open
xianjianlf2 wants to merge 1 commit into
alibaba:mainfrom
xianjianlf2:fix/flutter-3.29-flutterloader
Open

fix(android): 适配 Flutter 3.29+,用 FlutterLoader 替换已移除的 FlutterMain#2261
xianjianlf2 wants to merge 1 commit into
alibaba:mainfrom
xianjianlf2:fix/flutter-3.29-flutterloader

Conversation

@xianjianlf2

Copy link
Copy Markdown

问题

io.flutter.view.FlutterMain 在 Flutter 3.29 已被移除(3.x 期间一直 deprecated),导致升级到 3.29+ 的用户 Android 编译失败:cannot find symbol: FlutterMain。对应 #2222#2217

改动

全仓库仅 FlutterBoost.java 一处用到该 API,替换为官方等价写法:

  • import io.flutter.view.FlutterMainimport io.flutter.FlutterInjector
  • FlutterMain.findAppBundlePath()FlutterInjector.instance().flutterLoader().findAppBundlePath()

两者返回值均为 String;调用点在 new FlutterEngine(...) 之后,FlutterLoader 已初始化,调用安全。

兼容性

FlutterInjector 自 Flutter 1.20 起即存在,远早于本包要求的最低版本 3.0.0,低版本用户不受影响,无需版本分支或反射。

验证

对照真实 Flutter 3.32.0 引擎产物(flutter_embedding,engine hash 18818009…)用 javac 核验:

  • 旧写法 import io.flutter.view.FlutterMain → 编译失败(找不到符号),复现该 bug
  • 新写法整条调用链 → 编译通过,String 正确传入 DartExecutor.DartEntrypoint(String, String)

注:本仓库 Android 侧无单测基建,该改动为编译期类型等价的官方 API 迁移,故未新增测试。

Closes #2222
Closes #2217

`io.flutter.view.FlutterMain` was removed in Flutter 3.29 (deprecated
throughout 3.x), which breaks the Android build with "cannot find
symbol: FlutterMain" for everyone on Flutter 3.29+.

Replace the only usage with the official replacement
`FlutterInjector.instance().flutterLoader().findAppBundlePath()`. It
returns the same String and has existed since Flutter 1.20, so the
change stays backward compatible with this package's min SDK (3.0.0).
At the call site the engine is already constructed, so the loader is
guaranteed initialized.

Closes alibaba#2222
Closes alibaba#2217

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@CLAassistant

CLAassistant commented Jun 26, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: FlutterBoost 文件中 FlutterMain 找不到!!!! [featurePR]: flutter_boost 适配 flutter 3.32

2 participants