Skip to content

Commit 15da2c7

Browse files
committed
Merge branch 'main' into dev/grendel/fix-proxy-throwable
* main: [runtime] Remove the last vestiges of desktop builds (#8810) [ci] Don't auto-retry APK test suites. (#8811) [Microsoft.Android.Templates] Update EN l10n template strings (#8808) Bump to xamarin/Java.Interop/main@651de42 (#8809) [Mono.Android] is now "trimming safe" (#8778)
2 parents 705a6ec + 6fde0f6 commit 15da2c7

File tree

20 files changed

+337
-391
lines changed

20 files changed

+337
-391
lines changed

build-tools/automation/yaml-templates/apk-instrumentation.yaml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ parameters:
1010
artifactSource: ""
1111
artifactFolder: ""
1212
condition: succeeded()
13-
retryCountOnTaskFailure: 1
1413

1514
steps:
1615
- template: /build-tools/automation/yaml-templates/run-dotnet-preview.yaml
@@ -25,7 +24,6 @@ steps:
2524
-v:n -c ${{ parameters.configuration }} ${{ parameters.extraBuildArgs }}
2625
condition: ${{ parameters.condition }}
2726
continueOnError: true
28-
retryCountOnTaskFailure: ${{ parameters.retryCountOnTaskFailure }}
2927

3028
- script: >
3129
DEST="$(Build.StagingDirectory)/Test${{ parameters.configuration }}/${{ parameters.artifactFolder }}/" &&
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
<!-- Import this to enable trim warnings of all kinds -->
2+
<Project>
3+
<PropertyGroup>
4+
<!-- Sets assembly metadata, enable analyzers -->
5+
<IsTrimmable>true</IsTrimmable>
6+
<EnableSingleFileAnalyzer>true</EnableSingleFileAnalyzer>
7+
<EnableAotAnalyzer>true</EnableAotAnalyzer>
8+
<!-- In app projects, tells ILLink to emit warnings as errors -->
9+
<ILLinkTreatWarningsAsErrors>true</ILLinkTreatWarningsAsErrors>
10+
<!--
11+
Trim warnings, codes listed here:
12+
* https://github.com/dotnet/runtime/blob/7403a062960d092c73ce3f07d3ff323ffdf7de43/src/tools/illink/src/linker/Resources/Strings.resx
13+
* https://github.com/dotnet/docs/tree/9cb45cf9cd34f3b7259a023c3d92a124a87090d5/docs/core/deploying/trimming/trim-warnings
14+
-->
15+
<WarningsAsErrors>
16+
$(WarningsAsErrors);
17+
IL2000;IL2001;IL2002;IL2003;IL2004;
18+
IL2005;IL2006;IL2007;IL2008;IL2009;
19+
IL2010;IL2011;IL2012;IL2013;IL2014;
20+
IL2015;IL2016;IL2017;IL2018;IL2019;
21+
IL2020;IL2021;IL2022;IL2023;IL2024;
22+
IL2025;IL2026;IL2027;IL2028;IL2029;
23+
IL2030;IL2031;IL2032;IL2033;IL2034;
24+
IL2035;IL2036;IL2037;IL2038;IL2039;
25+
IL2040;IL2041;IL2042;IL2043;IL2044;
26+
IL2045;IL2046;IL2047;IL2048;IL2049;
27+
IL2050;IL2051;IL2052;IL2053;IL2054;
28+
IL2055;IL2056;IL2057;IL2058;IL2059;
29+
IL2060;IL2061;IL2062;IL2063;IL2064;
30+
IL2065;IL2066;IL2067;IL2068;IL2069;
31+
IL2070;IL2071;IL2072;IL2073;IL2074;
32+
IL2075;IL2076;IL2077;IL2078;IL2079;
33+
IL2080;IL2081;IL2082;IL2083;IL2084;
34+
IL2085;IL2086;IL2087;IL2088;IL2089;
35+
IL2090;IL2091;IL2092;IL2093;IL2094;
36+
IL2095;IL2096;IL2097;IL2098;IL2099;
37+
IL2100;IL2101;IL2102;IL2103;IL2104;
38+
IL2105;IL2106;IL2107;IL2108;IL2109;
39+
IL2110;IL2111;IL2112;IL2113;IL2114;
40+
IL2115;IL2116;IL2117;IL2118;IL2119;
41+
IL2120;IL2121;IL2122;IL2123;IL2124;
42+
IL2125;IL2126;IL2127;IL2128;IL2129;
43+
</WarningsAsErrors>
44+
<!-- In NativeAOT app projects, tells Ilc to emit warnings as errors -->
45+
<IlcTreatWarningsAsErrors>true</IlcTreatWarningsAsErrors>
46+
<!--
47+
NativeAOT warnings, codes listed here:
48+
* https://github.com/dotnet/docs/tree/9cb45cf9cd34f3b7259a023c3d92a124a87090d5/docs/core/deploying/native-aot/warnings
49+
-->
50+
<WarningsAsErrors>
51+
$(WarningsAsErrors);
52+
IL3050;IL3051;IL3052;IL3053;IL3054;IL3055;IL3056;
53+
</WarningsAsErrors>
54+
</PropertyGroup>
55+
</Project>

external/Java.Interop

src/Microsoft.Android.Templates/android-activity/.template.config/localize/templatestrings.en.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"author": "Microsoft",
3-
"name": "Android Activity template",
3+
"name": "Android Activity",
44
"description": "An Android Activity class",
55
"symbols/namespace/description": "namespace for the generated code",
66
"postActions/openInEditor/description": "Opens Activity1.cs in the editor"
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"author": "Microsoft",
3-
"name": "Android Layout template",
3+
"name": "Android Layout",
44
"description": "An Android layout (XML) file",
55
"postActions/openInEditor/description": "Opens Layout1.xml in the editor"
66
}

src/Mono.Android/Android.OS/AsyncTask.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,16 @@ namespace Android.OS {
99

1010
[global::System.Runtime.Versioning.ObsoletedOSPlatform ("android30.0")]
1111
[Register ("android/os/AsyncTask", DoNotGenerateAcw=true)]
12-
public abstract class AsyncTask<TParams, TProgress, TResult> : AsyncTask {
12+
public abstract class AsyncTask<
13+
[DynamicallyAccessedMembers (Constructors)]
14+
TParams,
15+
[DynamicallyAccessedMembers (Constructors)]
16+
TProgress,
17+
[DynamicallyAccessedMembers (Constructors)]
18+
TResult
19+
> : AsyncTask {
20+
21+
const DynamicallyAccessedMemberTypes Constructors = DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.NonPublicConstructors;
1322

1423
static IntPtr java_class_handle;
1524
internal static IntPtr class_ref {

src/Mono.Android/Android.Runtime/AndroidEnvironment.cs

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ public static class AndroidEnvironment {
2424
static IX509TrustManager? sslTrustManager;
2525
static KeyStore? certStore;
2626
static object lock_ = new object ();
27+
[DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)]
2728
static Type? httpMessageHandlerType;
2829

2930
static void SetupTrustManager ()
@@ -335,11 +336,18 @@ static IWebProxy GetDefaultProxy ()
335336
[DynamicDependency (DynamicallyAccessedMemberTypes.PublicParameterlessConstructor, typeof (Xamarin.Android.Net.AndroidMessageHandler))]
336337
static object GetHttpMessageHandler ()
337338
{
339+
// FIXME: https://github.com/xamarin/xamarin-android/issues/8797
340+
// Note that this is a problem for custom $(AndroidHttpClientHandlerType) or $XA_HTTP_CLIENT_HANDLER_TYPE
341+
[UnconditionalSuppressMessage ("Trimming", "IL2057", Justification = "DynamicDependency should preserve AndroidMessageHandler.")]
342+
[return: DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)]
343+
static Type TypeGetType (string typeName) =>
344+
Type.GetType (typeName, throwOnError: false);
345+
338346
if (httpMessageHandlerType is null) {
339347
var handlerTypeName = Environment.GetEnvironmentVariable ("XA_HTTP_CLIENT_HANDLER_TYPE")?.Trim ();
340348
Type? handlerType = null;
341349
if (!String.IsNullOrEmpty (handlerTypeName))
342-
handlerType = Type.GetType (handlerTypeName, throwOnError: false);
350+
handlerType = TypeGetType (handlerTypeName);
343351

344352
// We don't do any type checking or casting here to avoid dependency on System.Net.Http in Mono.Android.dll
345353
if (handlerType is null || !IsAcceptableHttpMessageHandlerType (handlerType)) {
@@ -369,13 +377,19 @@ static bool IsAcceptableHttpMessageHandlerType (Type handlerType)
369377
return true;
370378
}
371379

372-
static bool Extends (Type handlerType, string baseTypeName) {
380+
static bool Extends (
381+
Type handlerType,
382+
[DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)]
383+
string baseTypeName)
384+
{
373385
var baseType = Type.GetType (baseTypeName, throwOnError: false);
374386
return baseType?.IsAssignableFrom (handlerType) ?? false;
375387
}
376388

377-
static Type GetFallbackHttpMessageHandlerType (string typeName = "Xamarin.Android.Net.AndroidMessageHandler, Mono.Android")
389+
[return: DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)]
390+
static Type GetFallbackHttpMessageHandlerType ()
378391
{
392+
const string typeName = "Xamarin.Android.Net.AndroidMessageHandler, Mono.Android";
379393
var handlerType = Type.GetType (typeName, throwOnError: false)
380394
?? throw new InvalidOperationException ($"The {typeName} was not found. The type was probably linked away.");
381395

src/Mono.Android/Android.Runtime/JNIEnv.cs

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,27 @@
1616

1717
namespace Android.Runtime {
1818
public static partial class JNIEnv {
19+
const DynamicallyAccessedMemberTypes Constructors = DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.NonPublicConstructors;
20+
1921
[ThreadStatic]
2022
static byte[]? mvid_bytes;
2123

2224
public static IntPtr Handle => JniEnvironment.EnvironmentPointer;
2325

26+
static Array ArrayCreateInstance (Type elementType, int length) =>
27+
// FIXME: https://github.com/xamarin/xamarin-android/issues/8724
28+
// IL3050 disabled in source: if someone uses NativeAOT, they will get the warning.
29+
#pragma warning disable IL3050
30+
Array.CreateInstance (elementType, length);
31+
#pragma warning restore IL3050
32+
33+
static Type MakeArrayType (Type type) =>
34+
// FIXME: https://github.com/xamarin/xamarin-android/issues/8724
35+
// IL3050 disabled in source: if someone uses NativeAOT, they will get the warning.
36+
#pragma warning disable IL3050
37+
type.MakeArrayType ();
38+
#pragma warning restore IL3050
39+
2440
internal static IntPtr IdentityHash (IntPtr v)
2541
{
2642
return JNIEnvInit.LocalRefsAreIndirect ? RuntimeNativeMethods._monodroid_get_identity_hash_code (Handle, v) : v;
@@ -807,7 +823,7 @@ public static void CopyArray (IntPtr src, Array dest, Type? elementType = null)
807823
throw new ArgumentNullException ("dest");
808824

809825
if (elementType != null && elementType.IsValueType)
810-
AssertCompatibleArrayTypes (src, elementType.MakeArrayType ());
826+
AssertCompatibleArrayTypes (src, MakeArrayType (elementType));
811827

812828
if (elementType != null && elementType.IsArray) {
813829
for (int i = 0; i < dest.Length; ++i) {
@@ -950,7 +966,7 @@ public static void CopyArray (Array source, Type elementType, IntPtr dest)
950966
throw new ArgumentNullException ("elementType");
951967

952968
if (elementType.IsValueType)
953-
AssertCompatibleArrayTypes (elementType.MakeArrayType (), dest);
969+
AssertCompatibleArrayTypes (MakeArrayType (elementType), dest);
954970

955971
Action<Array, IntPtr> converter = GetConverter (CopyManagedToNativeArray, elementType, dest);
956972

@@ -1057,12 +1073,12 @@ public static void CopyArray<T> (T[] src, IntPtr dest)
10571073
}
10581074
} },
10591075
{ typeof (IJavaObject), (type, source, len) => {
1060-
var r = Array.CreateInstance (type!, len);
1076+
var r = ArrayCreateInstance (type!, len);
10611077
CopyArray (source, r, type);
10621078
return r;
10631079
} },
10641080
{ typeof (Array), (type, source, len) => {
1065-
var r = Array.CreateInstance (type!, len);
1081+
var r = ArrayCreateInstance (type!, len);
10661082
CopyArray (source, r, type);
10671083
return r;
10681084
} },
@@ -1075,7 +1091,7 @@ public static void CopyArray<T> (T[] src, IntPtr dest)
10751091
return null;
10761092

10771093
if (element_type != null && element_type.IsValueType)
1078-
AssertCompatibleArrayTypes (array_ptr, element_type.MakeArrayType ());
1094+
AssertCompatibleArrayTypes (array_ptr, MakeArrayType (element_type));
10791095

10801096
int cnt = _GetArrayLength (array_ptr);
10811097

@@ -1130,7 +1146,10 @@ static int _GetArrayLength (IntPtr array_ptr)
11301146
return ret;
11311147
}
11321148

1133-
public static T[]? GetArray<T> (Java.Lang.Object[] array)
1149+
public static T[]? GetArray<
1150+
[DynamicallyAccessedMembers (Constructors)]
1151+
T
1152+
> (Java.Lang.Object[] array)
11341153
{
11351154
if (array == null)
11361155
return null;
@@ -1244,7 +1263,10 @@ static IntPtr GetArrayElementClass<T>(T[] values)
12441263
return FindClass (elementType);
12451264
}
12461265

1247-
public static void CopyObjectArray<T>(IntPtr source, T[] destination)
1266+
public static void CopyObjectArray<
1267+
[DynamicallyAccessedMembers (Constructors)]
1268+
T
1269+
>(IntPtr source, T[] destination)
12481270
{
12491271
if (source == IntPtr.Zero)
12501272
return;

src/Mono.Android/Android.Runtime/JavaCollection.cs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ namespace Android.Runtime {
1414
// java.util.Collection allows null values
1515
public class JavaCollection : Java.Lang.Object, System.Collections.ICollection {
1616

17+
internal const DynamicallyAccessedMemberTypes Constructors = DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.NonPublicConstructors;
18+
1719
internal static IntPtr collection_class = JNIEnv.FindClass ("java/util/Collection");
1820

1921
internal static IntPtr id_add;
@@ -148,6 +150,11 @@ internal Java.Lang.Object[] ToArray ()
148150
//
149151
public void CopyTo (Array array, int array_index)
150152
{
153+
[UnconditionalSuppressMessage ("Trimming", "IL2073", Justification = "JavaCollection<T> constructors are preserved by the MarkJavaObjects trimmer step.")]
154+
[return: DynamicallyAccessedMembers (Constructors)]
155+
static Type GetElementType (Array array) =>
156+
array.GetType ().GetElementType ();
157+
151158
if (array == null)
152159
throw new ArgumentNullException ("array");
153160
if (array_index < 0)
@@ -164,7 +171,7 @@ public void CopyTo (Array array, int array_index)
164171
JavaConvert.FromJniHandle (
165172
JNIEnv.GetObjectArrayElement (lrefArray, i),
166173
JniHandleOwnership.TransferLocalRef,
167-
array.GetType ().GetElementType ()),
174+
GetElementType (array)),
168175
array_index + i);
169176
JNIEnv.DeleteLocalRef (lrefArray);
170177
}
@@ -203,7 +210,10 @@ public static IntPtr ToLocalJniHandle (ICollection? items)
203210
}
204211

205212
[Register ("java/util/Collection", DoNotGenerateAcw=true)]
206-
public sealed class JavaCollection<T> : JavaCollection, ICollection<T> {
213+
public sealed class JavaCollection<
214+
[DynamicallyAccessedMembers (Constructors)]
215+
T
216+
> : JavaCollection, ICollection<T> {
207217

208218
public JavaCollection (IntPtr handle, JniHandleOwnership transfer)
209219
: base (handle, transfer)

src/Mono.Android/Android.Runtime/JavaDictionary.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ namespace Android.Runtime {
1212
// java.util.HashMap allows null keys and values
1313
public class JavaDictionary : Java.Lang.Object, System.Collections.IDictionary {
1414

15+
internal const DynamicallyAccessedMemberTypes Constructors = DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.NonPublicConstructors;
16+
1517
class DictionaryEnumerator : IDictionaryEnumerator {
1618

1719
IEnumerator simple_enumerator;
@@ -396,7 +398,12 @@ public static IntPtr ToLocalJniHandle (IDictionary? dictionary)
396398
// it may throw.
397399
//
398400
[Register ("java/util/HashMap", DoNotGenerateAcw=true)]
399-
public class JavaDictionary<K, V> : JavaDictionary, IDictionary<K, V> {
401+
public class JavaDictionary<
402+
[DynamicallyAccessedMembers (Constructors)]
403+
K,
404+
[DynamicallyAccessedMembers (Constructors)]
405+
V
406+
> : JavaDictionary, IDictionary<K, V> {
400407

401408
[Register (".ctor", "()V", "")]
402409
public JavaDictionary ()

0 commit comments

Comments
 (0)