Skip to content

Commit b7ee29a

Browse files
committed
Merge branch 'main' into dev/grendel/clr-host
* main: [Mono.Android-Tests] Remove obsolete `.shproj` file. (#9758) [NativeAOT] introduce `Microsoft.Android.Runtime.NativeAOT.dll` (#9760)
2 parents 542c13a + d376590 commit b7ee29a

File tree

122 files changed

+845
-810
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

122 files changed

+845
-810
lines changed

.vscode/tasks.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,9 +126,9 @@
126126
{
127127
"label": "prepare-sample-under-dotnet",
128128
"type": "shell",
129-
"windows": { "command": "dotnet-local.cmd build --no-restore tests/Mono.Android-Tests/Runtime-Microsoft.Android.Sdk/Mono.Android.NET-Tests.csproj -c ${input:configuration} -t:GenerateNuGetConfig -p:AndroidNETTestConfigOutputDir=${workspaceRoot}/samples", },
130-
"linux": { "command": "./dotnet-local.sh build --no-restore tests/Mono.Android-Tests/Runtime-Microsoft.Android.Sdk/Mono.Android.NET-Tests.csproj -c ${input:configuration} -t:GenerateNuGetConfig -p:AndroidNETTestConfigOutputDir=${workspaceRoot}/samples",},
131-
"osx": { "command": "./dotnet-local.sh build --no-restore tests/Mono.Android-Tests/Runtime-Microsoft.Android.Sdk/Mono.Android.NET-Tests.csproj -c ${input:configuration} -t:GenerateNuGetConfig -p:AndroidNETTestConfigOutputDir=${workspaceRoot}/samples",},
129+
"windows": { "command": "dotnet-local.cmd build --no-restore tests/Mono.Android-Tests/Mono.Android-Tests/Mono.Android.NET-Tests.csproj -c ${input:configuration} -t:GenerateNuGetConfig -p:AndroidNETTestConfigOutputDir=${workspaceRoot}/samples", },
130+
"linux": { "command": "./dotnet-local.sh build --no-restore tests/Mono.Android-Tests/Mono.Android-Tests/Mono.Android.NET-Tests.csproj -c ${input:configuration} -t:GenerateNuGetConfig -p:AndroidNETTestConfigOutputDir=${workspaceRoot}/samples",},
131+
"osx": { "command": "./dotnet-local.sh build --no-restore tests/Mono.Android-Tests/Mono.Android-Tests/Mono.Android.NET-Tests.csproj -c ${input:configuration} -t:GenerateNuGetConfig -p:AndroidNETTestConfigOutputDir=${workspaceRoot}/samples",},
132132
"group": {
133133
"kind": "build",
134134
"isDefault": true

Documentation/workflow/UnitTests.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -411,12 +411,12 @@ These tests are generally found in:
411411
These tests are run by using the `RunTestApp` target on the appropriate project
412412
file, which includes:
413413

414-
* `tests/Mono.Android-Tests/Runtime-Microsoft.Android.Sdk/Mono.Android.NET-Tests.csproj`
414+
* `tests/Mono.Android-Tests/Mono.Android-Tests/Mono.Android.NET-Tests.csproj`
415415

416416
For example:
417417

418418
```zsh
419-
./dotnet-local.sh build -t:RunTestApp tests/Mono.Android-Tests/Runtime-Microsoft.Android.Sdk/Mono.Android.NET-Tests.csproj
419+
./dotnet-local.sh build -t:RunTestApp tests/Mono.Android-Tests/Mono.Android-Tests/Mono.Android.NET-Tests.csproj
420420
```
421421

422422
After running the tests, a `TestResult*.xml` file will be created in the

Xamarin.Android.sln

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "proguard-android", "src\pro
127127
EndProject
128128
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "native-clr", "src\native\native-clr.csproj", "{39F49484-872A-489D-8E6B-3BC532DD571D}"
129129
EndProject
130+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.Android.Runtime.NativeAOT", "src\Microsoft.Android.Runtime.NativeAOT\Microsoft.Android.Runtime.NativeAOT.csproj", "{E8831F32-11D7-D42C-E43C-711998BC357A}"
131+
EndProject
130132
Global
131133
GlobalSection(SolutionConfigurationPlatforms) = preSolution
132134
Debug|AnyCPU = Debug|AnyCPU
@@ -353,6 +355,10 @@ Global
353355
{39F49484-872A-489D-8E6B-3BC532DD571D}.Debug|AnyCPU.Build.0 = Debug|Any CPU
354356
{39F49484-872A-489D-8E6B-3BC532DD571D}.Release|AnyCPU.ActiveCfg = Release|Any CPU
355357
{39F49484-872A-489D-8E6B-3BC532DD571D}.Release|AnyCPU.Build.0 = Release|Any CPU
358+
{E8831F32-11D7-D42C-E43C-711998BC357A}.Debug|AnyCPU.ActiveCfg = Debug|Any CPU
359+
{E8831F32-11D7-D42C-E43C-711998BC357A}.Debug|AnyCPU.Build.0 = Debug|Any CPU
360+
{E8831F32-11D7-D42C-E43C-711998BC357A}.Release|AnyCPU.ActiveCfg = Release|Any CPU
361+
{E8831F32-11D7-D42C-E43C-711998BC357A}.Release|AnyCPU.Build.0 = Release|Any CPU
356362
EndGlobalSection
357363
GlobalSection(SolutionProperties) = preSolution
358364
HideSolutionNode = FALSE
@@ -413,6 +419,7 @@ Global
413419
{5E806C9F-1B67-4B6B-A6AB-258834250DBB} = {FFCF518F-2A4A-40A2-9174-2EE13B76C723}
414420
{5FD0133B-69E5-4474-9B67-9FD1D0150C70} = {FFCF518F-2A4A-40A2-9174-2EE13B76C723}
415421
{39F49484-872A-489D-8E6B-3BC532DD571D} = {FFCF518F-2A4A-40A2-9174-2EE13B76C723}
422+
{E8831F32-11D7-D42C-E43C-711998BC357A} = {04E3E11E-B47D-4599-8AFC-50515A95E715}
416423
EndGlobalSection
417424
GlobalSection(ExtensibilityGlobals) = postSolution
418425
SolutionGuid = {53A1F287-EFB2-4D97-A4BB-4A5E145613F6}

build-tools/automation/azure-pipelines-nightly.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ stages:
144144
parameters:
145145
configuration: $(XA.Build.Configuration)
146146
testName: Mono.Android.NET_Tests-$(XA.Build.Configuration)-$(avdApiLevel)
147-
project: tests/Mono.Android-Tests/Runtime-Microsoft.Android.Sdk/Mono.Android.NET-Tests.csproj
147+
project: tests/Mono.Android-Tests/Mono.Android-Tests/Mono.Android.NET-Tests.csproj
148148
testResultsFiles: TestResult-Mono.Android.NET_Tests-$(XA.Build.Configuration)$(avdApiLevel).xml
149149
extraBuildArgs: -p:TestsFlavor=$(avdApiLevel) -p:TestAvdApiLevel=$(avdApiLevel) -p:TestAvdAbi=$(avdAbi) -p:TestAvdType=$(avdType)
150150
artifactSource: bin/Test$(XA.Build.Configuration)/$(DotNetTargetFramework)-android/Mono.Android.NET_Tests-Signed.aab

build-tools/automation/yaml-templates/stage-package-tests.yaml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ stages:
6666
buildConfiguration: $(XA.Build.Configuration)
6767
configuration: Debug
6868
testName: Mono.Android.NET_Tests-Debug
69-
project: tests/Mono.Android-Tests/Runtime-Microsoft.Android.Sdk/Mono.Android.NET-Tests.csproj
69+
project: tests/Mono.Android-Tests/Mono.Android-Tests/Mono.Android.NET-Tests.csproj
7070
testResultsFiles: TestResult-Mono.Android.NET_Tests-Debug.xml
7171
artifactSource: bin/TestDebug/$(DotNetTargetFramework)-android/Mono.Android.NET_Tests-Signed.apk
7272
artifactFolder: $(DotNetTargetFramework)-Debug
@@ -75,7 +75,7 @@ stages:
7575
parameters:
7676
configuration: $(XA.Build.Configuration)
7777
testName: Mono.Android.NET_Tests-$(XA.Build.Configuration)
78-
project: tests/Mono.Android-Tests/Runtime-Microsoft.Android.Sdk/Mono.Android.NET-Tests.csproj
78+
project: tests/Mono.Android-Tests/Mono.Android-Tests/Mono.Android.NET-Tests.csproj
7979
testResultsFiles: TestResult-Mono.Android.NET_Tests-$(XA.Build.Configuration).xml
8080
artifactSource: bin/Test$(XA.Build.Configuration)/$(DotNetTargetFramework)-android/Mono.Android.NET_Tests-Signed.aab
8181
artifactFolder: $(DotNetTargetFramework)-$(XA.Build.Configuration)
@@ -84,7 +84,7 @@ stages:
8484
parameters:
8585
configuration: $(XA.Build.Configuration)
8686
testName: Mono.Android.NET_Tests-NoAab
87-
project: tests/Mono.Android-Tests/Runtime-Microsoft.Android.Sdk/Mono.Android.NET-Tests.csproj
87+
project: tests/Mono.Android-Tests/Mono.Android-Tests/Mono.Android.NET-Tests.csproj
8888
testResultsFiles: TestResult-Mono.Android.NET_Tests-$(XA.Build.Configuration)NoAab.xml
8989
extraBuildArgs: -p:TestsFlavor=NoAab -p:AndroidPackageFormat=apk
9090
artifactSource: bin/Test$(XA.Build.Configuration)/$(DotNetTargetFramework)-android/Mono.Android.NET_Tests-Signed.apk
@@ -94,7 +94,7 @@ stages:
9494
parameters:
9595
configuration: $(XA.Build.Configuration)
9696
testName: Mono.Android.NET_Tests-Interpreter
97-
project: tests/Mono.Android-Tests/Runtime-Microsoft.Android.Sdk/Mono.Android.NET-Tests.csproj
97+
project: tests/Mono.Android-Tests/Mono.Android-Tests/Mono.Android.NET-Tests.csproj
9898
testResultsFiles: TestResult-Mono.Android.NET_Tests-$(XA.Build.Configuration)Interpreter.xml
9999
extraBuildArgs: -p:TestsFlavor=Interpreter -p:UseInterpreter=True
100100
artifactSource: bin/Test$(XA.Build.Configuration)/$(DotNetTargetFramework)-android/Mono.Android.NET_Tests-Signed.aab
@@ -172,7 +172,7 @@ stages:
172172
parameters:
173173
configuration: $(XA.Build.Configuration)
174174
testName: Mono.Android.NET_Tests-NoAot
175-
project: tests/Mono.Android-Tests/Runtime-Microsoft.Android.Sdk/Mono.Android.NET-Tests.csproj
175+
project: tests/Mono.Android-Tests/Mono.Android-Tests/Mono.Android.NET-Tests.csproj
176176
testResultsFiles: TestResult-Mono.Android.NET_Tests-$(XA.Build.Configuration)NoAot.xml
177177
extraBuildArgs: -p:TestsFlavor=NoAot -p:RunAOTCompilation=false
178178
artifactSource: bin/Test$(XA.Build.Configuration)/$(DotNetTargetFramework)-android/Mono.Android.NET_Tests-Signed.aab
@@ -182,7 +182,7 @@ stages:
182182
parameters:
183183
configuration: $(XA.Build.Configuration)
184184
testName: Mono.Android.NET_Tests-TrimModePartial
185-
project: tests/Mono.Android-Tests/Runtime-Microsoft.Android.Sdk/Mono.Android.NET-Tests.csproj
185+
project: tests/Mono.Android-Tests/Mono.Android-Tests/Mono.Android.NET-Tests.csproj
186186
testResultsFiles: TestResult-Mono.Android.NET_Tests-$(XA.Build.Configuration)TrimModePartial.xml
187187
extraBuildArgs: -p:TestsFlavor=TrimModePartial -p:TrimMode=partial
188188
artifactSource: bin/Test$(XA.Build.Configuration)/$(DotNetTargetFramework)-android/Mono.Android.NET_Tests-Signed.aab
@@ -192,7 +192,7 @@ stages:
192192
parameters:
193193
configuration: $(XA.Build.Configuration)
194194
testName: Mono.Android.NET_Tests-AotLlvm
195-
project: tests/Mono.Android-Tests/Runtime-Microsoft.Android.Sdk/Mono.Android.NET-Tests.csproj
195+
project: tests/Mono.Android-Tests/Mono.Android-Tests/Mono.Android.NET-Tests.csproj
196196
testResultsFiles: TestResult-Mono.Android.NET_Tests-$(XA.Build.Configuration)AotLlvm.xml
197197
extraBuildArgs: -p:TestsFlavor=AotLlvm -p:EnableLLVM=true -p:AndroidEnableProfiledAot=false
198198
artifactSource: bin/Test$(XA.Build.Configuration)/$(DotNetTargetFramework)-android/Mono.Android.NET_Tests-Signed.aab

build-tools/create-packs/Microsoft.Android.Runtime.proj

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,11 @@ projects that use the Microsoft.Android framework in .NET 6+.
3939
<_AndroidRuntimePackAssemblies Include="$(_MonoAndroidNETDefaultOutDir)Java.Interop.dll" />
4040
<_AndroidRuntimePackAssemblies Include="$(_MonoAndroidNETDefaultOutDir)Mono.Android.dll" />
4141
<_AndroidRuntimePackAssemblies Include="$(_MonoAndroidNETDefaultOutDir)Mono.Android.Runtime.dll" />
42-
<!-- Always include stable Mono.Android.Export.dll -->
42+
<!-- Always include stable versions of the following assemblies -->
43+
<_AndroidRuntimePackAssemblies
44+
Include="$(_MonoAndroidNETOutputRoot)$(AndroidLatestStableApiLevel)\Microsoft.Android.Runtime.NativeAOT.dll"
45+
Condition=" '$(AndroidRuntime)' == 'NativeAOT' "
46+
/>
4347
<_AndroidRuntimePackAssemblies Include="$(_MonoAndroidNETOutputRoot)$(AndroidLatestStableApiLevel)\Mono.Android.Export.dll" />
4448
</ItemGroup>
4549

samples/NativeAOT/AndroidManifest.xml

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,6 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
33
<application android:allowBackup="true" android:icon="@mipmap/appicon" android:label="@string/app_name" android:roundIcon="@mipmap/appicon_round" android:supportsRtl="true">
4-
<!-- Temporary, to eventually be included in .NET Android infrastructure -->
5-
<provider
6-
android:name="net.dot.jni.nativeaot.NativeAotRuntimeProvider"
7-
android:exported="false"
8-
android:initOrder="1999999999"
9-
android:authorities="net.dot.jni.nativeaot.NativeAotRuntimeProvider.__init__"
10-
/>
114
</application>
125
<uses-permission android:name="android.permission.INTERNET" />
136
</manifest>

samples/NativeAOT/NativeAOT.csproj

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,6 @@
99
<ApplicationVersion>1</ApplicationVersion>
1010
<ApplicationDisplayVersion>1.0</ApplicationDisplayVersion>
1111
<AndroidPackageFormat>apk</AndroidPackageFormat>
12-
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
13-
<!-- Temporary for InternalsVisibleTo -->
14-
<SignAssembly>true</SignAssembly>
15-
<AssemblyOriginatorKeyFile>..\..\product.snk</AssemblyOriginatorKeyFile>
1612
<!-- Default to arm64 device -->
1713
<RuntimeIdentifier>android-arm64</RuntimeIdentifier>
1814
<!-- Current required properties for NativeAOT -->
@@ -29,8 +25,4 @@
2925
<_FastDeploymentDiagnosticLogging>true</_FastDeploymentDiagnosticLogging>
3026
</PropertyGroup>
3127

32-
<ItemGroup>
33-
<AndroidJavaSource Update="*.java" Bind="false" />
34-
<ProjectReference Include="..\..\external\Java.Interop\src\Java.Runtime.Environment\Java.Runtime.Environment.csproj" />
35-
</ItemGroup>
3628
</Project>

samples/NativeAOT/JavaInteropRuntime.cs renamed to src/Microsoft.Android.Runtime.NativeAOT/Android.Runtime.NativeAOT/JavaInteropRuntime.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
using Java.Interop;
33
using System.Runtime.InteropServices;
44

5-
namespace NativeAOT;
5+
namespace Microsoft.Android.Runtime;
66

77
static class JavaInteropRuntime
88
{
@@ -35,7 +35,7 @@ static void init (IntPtr jnienv, IntPtr klass)
3535
{
3636
try {
3737
var typeManager = new NativeAotTypeManager ();
38-
var options = new JreRuntimeOptions {
38+
var options = new NativeAotRuntimeOptions {
3939
EnvironmentPointer = jnienv,
4040
TypeManager = typeManager,
4141
ValueManager = new NativeAotValueManager (typeManager),

samples/NativeAOT/Logging.cs renamed to src/Microsoft.Android.Runtime.NativeAOT/Android.Runtime.NativeAOT/Logging.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
using System.Runtime.InteropServices;
77
using System.Text;
88

9-
namespace NativeAOT;
9+
namespace Microsoft.Android.Runtime;
1010

1111
internal sealed class LogcatTextWriter : TextWriter {
1212

samples/NativeAOT/NativeAotTypeManager.cs renamed to src/Microsoft.Android.Runtime.NativeAOT/Android.Runtime.NativeAOT/NativeAotTypeManager.cs

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,33 +3,35 @@
33
using Java.Interop;
44
using Java.Interop.Tools.TypeNameMappings;
55

6-
namespace NativeAOT;
6+
namespace Microsoft.Android.Runtime;
77

88
partial class NativeAotTypeManager : JniRuntime.JniTypeManager {
99

1010
const DynamicallyAccessedMemberTypes Constructors = DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.NonPublicConstructors;
1111
internal const DynamicallyAccessedMemberTypes Methods = DynamicallyAccessedMemberTypes.PublicMethods | DynamicallyAccessedMemberTypes.NonPublicMethods;
1212
internal const DynamicallyAccessedMemberTypes MethodsAndPrivateNested = Methods | DynamicallyAccessedMemberTypes.NonPublicNestedTypes;
1313

14-
// TODO: list of types specific to this application
15-
Dictionary<string, Type> typeMappings = new () {
16-
["android/app/Activity"] = typeof (Android.App.Activity),
17-
["android/app/Application"] = typeof (Android.App.Application),
18-
["android/content/Context"] = typeof (Android.Content.Context),
19-
["android/content/ContextWrapper"] = typeof (Android.Content.ContextWrapper),
20-
["android/os/BaseBundle"] = typeof (Android.OS.BaseBundle),
21-
["android/os/Bundle"] = typeof (Android.OS.Bundle),
22-
["android/view/ContextThemeWrapper"] = typeof (Android.Views.ContextThemeWrapper),
23-
["my/MainActivity"] = typeof (MainActivity),
24-
["my/MainApplication"] = typeof (MainApplication),
25-
};
14+
readonly IDictionary<string, Type> TypeMappings = new Dictionary<string, Type> (StringComparer.Ordinal);
2615

2716
public NativeAotTypeManager ()
2817
{
29-
AndroidLog.Print (AndroidLogLevel.Info, "NativeAotTypeManager", $"# jonp: NativeAotTypeManager()");
18+
AndroidLog.Print (AndroidLogLevel.Info, "NativeAotTypeManager", $"NativeAotTypeManager()");
19+
var startTicks = global::System.Environment.TickCount;
20+
InitializeTypeMappings ();
21+
var endTicks = global::System.Environment.TickCount;
22+
AndroidLog.Print (AndroidLogLevel.Info, "NativeAotTypeManager", $"InitializeTypeMappings() took {endTicks - startTicks}ms");
3023
}
3124

32-
protected override Type? GetInvokerTypeCore (Type type)
25+
void InitializeTypeMappings ()
26+
{
27+
// Should be replaced by src/Microsoft.Android.Sdk.ILLink/TypeMappingStep.cs
28+
throw new InvalidOperationException ("TypeMappings should be replaced during trimming!");
29+
}
30+
31+
[return: DynamicallyAccessedMembers (Constructors)]
32+
protected override Type? GetInvokerTypeCore (
33+
[DynamicallyAccessedMembers (Constructors)]
34+
Type type)
3335
{
3436
const string suffix = "Invoker";
3537

@@ -68,6 +70,10 @@ static Type MakeGenericType (
6870
return MakeGenericType (suffixDefinition, arguments);
6971
}
7072

73+
// NOTE: suppressions below also in `src/Mono.Android/Android.Runtime/AndroidRuntime.cs`
74+
[UnconditionalSuppressMessage ("Trimming", "IL2057", Justification = "Type.GetType() can never statically know the string value parsed from parameter 'methods'.")]
75+
[UnconditionalSuppressMessage ("Trimming", "IL2067", Justification = "Delegate.CreateDelegate() can never statically know the string value parsed from parameter 'methods'.")]
76+
[UnconditionalSuppressMessage ("Trimming", "IL2072", Justification = "Delegate.CreateDelegate() can never statically know the string value parsed from parameter 'methods'.")]
7177
public override void RegisterNativeMembers (
7278
JniType nativeClass,
7379
[DynamicallyAccessedMembers (MethodsAndPrivateNested)]
@@ -143,7 +149,7 @@ public override void RegisterNativeMembers (
143149
protected override IEnumerable<Type> GetTypesForSimpleReference (string jniSimpleReference)
144150
{
145151
AndroidLog.Print (AndroidLogLevel.Info, "NativeAotTypeManager", $"# jonp: GetTypesForSimpleReference: jniSimpleReference=`{jniSimpleReference}`");
146-
if (typeMappings.TryGetValue (jniSimpleReference, out var target)) {
152+
if (TypeMappings.TryGetValue (jniSimpleReference, out var target)) {
147153
Console.WriteLine ($"# jonp: GetTypesForSimpleReference: jniSimpleReference=`{jniSimpleReference}` -> `{target}`");
148154
yield return target;
149155
}
@@ -161,9 +167,7 @@ protected override IEnumerable<string> GetSimpleReferences (Type type)
161167

162168
IEnumerable<string> CreateSimpleReferencesEnumerator (Type type)
163169
{
164-
if (typeMappings == null)
165-
yield break;
166-
foreach (var e in typeMappings) {
170+
foreach (var e in TypeMappings) {
167171
if (e.Value == type)
168172
yield return e.Key;
169173
}

0 commit comments

Comments
 (0)