在动态功能模块中无法访问资源文件

问题描述 投票:5回答:2

我正在尝试实现动态交付类型的应用程序。首先,我创建新项目之后,为此创建动态步骤模块

从菜单栏中选择File> New> New Module,然后选择Create New Module对话框,选择Dynamic Feature Module,然后单击Next。 structure of folder

我创建类,并希望访问资源文件夹以使用布局,可绘制文件夹。

也在主模块gradle中实现

实现'com.google.android.play:core:1.2.0'和dynamicFeatures = [“:dynamic_feature”]

但得到动态模块Error display的错误

错误:找不到符号变量activity_main 错误:找不到符号变量iv_forward 错误:找不到符号变量seekBar

https://developer.android.com/studio/projects/dynamic-delivery https://proandroiddev.com/dynamic-feature-module-android-ondemand-module-android-app-bundle-ea0d872b32d

android android-layout app-bundle android-module android-app-bundle
2个回答
0
投票

这个问题看起来像是一个重构相关的导入问题。

将代码移动到其他模块时,请确保

  1. 移动相关的布局资源文件
  2. 更新导入以匹配新包名称

虽然1.并非绝对必要,但优良作法是将非共享布局文件与显示它们的代码段放在同一模块中。


0
投票

对于那些面临同样问题的人:您只能从基础模块获取资源。使用:

com.example.base_module.R.drawable.item

相反,默认R.drawable.item

© www.soinside.com 2019 - 2024. All rights reserved.