Commit 9e6ce03
authored
[Xamarin.Android.Build.Tasks] Add $(AndroidLinkResources) (#5317)
The generated `Resource` class in `Resource.designer.cs` can be quite
large.
When doing "Release" builds, update the linker to *remove* the
`Resource` class and its nested types. We do this by examining all
the locations where the fields are used and replacing those IL calls
with a call which specifies the actual resource id value directly.
This will remove the need to call
`global::Android.Runtime.ResourceIdManager.UpdateIdValues();` from
the static constructors in the `Resource` class and its nested types,
which will improve app launch times (as `UpdateIdValues()` involves
Reflection, which is not "fast").
Due to an odd linker failure we cannot completely remove the
`Resource` class itself. It *will* be completely empty.
"Debug" builds will *not* remove the `Resource` type, and will retain
the call to `UpdateIdValues()`, in order to ensure that app rebuild
and redeploy times are as fast as possible.
The new `$(AndroidLinkResources)` MSBuild property has been added to
control this feature. It is disabled by default for now.
`$(AndroidLinkResources)`=True appears to save between 100-280kb for
an `.apk`. This is dependent on how many assemblies are Android
assemblies and contain or use Resources.
Xamarin.Forms base app `apkdiff` results
Size difference in bytes ([*1] apk1 only, [*2] apk2 only):
- 10 assemblies/Mono.Android.dll
- 4,001 assemblies/Xamarin.Essentials.dll
- 45,426 assemblies/Xamarin.Forms.Platform.Android.dll
- 102,839 assemblies/formstest.Android.dll
Summary:
+ 0 Other entries 0.00% (of 887,808)
+ 0 Dalvik executables 0.00% (of 3,341,152)
- 152,276 Assemblies -3.23% (of 4,709,077)
+ 0 Shared libraries 0.00% (of 41,693,796)
- 151,552 Package size difference -0.73% (of 20,820,695)
Maps sample `apkdiff` results
Size difference in bytes ([*1] apk1 only, [*2] apk2 only):
- 4 lib/armeabi-v7a/libxamarin-app.so
- 14 assemblies/Mono.Android.dll
- 4,757 assemblies/Xamarin.Essentials.dll
- 46,051 assemblies/Xamarin.Forms.Platform.dll
- 47,586 assemblies/Xamarin.Forms.Platform.Android.dll
- 48,470 assemblies/Xamarin.Forms.Maps.Android.dll
- 135,589 assemblies/FormsMapsSample.Android.dll
Summary:
+ 0 Other entries 0.00% (of 1,137,209)
+ 0 Dalvik executables 0.00% (of 2,519,972)
- 282,467 Assemblies -5.51% (of 5,123,833)
- 4 Shared libraries -0.00% (of 41,843,596)
- 282,624 Package size difference -1.34% (of 21,075,664)1 parent 905878b commit 9e6ce03
File tree
14 files changed
+377
-41
lines changed- Documentation/guides/building-apps
- src
- Microsoft.Android.Sdk.ILLink
- Xamarin.Android.Build.Tasks
- Linker/MonoDroid.Tuner
- Microsoft.Android.Sdk/targets
- Tasks
- Tests/Xamarin.Android.Build.Tests/Tasks
14 files changed
+377
-41
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
696 | 696 | | |
697 | 697 | | |
698 | 698 | | |
| 699 | + | |
| 700 | + | |
| 701 | + | |
| 702 | + | |
| 703 | + | |
| 704 | + | |
| 705 | + | |
| 706 | + | |
| 707 | + | |
| 708 | + | |
| 709 | + | |
| 710 | + | |
| 711 | + | |
| 712 | + | |
| 713 | + | |
| 714 | + | |
| 715 | + | |
| 716 | + | |
| 717 | + | |
| 718 | + | |
| 719 | + | |
699 | 720 | | |
700 | 721 | | |
701 | 722 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
65 | 65 | | |
66 | 66 | | |
67 | 67 | | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
68 | 73 | | |
69 | 74 | | |
70 | 75 | | |
| |||
Lines changed: 27 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
Lines changed: 35 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
| 5 | + | |
5 | 6 | | |
6 | 7 | | |
7 | 8 | | |
| |||
327 | 328 | | |
328 | 329 | | |
329 | 330 | | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
330 | 365 | | |
331 | 366 | | |
Lines changed: 28 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
Lines changed: 6 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
77 | 77 | | |
78 | 78 | | |
79 | 79 | | |
80 | | - | |
| 80 | + | |
81 | 81 | | |
82 | 82 | | |
83 | 83 | | |
| |||
121 | 121 | | |
122 | 122 | | |
123 | 123 | | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
124 | 129 | | |
125 | 130 | | |
126 | 131 | | |
| |||
Lines changed: 1 addition & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
25 | 25 | | |
26 | 26 | | |
27 | 27 | | |
| 28 | + | |
28 | 29 | | |
29 | 30 | | |
Lines changed: 5 additions & 39 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
188 | 188 | | |
189 | 189 | | |
190 | 190 | | |
191 | | - | |
| 191 | + | |
192 | 192 | | |
193 | 193 | | |
194 | 194 | | |
| |||
197 | 197 | | |
198 | 198 | | |
199 | 199 | | |
200 | | - | |
| 200 | + | |
201 | 201 | | |
202 | 202 | | |
203 | 203 | | |
| |||
265 | 265 | | |
266 | 266 | | |
267 | 267 | | |
268 | | - | |
269 | | - | |
270 | | - | |
271 | | - | |
272 | | - | |
273 | | - | |
274 | | - | |
275 | | - | |
276 | | - | |
277 | | - | |
278 | | - | |
279 | | - | |
280 | | - | |
281 | | - | |
282 | | - | |
283 | | - | |
284 | | - | |
285 | | - | |
286 | | - | |
287 | | - | |
288 | | - | |
289 | | - | |
290 | | - | |
291 | | - | |
292 | | - | |
293 | | - | |
294 | | - | |
295 | | - | |
296 | | - | |
297 | | - | |
298 | | - | |
299 | | - | |
300 | | - | |
301 | | - | |
302 | 268 | | |
303 | 269 | | |
304 | 270 | | |
| |||
310 | 276 | | |
311 | 277 | | |
312 | 278 | | |
313 | | - | |
| 279 | + | |
314 | 280 | | |
315 | 281 | | |
316 | 282 | | |
| |||
351 | 317 | | |
352 | 318 | | |
353 | 319 | | |
354 | | - | |
| 320 | + | |
355 | 321 | | |
356 | 322 | | |
357 | 323 | | |
| |||
436 | 402 | | |
437 | 403 | | |
438 | 404 | | |
439 | | - | |
| 405 | + | |
440 | 406 | | |
441 | 407 | | |
442 | 408 | | |
| |||
0 commit comments