Skip to content

进一步兼容 AGP 8.9.0#1417

Open
yanglw wants to merge 1 commit intoTencent:masterfrom
yanglw:master-shrinkResources
Open

进一步兼容 AGP 8.9.0#1417
yanglw wants to merge 1 commit intoTencent:masterfrom
yanglw:master-shrinkResources

Conversation

@yanglw
Copy link

@yanglw yanglw commented Feb 14, 2026

当在 AGP 8.9.0 版本中开启 shrinkResources 功能后,ap_ 文件中的 AndroidManifest.xml 为新的二进制格式,且资源文件引用也不会改为 ID 。新的方案使用合并后的 AndroidManifest.xml 和 R.txt 生成 PluginManifest 文件。

新的方案仅在 AGP 8 以及以上版本中使用。

@shifujun
Copy link
Collaborator

提交日志建议修改为

feat(core.gradle-plugin): 支持AGP 8后开启shrinkResources

当在 AGP 8.9.0 版本中开启 shrinkResources 功能后,ap_ 文件中的 AndroidManifest.xml 为新的二进制格式,且资源文件引用也不会改为 ID 。新的方案使用合并后的 AndroidManifest.xml 和 R.txt 生成 PluginManifest 文件。

新的方案自动应用在 AGP 8 且开启shrinkResources时。

@yanglw yanglw force-pushed the master-shrinkResources branch from 1933b94 to bdd5552 Compare February 15, 2026 06:36
@tencent-adm
Copy link
Member

CLA assistant check
Thank you for your submission, we really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

当在 AGP 8.9.0 版本中开启 shrinkResources 功能后,ap_ 文件中的 AndroidManifest.xml 为新的二进制格式,且资源文件引用也不会改为 ID 。新的方案使用合并后的 AndroidManifest.xml 和 R.txt 生成 PluginManifest 文件。

新的方案自动应用在 AGP 8 且开启shrinkResources时。
@yanglw yanglw force-pushed the master-shrinkResources branch from bdd5552 to 1a87351 Compare February 15, 2026 06:39
@yanglw
Copy link
Author

yanglw commented Feb 15, 2026

提交日志建议修改为

feat(core.gradle-plugin): 支持AGP 8后开启shrinkResources

当在 AGP 8.9.0 版本中开启 shrinkResources 功能后,ap_ 文件中的 AndroidManifest.xml 为新的二进制格式,且资源文件引用也不会改为 ID 。新的方案使用合并后的 AndroidManifest.xml 和 R.txt 生成 PluginManifest 文件。

新的方案自动应用在 AGP 8 且开启shrinkResources时。

OK

* @param rTxt R.txt文件
* @return 资源映射器
*/
fun createResourceMapper(rTxt: File): (String) -> String {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个mapper后面用了多处,应该定义一个typealias

createPackagePluginTasks(project)

addLocateApkanalyzerTask(project)
if (agpCompat.hasDeprecatedTransformApi()) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个分支条件直接复用了transformAPI版本的判断,应该是巧合吧?这样以后可能就看不懂了。还是专门定一个判断接口吧,即便实现是一样的也没关系。

Comment on lines 232 to 248
val func :()-> TaskProvider<Task?>? = if (agpCompat.hasDeprecatedTransformApi()) {
{
createGeneratePluginManifestTaskOld(project, pluginVariant, pluginManifestSourceDir)
}
} else {
{
createGeneratePluginManifestTaskNew(project, pluginVariant, pluginManifestSourceDir)
}
}
val generatePluginManifestTask = func.invoke()
javacTask.dependsOn(generatePluginManifestTask)

// 把PluginManifest.java添加为源码
val relativePath =
project.projectDir.toPath().relativize(pluginManifestSourceDir.toPath()).toString()
(javacTask as JavaCompile).source(project.fileTree(relativePath))
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这段对createGeneratePluginManifestTasks方法内部的改造我看懂了。不过这段代码的修改还是太多了,而且包含很多旧代码的位置调整。这很不利于blame回溯代码。

这里最好把分支逻辑改到调用createGeneratePluginManifestTasks的地方去。就加一个if判断,然后使旧代码尽可能保持不变。新增的行多一些和旧代码重复的关系不大。因为我们不太需要同时维护这两份代码的修改。更重视保持旧的代码稳定,尽可能少的改动。

createPackagePluginTasks(project)

addLocateApkanalyzerTask(project)
if (agpCompat.hasDeprecatedTransformApi()) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

当在 AGP 8.9.0 版本中开启 shrinkResources 功能后,ap_ 文件中的 AndroidManifest.xml 为新的二进制格式

你这里复用的判断条件似乎没有对shrinkResources是否开启作判断。从你的描述来看,我们应该只对同时符合AGP版本和shrinkResources开启的场景使用这个新的功能。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

Comments