[R8] Aapt2 rules are silently dropped from R8 input
Maintainer thường phản hồi trong vòng 1 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức phù hợp với người mới
- 48/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Khá rõ ràng
- Mức độ hoạt động
- Sôi nổi
- Công nghệ
- android, csharp
- Lĩnh vực
- build-system, mobile-dev
Hướng nghiên cứu
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.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Android framework version
net10.0-android
Affected platform version
.NET 10.0.200
Description
Environment:
- Android application with the multi-project solution;
AndroidLinkTool=r8TrimMode=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:
_Aapt2ProguardRulesis resolved into a relative path likeobj/<Platform>/<Configuration>/net10.0-android36.0/aapt_rules.txt;Aapt2Linktask runs and competes successfully (JobWorked: True);- generated rules file is never added to the
ProguardConfiguration- there's noAdded Item(s): ProguardConfiguration=obj/.../aapt_rules.txtlog; aapt_rules.txtnever 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
- Ngôn ngữ chính
- C#
- Star
- 2.1k
- Fork
- 581
- Merge trung bình
- 2 ngày 31 phút
- Pull request đã merge (30 ngày)
- 223
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Không có hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của dotnet/android
-
Area: App+Library Build
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Area: Debugger enhancement needs-triage
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 85/100
Maintainer thường phản hồi trong vòng 1 ngày
-
EditText.getText() isn't boundĐang mởArea: Mono.Android
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 65/100
dotnet/android#9192 · 4 bình luận · 1 reaction ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Area: CoreCLR Area: NativeAOT needs-triage
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 30/100
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của dotnet/android
Issue tương tự
-
bug P3
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 88/100
nightscout/nocturne#1908 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
bug documentation Needs: Triage :mag:
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
-
WPF: each page's `Title` overwrites the window title, and returning to a page does not restore itĐang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
Maintainer thường phản hồi trong vòng 1 ngày
-
agentic-workflows area/Docs partner/agentic-workflows
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 82/100
Maintainer thường phản hồi trong vòng 1 ngày
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
jamesmontemagno/tiny-clips#378 · 2 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày