Gradle 8 – R 文件合并不再工作?

huangapple go评论55阅读模式
英文:

Gradle 8 - R file merging not working anymore?

问题

在我的项目中,我在核心模块中定义了许多字符串。升级到Gradle 8后,我发现现在需要精确引用R文件。

例如,如果我在核心模块中定义一个字符串,并希望从我的主模块中访问它(主模块当然包括核心模块),我看到以下行为:

之前

我可以通过com.my.package.main.Rcom.my.package.core.R在主模块内访问字符串(以及所有其他资源)。

之后

现在,我只能从精确的模块中访问字符串,所以我需要在主模块内使用com.my.package.core.R来访问核心模块的字符串...

对于来自com.google.android.material.Randroidx.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.

huangapple
  • 本文由 发表于 2023年5月11日 19:03:38
  • 转载请务必保留本文链接:https://go.coder-hub.com/76226923.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定