英文:
Gradle 8 - R file merging not working anymore?
问题
在我的项目中,我在核心模块中定义了许多字符串。升级到Gradle 8后,我发现现在需要精确引用R文件。
例如,如果我在核心模块中定义一个字符串,并希望从我的主模块中访问它(主模块当然包括核心模块),我看到以下行为:
之前
我可以通过com.my.package.main.R
和com.my.package.core.R
在主模块内访问字符串(以及所有其他资源)。
之后
现在,我只能从精确的模块中访问字符串,所以我需要在主模块内使用com.my.package.core.R
来访问核心模块的字符串...
对于来自com.google.android.material.R
和androidx.appcompat
的属性也是一样的...
我是否漏掉了迁移步骤?或者这确实应该是这样的吗?
英文:
In my project I have defined many strings inside a core module. After upgrading to gradle 8 I see that I need to reference R files exactly now.
E.g. if I define a string inside my core module and want to access it from my main module (the main module includes the core module of course) I see following behaviour:
Before
I could access strings (and all other resources) from the core module inside the main module via com.my.package.main.R
and com.my.package.core.R
After
Now I can only access the strings from the exact module anymore so I need to use com.my.package.core.R
inside my main module to access strings from the core module...
The same happens for attributes from com.google.android.material.R
and androidx.appcompat
...
Did I miss a migration step? Or should this really be like that?
答案1
得分: 11
AGP 8 默认行为已更改:
请参见 https://developer.android.com/build/releases/gradle-plugin 中的选项 android.nonTransitiveRClass
android.nonTransitiveRClass
新默认值:true 旧默认值:false
AGP 8.0 仅为当前模块中定义的资源生成 R 类。
英文:
With AGP 8 the default behaviour did change:
See the option android.nonTransitiveRClass
in
https://developer.android.com/build/releases/gradle-plugin
android.nonTransitiveRClass
New default: true Old default: false
AGP 8.0 generates R classes for resources defined in the current module only.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论