Skip to content

Commit e5a4bee

Browse files
Revert "[Mono.Android] Add [Category] for IDE completion of string props (#2866)" (#5375)
Fixes: #5373 Reverts: d548ec9 Reverts: #2862 The idea in Issue #2862 and commit d548ec9 was to to improve code completion for Android Resources within Visual Studio: ![Android Resource completion in Visual Studio][0] This was achieved by adding [`CategoryAttribute`][1] to various properties so that Visual Studio could know what completions to show: partial class ActivityAttribute { [System.ComponentModel.Category ("@string")] public string? Label {get; set;} } Unfortunately, the presence of `CategoryAttribute` causes the .NET 6 linker to preserve various dependencies of `System.ComponentModel`, causing `.apk` files to be larger than desired. Furthermore, the feature was *experimental*, and never shipped in a stable Visual Studio release. For now, revert commit d548ec9, removing the `[Category]` custom attributes. This will allow `.apk` files to be smaller for .NET 6. Should we want to bring this feature back, we'll either need to see if the linker can be improved to remove `CategoryAttribute`, or instead introduce a set of `internal` attributes for this purpose. Results of this change in a .NET 6 `.apk`: > apkdiff before.apk after.apk Size difference in bytes ([*1] apk1 only, [*2] apk2 only): - 56 lib/armeabi-v7a/libxamarin-app.so Section size difference - 8 .rel.dyn - 12 .data - 6,144 .bss - 77 assemblies/Mono.Android.dll - 3,194 assemblies/System.ComponentModel.Primitives.dll *1 Summary: + 0 Other entries 0.00% (of 6,484) + 0 Dalvik executables 0.00% (of 317,508) - 3,271 Assemblies -0.15% (of 2,139,234) - 56 Shared libraries -0.00% (of 20,674,428) - 3,468 Package size difference -0.04% (of 9,485,287) [0]: https://user-images.githubusercontent.com/169707/54777844-f9b37500-4bf1-11e9-8e52-63982b8b362f.gif [1]: https://docs.microsoft.com/dotnet/api/system.componentmodel.categoryattribute?view=netframework-4.7.2
1 parent 143f662 commit e5a4bee

File tree

8 files changed

+49
-29
lines changed

8 files changed

+49
-29
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
### Application size improvements
2+
3+
* [GitHub PR 5375](https://github.com/xamarin/xamarin-android/pull/5375):
4+
Removed decoration of `System.ComponentModel.CategoryAttribute` to
5+
improve linker behavior. This reduced the .NET assembly size of a
6+
.NET 6 application by 3,271 bytes.
7+
8+
`CategoryAttribute` was removed from properties on types such as
9+
`Android.App.ActivityAttribute`:
10+
11+
```diff
12+
-[Category ("@drawable;@mipmap")]
13+
public string? Icon { get; set; }
14+
-[Category ("@string")]
15+
public string? Label { get; set; }
16+
```
17+
18+
A full list of types changed:
19+
20+
* `Android.App.ActivityAttribute`
21+
* `Android.App.ApplicationAttribute`
22+
* `Android.App.InstrumentationAttribute`
23+
* `Android.App.ServiceAttribute`
24+
* `Android.Content.BroadcastReceiverAttribute`
25+
* `Android.Content.ContentProviderAttribute`

src/Xamarin.Android.NamingCustomAttributes/Android.App/ActivityAttribute.cs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
using System;
2-
using System.ComponentModel;
32

43
using Android.Content.PM;
54
using Android.Views;
@@ -53,9 +52,7 @@ public ActivityAttribute ()
5352
#if ANDROID_11
5453
public bool HardwareAccelerated {get; set;}
5554
#endif
56-
[Category ("@drawable;@mipmap")]
5755
public string? Icon {get; set;}
58-
[Category ("@string")]
5956
public string? Label {get; set;}
6057
public LaunchMode LaunchMode {get; set;}
6158
#if ANDROID_23
@@ -102,7 +99,6 @@ public ActivityAttribute ()
10299
public WindowRotationAnimation RotationAnimation {get; set;}
103100
#endif
104101
#if ANDROID_25
105-
[Category ("@drawable;@mipmap")]
106102
public string? RoundIcon {get; set;}
107103
#endif
108104
#if ANDROID_23
@@ -124,7 +120,6 @@ public ActivityAttribute ()
124120
#endif
125121
public bool StateNotNeeded {get; set;}
126122
public string? TaskAffinity {get; set;}
127-
[Category ("@style")]
128123
public string? Theme {get; set;}
129124
#if ANDROID_27
130125
public bool TurnScreenOn {get; set;}

src/Xamarin.Android.NamingCustomAttributes/Android.App/ApplicationAttribute.cs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
using System;
2-
using System.ComponentModel;
32

43
using Android.Content.PM;
54
using Android.Views;
@@ -31,7 +30,6 @@ public ApplicationAttribute ()
3130
public string? Banner {get; set;}
3231
#endif
3332
public bool Debuggable {get; set;}
34-
[Category ("@string")]
3533
public string? Description {get; set;}
3634
#if ANDROID_24
3735
public bool DirectBootAware {get; set;}
@@ -48,16 +46,13 @@ public ApplicationAttribute ()
4846
public bool HardwareAccelerated {get; set;}
4947
#endif
5048
public bool HasCode {get; set;}
51-
[Category ("@drawable;@mipmap")]
5249
public string? Icon {get; set;}
5350
public bool KillAfterRestore {get; set;}
5451
#if ANDROID_11
5552
public bool LargeHeap {get; set;}
5653
#endif
57-
[Category ("@string")]
5854
public string? Label {get; set;}
5955
#if ANDROID_11
60-
[Category ("@drawable;@mipmap")]
6156
public string? Logo {get; set;}
6257
#endif
6358
public Type? ManageSpaceActivity {get; set;}
@@ -75,14 +70,12 @@ public ApplicationAttribute ()
7570
public string? RestrictedAccountType {get; set;}
7671
#endif
7772
#if ANDROID_25
78-
[Category ("@drawable;@mipmap")]
7973
public string? RoundIcon {get; set;}
8074
#endif
8175
#if ANDROID_17
8276
public bool SupportsRtl {get; set;}
8377
#endif
8478
public string? TaskAffinity {get; set;}
85-
[Category ("@style")]
8679
public string? Theme {get; set;}
8780
#if ANDROID_14
8881
public UiOptions UiOptions {get; set;}

src/Xamarin.Android.NamingCustomAttributes/Android.App/InstrumentationAttribute.cs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
using System;
2-
using System.ComponentModel;
32

43
namespace Android.App {
54

@@ -15,13 +14,10 @@ public InstrumentationAttribute ()
1514

1615
public bool FunctionalTest {get; set;}
1716
public bool HandleProfiling {get; set;}
18-
[Category ("@drawable;@mipmap")]
1917
public string? Icon {get; set;}
20-
[Category ("@string")]
2118
public string? Label {get; set;}
2219
public string? Name {get; set;}
2320
#if ANDROID_25
24-
[Category ("@drawable;@mipmap")]
2521
public string? RoundIcon {get; set;}
2622
#endif
2723
public string? TargetPackage {get; set;}

src/Xamarin.Android.NamingCustomAttributes/Android.App/ServiceAttribute.cs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
using System;
2-
using System.ComponentModel;
32

43
using Android.Content.PM;
54
using Android.Views;
@@ -26,17 +25,14 @@ public ServiceAttribute ()
2625
#if ANDROID_29
2726
public ForegroundService ForegroundServiceType {get; set;}
2827
#endif
29-
[Category ("@drawable;@mipmap")]
3028
public string? Icon {get; set;}
3129
#if ANDROID_16
3230
public bool IsolatedProcess {get; set;}
3331
#endif
34-
[Category ("@string")]
3532
public string? Label {get; set;}
3633
public string? Permission {get; set;}
3734
public string? Process {get; set;}
3835
#if ANDROID_25
39-
[Category ("@drawable;@mipmap")]
4036
public string? RoundIcon {get; set;}
4137
#endif
4238
}

src/Xamarin.Android.NamingCustomAttributes/Android.Content/BroadcastReceiverAttribute.cs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
using System;
2-
using System.ComponentModel;
32

43
namespace Android.Content {
54

@@ -16,17 +15,13 @@ public BroadcastReceiverAttribute ()
1615
public bool DirectBootAware {get; set;}
1716
public bool Enabled {get; set;}
1817
public bool Exported {get; set;}
19-
[Category ("@string")]
2018
public string? Description {get; set;}
21-
[Category ("@drawable;@mipmap")]
2219
public string? Icon {get; set;}
23-
[Category ("@string")]
2420
public string? Label {get; set;}
2521
public string? Name {get; set;}
2622
public string? Permission {get; set;}
2723
public string? Process {get; set;}
2824
#if ANDROID_25
29-
[Category ("@drawable;@mipmap")]
3025
public string? RoundIcon {get; set;}
3126
#endif
3227
}

src/Xamarin.Android.NamingCustomAttributes/Android.Content/ContentProviderAttribute.cs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
using System;
2-
using System.ComponentModel;
32

43
namespace Android.Content {
54

@@ -25,18 +24,15 @@ public ContentProviderAttribute (string[] authorities)
2524
public bool Enabled {get; set;}
2625
public bool Exported {get; set;}
2726
public bool GrantUriPermissions {get; set;}
28-
[Category ("@drawable;@mipmap")]
2927
public string? Icon {get; set;}
3028
public int InitOrder {get; set;}
31-
[Category ("@string")]
3229
public string? Label {get; set;}
3330
public bool MultiProcess {get; set;}
3431
public string? Name {get; set;}
3532
public string? Permission {get; set;}
3633
public string? Process {get; set;}
3734
public string? ReadPermission {get; set;}
3835
#if ANDROID_25
39-
[Category ("@drawable;@mipmap")]
4036
public string? RoundIcon {get; set;}
4137
#endif
4238
public bool Syncable {get; set;}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
Compat issues with assembly Mono.Android:
2+
CannotRemoveAttribute : Attribute 'System.ComponentModel.CategoryAttribute' exists on 'Android.App.ActivityAttribute.Icon' in the contract but not the implementation.
3+
CannotRemoveAttribute : Attribute 'System.ComponentModel.CategoryAttribute' exists on 'Android.App.ActivityAttribute.Label' in the contract but not the implementation.
4+
CannotRemoveAttribute : Attribute 'System.ComponentModel.CategoryAttribute' exists on 'Android.App.ActivityAttribute.RoundIcon' in the contract but not the implementation.
5+
CannotRemoveAttribute : Attribute 'System.ComponentModel.CategoryAttribute' exists on 'Android.App.ActivityAttribute.Theme' in the contract but not the implementation.
6+
CannotRemoveAttribute : Attribute 'System.ComponentModel.CategoryAttribute' exists on 'Android.App.ApplicationAttribute.Description' in the contract but not the implementation.
7+
CannotRemoveAttribute : Attribute 'System.ComponentModel.CategoryAttribute' exists on 'Android.App.ApplicationAttribute.Icon' in the contract but not the implementation.
8+
CannotRemoveAttribute : Attribute 'System.ComponentModel.CategoryAttribute' exists on 'Android.App.ApplicationAttribute.Label' in the contract but not the implementation.
9+
CannotRemoveAttribute : Attribute 'System.ComponentModel.CategoryAttribute' exists on 'Android.App.ApplicationAttribute.Logo' in the contract but not the implementation.
10+
CannotRemoveAttribute : Attribute 'System.ComponentModel.CategoryAttribute' exists on 'Android.App.ApplicationAttribute.RoundIcon' in the contract but not the implementation.
11+
CannotRemoveAttribute : Attribute 'System.ComponentModel.CategoryAttribute' exists on 'Android.App.ApplicationAttribute.Theme' in the contract but not the implementation.
12+
CannotRemoveAttribute : Attribute 'System.ComponentModel.CategoryAttribute' exists on 'Android.App.InstrumentationAttribute.Icon' in the contract but not the implementation.
13+
CannotRemoveAttribute : Attribute 'System.ComponentModel.CategoryAttribute' exists on 'Android.App.InstrumentationAttribute.Label' in the contract but not the implementation.
14+
CannotRemoveAttribute : Attribute 'System.ComponentModel.CategoryAttribute' exists on 'Android.App.InstrumentationAttribute.RoundIcon' in the contract but not the implementation.
15+
CannotRemoveAttribute : Attribute 'System.ComponentModel.CategoryAttribute' exists on 'Android.App.ServiceAttribute.Icon' in the contract but not the implementation.
16+
CannotRemoveAttribute : Attribute 'System.ComponentModel.CategoryAttribute' exists on 'Android.App.ServiceAttribute.Label' in the contract but not the implementation.
17+
CannotRemoveAttribute : Attribute 'System.ComponentModel.CategoryAttribute' exists on 'Android.App.ServiceAttribute.RoundIcon' in the contract but not the implementation.
18+
CannotRemoveAttribute : Attribute 'System.ComponentModel.CategoryAttribute' exists on 'Android.Content.BroadcastReceiverAttribute.Description' in the contract but not the implementation.
19+
CannotRemoveAttribute : Attribute 'System.ComponentModel.CategoryAttribute' exists on 'Android.Content.BroadcastReceiverAttribute.Icon' in the contract but not the implementation.
20+
CannotRemoveAttribute : Attribute 'System.ComponentModel.CategoryAttribute' exists on 'Android.Content.BroadcastReceiverAttribute.Label' in the contract but not the implementation.
21+
CannotRemoveAttribute : Attribute 'System.ComponentModel.CategoryAttribute' exists on 'Android.Content.BroadcastReceiverAttribute.RoundIcon' in the contract but not the implementation.
22+
CannotRemoveAttribute : Attribute 'System.ComponentModel.CategoryAttribute' exists on 'Android.Content.ContentProviderAttribute.Icon' in the contract but not the implementation.
23+
CannotRemoveAttribute : Attribute 'System.ComponentModel.CategoryAttribute' exists on 'Android.Content.ContentProviderAttribute.Label' in the contract but not the implementation.
24+
CannotRemoveAttribute : Attribute 'System.ComponentModel.CategoryAttribute' exists on 'Android.Content.ContentProviderAttribute.RoundIcon' in the contract but not the implementation.

0 commit comments

Comments
 (0)