Skip to content

Commit

Permalink
Revert "[Mono.Android] Add [Category] for IDE completion of string pr…
Browse files Browse the repository at this point in the history
…ops (dotnet#2866)" (dotnet#5375)

Fixes: dotnet#5373

Reverts: d548ec9
Reverts: dotnet#2862

The idea in Issue dotnet#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
  • Loading branch information
jonathanpeppers authored Dec 9, 2020
1 parent 143f662 commit e5a4bee
Show file tree
Hide file tree
Showing 8 changed files with 49 additions and 29 deletions.
25 changes: 25 additions & 0 deletions Documentation/release-notes/5375.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
### Application size improvements

* [GitHub PR 5375](https://github.com/xamarin/xamarin-android/pull/5375):
Removed decoration of `System.ComponentModel.CategoryAttribute` to
improve linker behavior. This reduced the .NET assembly size of a
.NET 6 application by 3,271 bytes.

`CategoryAttribute` was removed from properties on types such as
`Android.App.ActivityAttribute`:

```diff
-[Category ("@drawable;@mipmap")]
public string? Icon { get; set; }
-[Category ("@string")]
public string? Label { get; set; }
```

A full list of types changed:

* `Android.App.ActivityAttribute`
* `Android.App.ApplicationAttribute`
* `Android.App.InstrumentationAttribute`
* `Android.App.ServiceAttribute`
* `Android.Content.BroadcastReceiverAttribute`
* `Android.Content.ContentProviderAttribute`
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using System.ComponentModel;

using Android.Content.PM;
using Android.Views;
Expand Down Expand Up @@ -53,9 +52,7 @@ public ActivityAttribute ()
#if ANDROID_11
public bool HardwareAccelerated {get; set;}
#endif
[Category ("@drawable;@mipmap")]
public string? Icon {get; set;}
[Category ("@string")]
public string? Label {get; set;}
public LaunchMode LaunchMode {get; set;}
#if ANDROID_23
Expand Down Expand Up @@ -102,7 +99,6 @@ public ActivityAttribute ()
public WindowRotationAnimation RotationAnimation {get; set;}
#endif
#if ANDROID_25
[Category ("@drawable;@mipmap")]
public string? RoundIcon {get; set;}
#endif
#if ANDROID_23
Expand All @@ -124,7 +120,6 @@ public ActivityAttribute ()
#endif
public bool StateNotNeeded {get; set;}
public string? TaskAffinity {get; set;}
[Category ("@style")]
public string? Theme {get; set;}
#if ANDROID_27
public bool TurnScreenOn {get; set;}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using System.ComponentModel;

using Android.Content.PM;
using Android.Views;
Expand Down Expand Up @@ -31,7 +30,6 @@ public ApplicationAttribute ()
public string? Banner {get; set;}
#endif
public bool Debuggable {get; set;}
[Category ("@string")]
public string? Description {get; set;}
#if ANDROID_24
public bool DirectBootAware {get; set;}
Expand All @@ -48,16 +46,13 @@ public ApplicationAttribute ()
public bool HardwareAccelerated {get; set;}
#endif
public bool HasCode {get; set;}
[Category ("@drawable;@mipmap")]
public string? Icon {get; set;}
public bool KillAfterRestore {get; set;}
#if ANDROID_11
public bool LargeHeap {get; set;}
#endif
[Category ("@string")]
public string? Label {get; set;}
#if ANDROID_11
[Category ("@drawable;@mipmap")]
public string? Logo {get; set;}
#endif
public Type? ManageSpaceActivity {get; set;}
Expand All @@ -75,14 +70,12 @@ public ApplicationAttribute ()
public string? RestrictedAccountType {get; set;}
#endif
#if ANDROID_25
[Category ("@drawable;@mipmap")]
public string? RoundIcon {get; set;}
#endif
#if ANDROID_17
public bool SupportsRtl {get; set;}
#endif
public string? TaskAffinity {get; set;}
[Category ("@style")]
public string? Theme {get; set;}
#if ANDROID_14
public UiOptions UiOptions {get; set;}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using System.ComponentModel;

namespace Android.App {

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

public bool FunctionalTest {get; set;}
public bool HandleProfiling {get; set;}
[Category ("@drawable;@mipmap")]
public string? Icon {get; set;}
[Category ("@string")]
public string? Label {get; set;}
public string? Name {get; set;}
#if ANDROID_25
[Category ("@drawable;@mipmap")]
public string? RoundIcon {get; set;}
#endif
public string? TargetPackage {get; set;}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using System.ComponentModel;

using Android.Content.PM;
using Android.Views;
Expand All @@ -26,17 +25,14 @@ public ServiceAttribute ()
#if ANDROID_29
public ForegroundService ForegroundServiceType {get; set;}
#endif
[Category ("@drawable;@mipmap")]
public string? Icon {get; set;}
#if ANDROID_16
public bool IsolatedProcess {get; set;}
#endif
[Category ("@string")]
public string? Label {get; set;}
public string? Permission {get; set;}
public string? Process {get; set;}
#if ANDROID_25
[Category ("@drawable;@mipmap")]
public string? RoundIcon {get; set;}
#endif
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using System.ComponentModel;

namespace Android.Content {

Expand All @@ -16,17 +15,13 @@ public BroadcastReceiverAttribute ()
public bool DirectBootAware {get; set;}
public bool Enabled {get; set;}
public bool Exported {get; set;}
[Category ("@string")]
public string? Description {get; set;}
[Category ("@drawable;@mipmap")]
public string? Icon {get; set;}
[Category ("@string")]
public string? Label {get; set;}
public string? Name {get; set;}
public string? Permission {get; set;}
public string? Process {get; set;}
#if ANDROID_25
[Category ("@drawable;@mipmap")]
public string? RoundIcon {get; set;}
#endif
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using System.ComponentModel;

namespace Android.Content {

Expand All @@ -25,18 +24,15 @@ public ContentProviderAttribute (string[] authorities)
public bool Enabled {get; set;}
public bool Exported {get; set;}
public bool GrantUriPermissions {get; set;}
[Category ("@drawable;@mipmap")]
public string? Icon {get; set;}
public int InitOrder {get; set;}
[Category ("@string")]
public string? Label {get; set;}
public bool MultiProcess {get; set;}
public string? Name {get; set;}
public string? Permission {get; set;}
public string? Process {get; set;}
public string? ReadPermission {get; set;}
#if ANDROID_25
[Category ("@drawable;@mipmap")]
public string? RoundIcon {get; set;}
#endif
public bool Syncable {get; set;}
Expand Down
24 changes: 24 additions & 0 deletions tests/api-compatibility/acceptable-breakages-vReference.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
Compat issues with assembly Mono.Android:
CannotRemoveAttribute : Attribute 'System.ComponentModel.CategoryAttribute' exists on 'Android.App.ActivityAttribute.Icon' in the contract but not the implementation.
CannotRemoveAttribute : Attribute 'System.ComponentModel.CategoryAttribute' exists on 'Android.App.ActivityAttribute.Label' in the contract but not the implementation.
CannotRemoveAttribute : Attribute 'System.ComponentModel.CategoryAttribute' exists on 'Android.App.ActivityAttribute.RoundIcon' in the contract but not the implementation.
CannotRemoveAttribute : Attribute 'System.ComponentModel.CategoryAttribute' exists on 'Android.App.ActivityAttribute.Theme' in the contract but not the implementation.
CannotRemoveAttribute : Attribute 'System.ComponentModel.CategoryAttribute' exists on 'Android.App.ApplicationAttribute.Description' in the contract but not the implementation.
CannotRemoveAttribute : Attribute 'System.ComponentModel.CategoryAttribute' exists on 'Android.App.ApplicationAttribute.Icon' in the contract but not the implementation.
CannotRemoveAttribute : Attribute 'System.ComponentModel.CategoryAttribute' exists on 'Android.App.ApplicationAttribute.Label' in the contract but not the implementation.
CannotRemoveAttribute : Attribute 'System.ComponentModel.CategoryAttribute' exists on 'Android.App.ApplicationAttribute.Logo' in the contract but not the implementation.
CannotRemoveAttribute : Attribute 'System.ComponentModel.CategoryAttribute' exists on 'Android.App.ApplicationAttribute.RoundIcon' in the contract but not the implementation.
CannotRemoveAttribute : Attribute 'System.ComponentModel.CategoryAttribute' exists on 'Android.App.ApplicationAttribute.Theme' in the contract but not the implementation.
CannotRemoveAttribute : Attribute 'System.ComponentModel.CategoryAttribute' exists on 'Android.App.InstrumentationAttribute.Icon' in the contract but not the implementation.
CannotRemoveAttribute : Attribute 'System.ComponentModel.CategoryAttribute' exists on 'Android.App.InstrumentationAttribute.Label' in the contract but not the implementation.
CannotRemoveAttribute : Attribute 'System.ComponentModel.CategoryAttribute' exists on 'Android.App.InstrumentationAttribute.RoundIcon' in the contract but not the implementation.
CannotRemoveAttribute : Attribute 'System.ComponentModel.CategoryAttribute' exists on 'Android.App.ServiceAttribute.Icon' in the contract but not the implementation.
CannotRemoveAttribute : Attribute 'System.ComponentModel.CategoryAttribute' exists on 'Android.App.ServiceAttribute.Label' in the contract but not the implementation.
CannotRemoveAttribute : Attribute 'System.ComponentModel.CategoryAttribute' exists on 'Android.App.ServiceAttribute.RoundIcon' in the contract but not the implementation.
CannotRemoveAttribute : Attribute 'System.ComponentModel.CategoryAttribute' exists on 'Android.Content.BroadcastReceiverAttribute.Description' in the contract but not the implementation.
CannotRemoveAttribute : Attribute 'System.ComponentModel.CategoryAttribute' exists on 'Android.Content.BroadcastReceiverAttribute.Icon' in the contract but not the implementation.
CannotRemoveAttribute : Attribute 'System.ComponentModel.CategoryAttribute' exists on 'Android.Content.BroadcastReceiverAttribute.Label' in the contract but not the implementation.
CannotRemoveAttribute : Attribute 'System.ComponentModel.CategoryAttribute' exists on 'Android.Content.BroadcastReceiverAttribute.RoundIcon' in the contract but not the implementation.
CannotRemoveAttribute : Attribute 'System.ComponentModel.CategoryAttribute' exists on 'Android.Content.ContentProviderAttribute.Icon' in the contract but not the implementation.
CannotRemoveAttribute : Attribute 'System.ComponentModel.CategoryAttribute' exists on 'Android.Content.ContentProviderAttribute.Label' in the contract but not the implementation.
CannotRemoveAttribute : Attribute 'System.ComponentModel.CategoryAttribute' exists on 'Android.Content.ContentProviderAttribute.RoundIcon' in the contract but not the implementation.

0 comments on commit e5a4bee

Please sign in to comment.