Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

[R8] Aapt2 rules are silently dropped from R8 input

未关闭
#12,942 3 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
4/5
预计耗时
3-5 天
新手友好度
48/100
Issue 类型
缺陷
描述清晰度
基本清楚
活跃度
活跃
技术栈
android, csharp

调研方向

Start by tracing ProguardRuleOutput handling in src/Xamarin.Android.Build.Tasks/Tasks/Aapt2Link.cs around line 134, then inspect _UseAapt2ManifestProguardRules in src/Xamarin.Android.Build.Tasks/MSBuild/Xamarin/Android/Xamarin.Android.Aapt2.targets around lines 247-250. Reproduce or instrument the multi-project R8 build and verify that generated aapt_rules.txt is consistently added to ProguardConfiguration and passed to R8.

由索引模型根据 Issue 内容生成。

描述

Area: App+Library Build need-info
Android framework version

net10.0-android

Affected platform version

.NET 10.0.200

Description

Environment:

  • Android application with the multi-project solution;
  • AndroidLinkTool=r8
  • TrimMode=full

We are currently testing enabling full Android linking with tree-shaking. We noticed that sometimes builds compiled on CI are "broken" - crashing on startup with ClassNotFoundException. We ruled out environmental cause as there's no correlation between issue reproduction and build agents, all CI builds are "clean".
After analyzing the R8 outputs from broken builds (collected via --pg-conf-output extra argument) we found the root cause: broken builds (~4% of total) are all missing the section with generated Aapt2 rules (from aapt_rules.txt).

We managed to reproduce the issue with the additional binlog enabled, it shows the following picture:

  • _Aapt2ProguardRules is resolved into a relative path like obj/<Platform>/<Configuration>/net10.0-android36.0/aapt_rules.txt;
  • Aapt2Link task runs and competes successfully (JobWorked: True);
  • generated rules file is never added to the ProguardConfiguration - there's no Added Item(s): ProguardConfiguration=obj/.../aapt_rules.txt log;
  • aapt_rules.txt never passed to the R8, classes defined in manifest trimmed;

The issue might be caused by the Aapt2Link task operating on a relative path with incorrect captured WorkingDirectory:
https://github.com/dotnet/android/blob/7a170b185aa8e78fc18908834ada19b578668d39/src/Xamarin.Android.Build.Tasks/Tasks/Aapt2Link.cs#L134
Unlike other path variables, ProguardRuleOutput is never used with GetFullPath(), which may cause aapt_rules.txt being generated in the incorrect project. The Exists() guard then will skip adding this file to ProguardConfiguration not producing any errors
https://github.com/dotnet/android/blob/085b6f4e80f9812c3e9bb509c9b2a8a19de17d36/src/Xamarin.Android.Build.Tasks/MSBuild/Xamarin/Android/Xamarin.Android.Aapt2.targets#L247-L250

Steps to Reproduce

There are no 100% reproduction steps, the issue seems to reproduce randomly with environment described above.

Did you find any workaround?

It seems that the issue is only with the merged aapt_rules.txt, individual manifest rules per ABI are using full paths - and thus should always land in the root project. It should be possible to include those files into ProguardConfiguration directly:

<Target Name="_UseAapt2ManifestProguardRules"
        Condition="'$(AndroidLinkTool)' != ''"
        BeforeTargets="_CalculateProguardConfigurationFiles">
  <ItemGroup>
    <_Aapt2ManifestProguardRules Include="$(MSBuildProjectDirectory)/$(IntermediateOutputPath)android/*/aapt_rules.txt" />
    <ProguardConfiguration Include="@(_Aapt2ManifestProguardRules)" />
  </ItemGroup>
</Target>

Another option might be using, but we didn't test it yet

<YieldDuringToolExecution>false</YieldDuringToolExecution>
Relevant log output

主要语言
C#
星标
2.1k
派生
581
平均合并
2 天 2 小时
30 天内合并 PR
228

环境准备

  • 没有 Dockerfile 或 Docker Compose 文件
  • 有 Pull Request 模板
  • 没有贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

dotnet/android 的其他 Issue

查看 dotnet/android 的全部 Issue

相似的 Issue

更多 C# Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。