将 PluginContainerActivity 改为继承 FragmentActivity 时遇到的类加载问题
还没有人认领这个 Issue。
评估
调研方向
Start with ActivityCodeGenerator.kt and trace how GeneratedPluginContainerActivity is generated and loaded by the plugin runtime. Then inspect the runtime class loading and dependency handling for AndroidX Fragment and Lifecycle, including the FragmentActivity stubs and key event dispatch changes described in the issue. The issue is done when the inheritance change works in a real host and plugin setup without class resolution or Lifecycle access failures; it does not identify a specific test or provide a settled implementation route.
由索引模型根据 Issue 内容生成。
描述
背景
我们有一个需求:宿主会传递一个 WebView 给插件使用,WebView 有时需要启动 Dialog。Dialog 需要 FragmentActivity 或 AppCompatActivity 作为 Context,而当前 PluginContainerActivity 继承自普通 Activity,导致 Dialog 无法正常弹出。
因此我尝试将 PluginContainerActivity 改为继承 FragmentActivity。
已完成的修改
- 修改
ActivityCodeGenerator.kt,将GeneratedPluginContainerActivity的父类从Activity改为FragmentActivity - 添加
FragmentActivitystub 类用于编译 - 处理
ComponentActivity的 final 方法(如onRetainNonConfigurationInstance) - 解决
KeyEventDispatcher导致的无限递归问题(覆写superDispatchKeyEvent)
遇到的问题
在 sample 项目中测试正常,但在实际项目中遇到以下问题:
问题 1:使用 compileOnly 依赖时类找不到
在 plugin-runtime 中使用 compileOnly 'androidx.fragment:fragment:1.4.1',加载插件时报错:
Failed resolution of: Lcom/tencent/shadow/core/runtime/container/PluginContainerActivity;
问题 2:使用 implementation 依赖时方法不可访问
改为 implementation 'androidx.fragment:fragment:1.4.1' 后,启动时崩溃:
Method 'androidx.lifecycle.LifecycleEventObserver androidx.lifecycle.Lifecycling.lifecycleEventObserver(java.lang.Object)' is inaccessible to class 'androidx.lifecycle.LifecycleRegistry$ObserverWithState' (declaration of 'androidx.lifecycle.LifecycleRegistry$ObserverWithState' appears in /data/app/~~ZsI_dEdXQCfBzCzBCwZ9fg==/com.netease.gl-T_n2e4Q6M7HhQCr2S2jokw==/base.apk)
at androidx.lifecycle.LifecycleRegistry$ObserverWithState.<init>(LifecycleRegistry.java:353)
at androidx.lifecycle.LifecycleRegistry.addObserver(LifecycleRegistry.java:180)
这个错误看起来是宿主和插件的 androidx.lifecycle 类存在版本冲突或类加载器隔离问题。
问题
- 我的修改方向是否有问题?作者能给一个大概要修改的类的路线吗?
- 如果要让
PluginContainerActivity继承FragmentActivity,在 Shadow 框架中还有需要注意哪些地方?
环境信息
- Shadow 版本:基于 2024-12-25 的 master 分支(commit 09e7e0a6)
- androidx.fragment 版本:1.4.1
- 主要语言
- Java
- 星标
- 7.8k
- 派生
- 1.3k
- PR 合并指标
- 30 天内没有已合并 PR
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 没有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
Tencent/Shadow 的其他 Issue
-
难度 4/5 3-5 天 新手友好度 25/100
-
有AGP9的支持计划吗未关闭
难度 4/5 3-5 天 新手友好度 35/100
-
难度 5/5 一周以上 新手友好度 25/100
-
难度 1/5 1 小时以内 新手友好度 35/100
-
AGP 9支持有计划吗?未关闭
难度 5/5 一周以上 新手友好度 15/100
相似的 Issue
-
area:cpan-port area:performance bug
难度 2/5 1-3 小时 新手友好度 72/100
fglock/PerlOnJava#2230 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 76/100
-
难度 2/5 1-3 小时 新手友好度 82/100
federicoiosue/Omni-Notes#1044 ·
-
Bug
难度 1/5 1 小时以内 新手友好度 68/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 82/100
维护者通常 1 天内回复