动态功能:从动态功能模块访问可绘制库
我正在尝试从我的 :wrapped
模块(也是常规的 android 库模块)访问 :library
模块(常规的 android 库模块)中的资源。
复杂的因素是我创建了一个 :dynamicFeatureWrapper
模块,它导入 plugin id: 'com.android.dynamic-feature'
,因此充当动态功能模块,但实际上,我的动态功能的实际内容位于 :wrapped
中,
:dynamicFeatureWrapper (imports the plugin id: 'com.android.dynamic-feature')
| |
| api |impl
v v
:wrapped :baseApp
|
|api
v
:library
我首先像安装任何动态功能模块一样安装 :dynamicFeatureWrapper
,然后从我的:wrapped
模块,我尝试访问 :library
中的可绘制资源。但是,当我尝试像这样访问它时,我得到 ResourceNotFound
:
// in :wrapped module
LocalContext.current.applicationContext.resources.getIdentifier(
"my_icon",
"drawable",
"com.example.myapp.library"
这会导致以下崩溃:
2022-04-07 14:13:41.516 2114-2114/com.example.myapp E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.myapp, PID: 2114
java.lang.NoSuchFieldError: No static field my_icon of type I in class
Lcom/example/myapp/library/R$drawable; or its superclasses (declaration of
'com.example.myapp.library.R$drawable' appears in /data/user/0/com.example.myapp/files/splitcompat/6057000/verified-splits/dynamicFeatureWrapper.apk!classes4.dex)
I am trying to access a resource that lives in :library
module (a regular android library module), from my :wrapped
module, also a regular android library module.
The complicating factor is that I created a :dynamicFeatureWrapper
module, which imports the plugin id: 'com.android.dynamic-feature'
, and therefore serves as the dynamic feature module, but really, the actual content of my dynamic feature is in :wrapped
:dynamicFeatureWrapper (imports the plugin id: 'com.android.dynamic-feature')
| |
| api |impl
v v
:wrapped :baseApp
|
|api
v
:library
I first install the :dynamicFeatureWrapper
as I would any dynamic feature module, and then from my :wrapped
module, I try to access a drawable resource in :library
. However, when I try to access it like this, I get ResourceNotFound
:
// in :wrapped module
LocalContext.current.applicationContext.resources.getIdentifier(
"my_icon",
"drawable",
"com.example.myapp.library"
This results in the following crash:
2022-04-07 14:13:41.516 2114-2114/com.example.myapp E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.myapp, PID: 2114
java.lang.NoSuchFieldError: No static field my_icon of type I in class
Lcom/example/myapp/library/R$drawable; or its superclasses (declaration of
'com.example.myapp.library.R$drawable' appears in /data/user/0/com.example.myapp/files/splitcompat/6057000/verified-splits/dynamicFeatureWrapper.apk!classes4.dex)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
弄清楚如何从位于
:wrapped
中的 Compose 代码访问位于:library
中的资源:Figured out how to access my resource that lives in
:library
from my Compose code that lives in:wrapped
: