-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix animated gifs in Release builds #22874
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,13 @@ | ||
using System; | ||
using System.Diagnostics.CodeAnalysis; | ||
using Android.Runtime; | ||
|
||
namespace Microsoft.Maui | ||
{ | ||
static class JavaObjectExtensions | ||
{ | ||
const DynamicallyAccessedMemberTypes Constructors = DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.NonPublicConstructors; | ||
|
||
public static bool IsDisposed(this Java.Lang.Object obj) | ||
{ | ||
return obj.Handle == IntPtr.Zero; | ||
|
@@ -30,5 +33,18 @@ public static bool IsAlive([NotNullWhen(true)] this global::Android.Runtime.IJav | |
|
||
return !obj.IsDisposed(); | ||
} | ||
|
||
public static TResult? TryJavaCast<[DynamicallyAccessedMembers (Constructors)] TResult>(this IJavaObject? instance) | ||
where TResult : class, IJavaObject | ||
{ | ||
try | ||
{ | ||
return instance.JavaCast<TResult>(); | ||
} | ||
catch | ||
{ | ||
return null; | ||
} | ||
Comment on lines
+44
to
+47
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not a fan of an empty try-catch with no logging. Does a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I logged an issue with a feature request or something: dotnet/android#9038 |
||
} | ||
mattleibow marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had to fix something similar earlier this year: dotnet/android#8594 I think you can fix this with a few
[DynamicDependency]
attributes to this method:There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does no C# code use any of the above types? What @simonrozsival suggests seems like the right idea.
Something similar also happens here:
Since no C# code uses
NinePatchDrawable
it's linked away.Mono.Android.dll
and all the AndroidX libraries mark themselves trimmable.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The issue is that I don't know what types are being used - I know of some but it could be any type of drawable. I would have to list all of the known ones and then it would still not be super perfect because of third parties.
Also, since we don't use the type in C# - all the loading code is in Java now - we are otentially forcing a whole bunch of C# types to exist when we don't really need it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It doesn't seem like
[DynamicDependency]
is applicable in this case then. Doing the JavaCast might be the best way after all. Hopefully Proguard won't be messing up the Java side of things :)