forked from dotnet/android
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Mono.Android] is now "trimming safe"
Fixes: dotnet#5652 Each trimming problem listed below. ~~ AndroidEnvironment ~~ src\Mono.Android\Android.Runtime\AndroidEnvironment.cs(373,19): error IL2057: Unrecognized value passed to the parameter 'typeName' of method 'System.Type.GetType(String, Boolean)'. It's not possible to guarantee the availability of the target type. src\Mono.Android\Android.Runtime\AndroidEnvironment.cs(379,22): error IL2057: Unrecognized value passed to the parameter 'typeName' of method 'System.Type.GetType(String, Boolean)'. It's not possible to guarantee the availability of the target type. src\Mono.Android\Android.Runtime\AndroidEnvironment.cs(342,20): error IL2057: Unrecognized value passed to the parameter 'typeName' of method 'System.Type.GetType(String, Boolean)'. It's not possible to guarantee the availability of the target type. src\Mono.Android\Android.Runtime\AndroidEnvironment.cs(352,11): error IL2077: 'type' argument does not satisfy 'DynamicallyAccessedMemberTypes.PublicParameterlessConstructor' in call to 'System.Activator.CreateInstance(Type)'. The field 'Android.Runtime.AndroidEnvironment.httpMessageHandlerType' does not have matching annotations. The source value must declare at least the same requirements as those declared on the target location it is assigned to. To fix these: * Use constant strings for calls like: Type.GetType ("System.Net.Http.HttpMessageHandler, System.Net.Http", throwOnError: false) Use `Type.IsAssignableFrom()` inline, and the trimmer now understands the code paths. ~~ JavaConvert ~~ src\Mono.Android\Java.Interop\JavaConvert.cs(223,12): error IL2091: 'TResult' generic argument does not satisfy 'DynamicallyAccessedMemberTypes.PublicConstructors', 'DynamicallyAccessedMemberTypes.NonPublicConstructors' in 'Java.Interop.JavaObjectExtensions._JavaCast<TResult>(IJavaObject)'. The generic parameter 'T' of 'Java.Interop.JavaConvert.FromJavaObject<T>(IJavaObject, out Boolean)' does not have matching annotations. The source value must declare at least the same requirements as those declared on the target location it is assigned to. src\Mono.Android\Java.Interop\JavaConvert.cs(254,12): error IL2067: 'resultType' argument does not satisfy 'DynamicallyAccessedMemberTypes.PublicConstructors', 'DynamicallyAccessedMemberTypes.NonPublicConstructors' in call to 'Java.Interop.JavaObjectExtensions.JavaCast(IJavaObject, Type)'. The parameter 'targetType' of method 'Java.Interop.JavaConvert.FromJavaObject(IJavaObject, Type)' does not have matching annotations. The source value must declare at least the same requirements as those declared on the target location it is assigned to. src\Mono.Android\Java.Interop\JavaConvert.cs(67,14): error IL3050: Using member 'System.Type.MakeGenericType(params Type[])' which has 'RequiresDynamicCodeAttribute' can break functionality when AOT compiling. The native code for this instantiation might not be available at runtime. src\Mono.Android\Java.Interop\JavaConvert.cs(73,14): error IL3050: Using member 'System.Type.MakeGenericType(params Type[])' which has 'RequiresDynamicCodeAttribute' can break functionality when AOT compiling. The native code for this instantiation might not be available at runtime. src\Mono.Android\Java.Interop\JavaConvert.cs(79,14): error IL3050: Using member 'System.Type.MakeGenericType(params Type[])' which has 'RequiresDynamicCodeAttribute' can break functionality when AOT compiling. The native code for this instantiation might not be available at runtime. Adding attributes fixed some of these. I suppressed warnings for: * `Type.MakeGenericType()`: `JavaDictionary<,>`, `JavaList<>`, and `JavaCollection<>` use DynamicDependency to preserve `FromJniHandle` method. * `Type.GetElementType()`: for calling `MyJavaObject[]` constructors, the `MarkJavaObjects` trimmer step should preserve these constructors. This trickled over to require more attributes for: * `AdapterView` * `ArrayAdapter` * `AsyncTask` * `JavaCollection` * `JavaDictionary` * `JavaList` * `JavaList` * `JavaObjectExtensions` * `JavaSet` * `SparseArray` * `System.Linq\Extensions` ~~ JNIEnv ~~ src\Mono.Android\Android.Runtime\JNIEnv.cs(810,38): error IL3050: Using member 'System.Type.MakeArrayType()' which has 'RequiresDynamicCodeAttribute' can break functionality when AOT compiling. The code for an array of the specified type might not be available. src\Mono.Android\Android.Runtime\JNIEnv.cs(953,33): error IL3050: Using member 'System.Type.MakeArrayType()' which has 'RequiresDynamicCodeAttribute' can break functionality when AOT compiling. The code for an array of the specified type might not be available. src\Mono.Android\Android.Runtime\JNIEnv.cs(1078,44): error IL3050: Using member 'System.Type.MakeArrayType()' which has 'RequiresDynamicCodeAttribute' can break functionality when AOT compiling. The code for an array of the specified type might not be available. src\Mono.Android\Android.Runtime\JNIEnv.cs(1139,15): error IL2091: 'T' generic argument does not satisfy 'DynamicallyAccessedMemberTypes.PublicConstructors', 'DynamicallyAccessedMemberTypes.NonPublicConstructors' in 'Java.Interop.JavaConvert.FromJavaObject<T>(IJavaObject)'. The generic parameter 'T' of 'Android.Runtime.JNIEnv.GetArray<T>(Object[])' does not have matching annotations. The source value must declare at least the same requirements as those declared on the target location it is assigned to. src\Mono.Android\Android.Runtime\JNIEnv.cs(1060,14): error IL3050: Using member 'System.Array.CreateInstance(Type, Int32)' which has 'RequiresDynamicCodeAttribute' can break functionality when AOT compiling. The code for an array of the specified type might not be available. src\Mono.Android\Android.Runtime\JNIEnv.cs(1065,14): error IL3050: Using member 'System.Array.CreateInstance(Type, Int32)' which has 'RequiresDynamicCodeAttribute' can break functionality when AOT compiling. The code for an array of the specified type might not be available. src\Mono.Android\Android.Runtime\JNIEnv.cs(1257,23): error IL2091: 'T' generic argument does not satisfy 'DynamicallyAccessedMemberTypes.PublicConstructors', 'DynamicallyAccessedMemberTypes.NonPublicConstructors' in 'Java.Interop.JavaConvert.FromJniHandle<T>(nint, JniHandleOwnership)'. The generic parameter 'T' of 'Android.Runtime.JNIEnv.CopyObjectArray<T>(nint, T[])' does not have matching annotations. The source value must declare at least the same requirements as those declared on the target location it is assigned to. Adding some attributes fixed two of these. Suppress NativeAOT warnings, in source, for: * `Array.CreateInstance()` * `Type.MakeArrayType()` Link to an issue to fix in the future.
- Loading branch information
1 parent
68b1b91
commit f2716fa
Showing
16 changed files
with
257 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
<!-- Import this to enable trim warnings of all kinds --> | ||
<Project> | ||
<PropertyGroup> | ||
<!-- Sets assembly metadata, enable analyzers --> | ||
<IsTrimmable>true</IsTrimmable> | ||
<EnableSingleFileAnalyzer>true</EnableSingleFileAnalyzer> | ||
<EnableAotAnalyzer>true</EnableAotAnalyzer> | ||
<!-- In app projects, tells ILLink to emit warnings as errors --> | ||
<ILLinkTreatWarningsAsErrors>true</ILLinkTreatWarningsAsErrors> | ||
<!-- | ||
Trim warnings, codes listed here: | ||
* https://github.com/dotnet/runtime/blob/7403a062960d092c73ce3f07d3ff323ffdf7de43/src/tools/illink/src/linker/Resources/Strings.resx | ||
* https://github.com/dotnet/docs/tree/9cb45cf9cd34f3b7259a023c3d92a124a87090d5/docs/core/deploying/trimming/trim-warnings | ||
--> | ||
<WarningsAsErrors> | ||
$(WarningsAsErrors); | ||
IL2000;IL2001;IL2002;IL2003;IL2004; | ||
IL2005;IL2006;IL2007;IL2008;IL2009; | ||
IL2010;IL2011;IL2012;IL2013;IL2014; | ||
IL2015;IL2016;IL2017;IL2018;IL2019; | ||
IL2020;IL2021;IL2022;IL2023;IL2024; | ||
IL2025;IL2026;IL2027;IL2028;IL2029; | ||
IL2030;IL2031;IL2032;IL2033;IL2034; | ||
IL2035;IL2036;IL2037;IL2038;IL2039; | ||
IL2040;IL2041;IL2042;IL2043;IL2044; | ||
IL2045;IL2046;IL2047;IL2048;IL2049; | ||
IL2050;IL2051;IL2052;IL2053;IL2054; | ||
IL2055;IL2056;IL2057;IL2058;IL2059; | ||
IL2060;IL2061;IL2062;IL2063;IL2064; | ||
IL2065;IL2066;IL2067;IL2068;IL2069; | ||
IL2070;IL2071;IL2072;IL2073;IL2074; | ||
IL2075;IL2076;IL2077;IL2078;IL2079; | ||
IL2080;IL2081;IL2082;IL2083;IL2084; | ||
IL2085;IL2086;IL2087;IL2088;IL2089; | ||
IL2090;IL2091;IL2092;IL2093;IL2094; | ||
IL2095;IL2096;IL2097;IL2098;IL2099; | ||
IL2100;IL2101;IL2102;IL2103;IL2104; | ||
IL2105;IL2106;IL2107;IL2108;IL2109; | ||
IL2110;IL2111;IL2112;IL2113;IL2114; | ||
IL2115;IL2116;IL2117;IL2118;IL2119; | ||
IL2120;IL2121;IL2122;IL2123;IL2124; | ||
IL2125;IL2126;IL2127;IL2128;IL2129; | ||
</WarningsAsErrors> | ||
<!-- | ||
NativeAOT warnings, codes listed here: | ||
* https://github.com/dotnet/docs/tree/9cb45cf9cd34f3b7259a023c3d92a124a87090d5/docs/core/deploying/native-aot/warnings | ||
--> | ||
<WarningsAsErrors> | ||
$(WarningsAsErrors); | ||
IL3050;IL3051;IL3052;IL3053;IL3054;IL3055;IL3056; | ||
</WarningsAsErrors> | ||
</PropertyGroup> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.