Skip to content
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

Enable marshal methods support by default #7351

Merged
merged 141 commits into from
Oct 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
141 commits
Select commit Hold shift + click to select a range
35f4e24
Implement marshal methods LLVM IR executable code generator.
grendello Mar 29, 2022
e34f88e
[marshal methods] Runtime fixes and missing features
grendello Mar 29, 2022
eb15bd2
Update
grendello Jul 18, 2022
a80e4a1
TODOs and CWLs
grendello Jul 18, 2022
49751f7
Update JI
grendello Jul 26, 2022
803b3e3
Merge branch 'main' into mm-codegen
grendello Aug 1, 2022
e6101c1
Merge branch 'mm-codegen' into mm-runtime
grendello Aug 1, 2022
657aff0
[WIP] Generate full native symbol names when necessary
grendello Aug 1, 2022
e8d3026
Handle enums properly (except when there are arrays of them)
grendello Aug 2, 2022
4d7ec30
Merge branch 'main' into mm-codegen
grendello Aug 3, 2022
39068d3
Merge branch 'mm-codegen' into mm-runtime
grendello Aug 3, 2022
82ece43
Generate correct native names and process overloads properly
grendello Aug 3, 2022
acd5bc8
When a class is first seen, make sure to set class index properly
grendello Aug 3, 2022
9a476d8
Merge branch 'main' into mm-codegen
grendello Aug 3, 2022
8d2503f
Merge branch 'mm-codegen' into mm-runtime
grendello Aug 3, 2022
f913d24
Merge branch 'main' into mm-codegen
grendello Aug 5, 2022
52c99db
Merge branch 'mm-codegen' into mm-runtime
grendello Aug 5, 2022
e5358f4
Trying to get the MAUI sample app running
grendello Aug 5, 2022
2f15f67
Merge branch 'main' into mm-codegen
grendello Aug 5, 2022
21c066f
Merge branch 'mm-codegen' into mm-runtime
grendello Aug 5, 2022
3c8901a
MAUI app ran with marshal methods for the first time
grendello Aug 8, 2022
7dc40fc
Check array dimensions when classifying methods
grendello Aug 8, 2022
2b2ce55
Merge branch 'main' into mm-codegen
grendello Aug 8, 2022
9c38c68
Merge branch 'mm-codegen' into mm-runtime
grendello Aug 8, 2022
85f2cfa
Merge branch 'main' into mm-codegen
grendello Aug 10, 2022
024b5f5
Merge branch 'mm-codegen' into mm-runtime
grendello Aug 10, 2022
4d92570
We need to generate wrappers for methods with non-blittable params
grendello Aug 10, 2022
20a2f00
Blittable wrapper generator progress
grendello Aug 11, 2022
2d3c043
Non-blittable marshal method wrappers implemented
grendello Aug 12, 2022
071e9d3
Merge branch 'main' into mm-codegen
grendello Aug 17, 2022
710242e
Merge branch 'mm-codegen' into mm-runtime
grendello Aug 17, 2022
af91895
Fix non-blittable wrapper method generation
grendello Aug 17, 2022
673836c
Merge branch 'main' into mm-codegen
grendello Aug 17, 2022
ca2f92d
Merge branch 'mm-codegen' into mm-runtime
grendello Aug 17, 2022
10e63e2
Merge branch 'main' into mm-codegen
grendello Aug 17, 2022
238417e
Merge branch 'mm-codegen' into mm-runtime
grendello Aug 17, 2022
72c4b60
Disable some debug CWLs
grendello Aug 18, 2022
eb94adc
Merge branch 'mm-codegen' into mm-runtime
grendello Aug 18, 2022
a8471cd
Add some debugging info to function pointer lookups
grendello Aug 18, 2022
cfaabf2
Escape double quotes in function attribute value
grendello Aug 18, 2022
8ca61bb
Merge branch 'main' into mm-codegen
grendello Aug 18, 2022
a473f27
Merge branch 'mm-codegen' into mm-runtime
grendello Aug 18, 2022
d99b7e3
Fix and optimize debugging info for class and method names
grendello Aug 19, 2022
cfa1b30
Reorganize code, move error handling to the end of function
grendello Aug 19, 2022
9c9612d
Merge branch 'main' into mm-runtime
grendello Aug 19, 2022
334619b
Disable marshal methods for PR
grendello Aug 19, 2022
c9332a8
Move some code behind the ENABLE_MARSHAL_METHODS flag
grendello Aug 19, 2022
e518a4e
Remove workarounds for methods with non-blittable types
grendello Aug 22, 2022
905e784
Build marshal methods support unconditionally
grendello Aug 22, 2022
f29f0d2
Remove debugging messages
grendello Aug 22, 2022
6ca1245
Update apkdesc files
grendello Aug 22, 2022
b988b7f
Merge branch 'mm-runtime' into mm-cleanup-and-enable
grendello Aug 22, 2022
63bf193
Fix a failing test
grendello Aug 22, 2022
3530c39
Merge branch 'mm-runtime' into mm-cleanup-and-enable
grendello Aug 22, 2022
c516792
Merge branch 'main' into mm-runtime
grendello Aug 23, 2022
c8a2d9f
Implement some requested changes
grendello Aug 23, 2022
e8f3215
Merge branch 'mm-runtime' into mm-cleanup-and-enable
grendello Aug 23, 2022
b60c767
Don't package mono.android.jar when marshal methods are enabled
grendello Aug 23, 2022
0aa3e95
Merge branch 'main' into mm-runtime
grendello Aug 24, 2022
e3ac595
Merge branch 'mm-runtime' into mm-cleanup-and-enable
grendello Aug 24, 2022
49895b8
Merge branch 'main' into mm-runtime
grendello Aug 24, 2022
a8cfd90
Merge branch 'mm-runtime' into mm-cleanup-and-enable
grendello Aug 24, 2022
92fa671
Remove JI workaround
grendello Aug 24, 2022
f37b4dc
Merge branch 'mm-runtime' into mm-cleanup-and-enable
grendello Aug 24, 2022
09678bd
Don't register dynamically methods for which we generate JCWs
grendello Aug 24, 2022
d60fc08
[WIP] Some cleanup + special cases
grendello Aug 25, 2022
6b116bf
Merge branch 'main' into mm-runtime
grendello Aug 26, 2022
1d88be2
Merge branch 'mm-runtime' into mm-cleanup-and-enable
grendello Aug 26, 2022
aea0b0f
TypeManager special case now works
grendello Aug 26, 2022
e1e59f0
Merge branch 'main' into mm-runtime
grendello Aug 31, 2022
aaff9f5
Merge branch 'mm-runtime' into mm-cleanup-and-enable
grendello Aug 31, 2022
df04d47
Merge branch 'main' into mm-runtime
grendello Sep 2, 2022
7e9761f
Merge branch 'mm-runtime' into mm-cleanup-and-enable
grendello Sep 2, 2022
f17ad9f
Fix Debug mode and Release w/o marshal methods
grendello Sep 5, 2022
7a00e0e
Make AOT work (with trimming)
grendello Sep 6, 2022
d3d9007
Merge branch 'main' into mm-runtime
grendello Sep 6, 2022
73237a2
Merge branch 'mm-runtime' into mm-cleanup-and-enable
grendello Sep 6, 2022
b459e4a
Merge branch 'main' into mm-runtime
grendello Sep 7, 2022
dfcf734
Merge branch 'mm-runtime' into mm-cleanup-and-enable
grendello Sep 7, 2022
5dccadb
Time to test things
grendello Sep 7, 2022
fc83958
Merge branch 'main' into mm-cleanup-and-enable
grendello Sep 7, 2022
8bdb607
Merge branch 'main' into mm-cleanup-and-enable
grendello Sep 7, 2022
cd832c7
Turn a couple of warnings into debug messages for now
grendello Sep 7, 2022
a9995b0
Update apkdesc files
grendello Sep 7, 2022
86d9fca
Try to avoid locked files on Windows
grendello Sep 7, 2022
1162a09
Merge branch 'main' into mm-cleanup-and-enable
grendello Sep 8, 2022
65471a8
Try to unbreak build of tests
grendello Sep 8, 2022
7f87a37
Don't require the `EnableMarshalMethods` parameter
grendello Sep 8, 2022
ea4c57f
Merge branch 'main' into mm-cleanup-and-enable
grendello Sep 8, 2022
115c6fa
Remove the check, it's incorrect
grendello Sep 8, 2022
222163e
Avoid warning about duplicate files to add to apk
grendello Sep 8, 2022
5bd03e2
Merge branch 'main' into mm-cleanup-and-enable
grendello Sep 8, 2022
e635b27
Update apkdesc files
grendello Sep 8, 2022
221ad8f
Let's see if it breaks any tests (it works locally)
grendello Sep 8, 2022
d03092d
Merge branch 'main' into mm-cleanup-and-enable
grendello Sep 8, 2022
e1a621e
Merge branch 'main' into mm-cleanup-and-enable
grendello Sep 9, 2022
f9bca3c
Update apkdesc files
grendello Sep 9, 2022
977a060
Hunting for reasons of the crashes
grendello Sep 9, 2022
09eeb7e
Merge branch 'main' into mm-cleanup-and-enable
grendello Sep 9, 2022
312d84e
Refactor the JNIEnv class
grendello Sep 12, 2022
b143c95
Merge branch 'main' into mm-cleanup-and-enable
grendello Sep 13, 2022
c20ae31
Generate assembly image cache array even if marshal methods disabled
grendello Sep 13, 2022
8c9ceca
Most problems solved, the crashes make sense now
grendello Sep 13, 2022
2b33563
Put the assembly reader settings back in
grendello Sep 13, 2022
94d9bea
Merge branch 'main' into mm-cleanup-and-enable
grendello Sep 14, 2022
73277aa
Fix copying of rewritten assemblies
grendello Sep 14, 2022
5b14a70
Fix a typo and relax requirements on GenerateJavaStubs.IntermediateOu…
grendello Sep 14, 2022
9077b6a
Fix unhandled exception propagation
grendello Sep 14, 2022
32347b7
Fix builds of apps with linking and just a single RID
grendello Sep 14, 2022
ddedcc3
[WIP] Investigating a Mono.Android crash
grendello Sep 15, 2022
aed7b2d
Merge branch 'main' into mm-cleanup-and-enable
grendello Sep 16, 2022
2aa7cfe
Mono.Android.NET_Tests crash investigations continued
grendello Sep 16, 2022
92fb339
TODO
grendello Sep 16, 2022
d3c54a0
Merge branch 'main' into mm-cleanup-and-enable
grendello Sep 19, 2022
170b5d1
Factor out bits of code to a separate assembly
grendello Sep 19, 2022
3fdc653
Merge branch 'main' into mm-cleanup-and-enable
grendello Sep 20, 2022
504ced9
[WIP] Exception wrapper generator in assembly rewriter
grendello Sep 20, 2022
be9280e
Merge branch 'main' into mm-cleanup-and-enable
grendello Sep 21, 2022
983ad70
Exception wrapper appears to work now
grendello Sep 21, 2022
7d201e3
Fix a handful of CI test failures
grendello Sep 21, 2022
35d49d4
Remove unnecessary argument
grendello Sep 21, 2022
1ebb5d8
Fix a couple more causes for test failures
grendello Sep 26, 2022
62a5138
More tests fixed
grendello Sep 26, 2022
9852cc5
Merge branch 'main' into mm-cleanup-and-enable
grendello Sep 27, 2022
fe2ae06
Fix tests which use callbacks with Android.Graphics.Color
grendello Sep 27, 2022
e1609d9
Let's see if the failing tests work with these changes
grendello Sep 27, 2022
98655ea
Oops, forgot to put that back in
grendello Sep 27, 2022
5d138d0
Copy PR 7406 to test if it works for marshal methods
grendello Sep 27, 2022
71aafd5
Merge branch 'main' into mm-cleanup-and-enable
grendello Sep 27, 2022
d708edc
Merge branch 'main' into mm-cleanup-and-enable
grendello Sep 27, 2022
7124851
Disable marshal methods for Designer tests
grendello Sep 28, 2022
9be7e6b
Add docs
grendello Sep 28, 2022
edcf092
See if we can get crash logs from designer tests
grendello Sep 29, 2022
48c3328
Let's see if this fixes the designer failures
grendello Sep 29, 2022
5781643
Merge branch 'main' into mm-cleanup-and-enable
grendello Sep 29, 2022
5f433b1
Remove debug logging
grendello Sep 29, 2022
8b1d3f9
Address reviews
grendello Sep 30, 2022
724de1d
Merge branch 'main' into mm-cleanup-and-enable
grendello Oct 5, 2022
d26d9e1
Get rid of dead code
grendello Oct 5, 2022
d5016fe
Update documentation
grendello Oct 10, 2022
f8db2d2
Fix indentation and trailing whitespace
grendello Oct 10, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,6 @@
<DisableTransitiveFrameworkReferenceDownloads>true</DisableTransitiveFrameworkReferenceDownloads>
</PropertyGroup>

<PropertyGroup Condition=" '$(MSBuildRuntimeType)' == 'Core' ">
<_EnableMarshalMethods>NoThanks</_EnableMarshalMethods> <!-- set to YesPlease to enable -->
</PropertyGroup>

<PropertyGroup>
<ProductVersion>13.1.99</ProductVersion>
<!-- NuGet package version numbers. See Documentation/guides/OneDotNet.md.
Expand Down
9 changes: 9 additions & 0 deletions Documentation/guides/building-apps/build-properties.md
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,15 @@ not wish to run those checks.

Added in Xamarin.Android 9.4.

## AndroidEnableMarshalMethods

A bool property, not available in the classic Xamarin.Android
releases.

Enable or disable generation of [marshal
methods](../../internals/JavaJNI_Interop.md). Defaults to `True` for
`Release` builds and to `False` for `Debug` builds.

## AndroidEnableMultiDex

A boolean property that
Expand Down
766 changes: 766 additions & 0 deletions Documentation/guides/internals/JavaJNI_Interop.md

Large diffs are not rendered by default.

9 changes: 9 additions & 0 deletions Xamarin.Android.sln
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Mono.Android", "src\Mono.An
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Mono.Android.Export", "src\Mono.Android.Export\Mono.Android.Export.csproj", "{B8105878-D423-4159-A3E7-028298281EC6}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Mono.Android.Runtime", "src\Mono.Android.Runtime\Mono.Android.Runtime.csproj", "{43564FB3-0F79-4FF4-A2B0-B1637072FF01}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Android.Build.BaseTasks", "external\xamarin-android-tools\src\Microsoft.Android.Build.BaseTasks\Microsoft.Android.Build.BaseTasks.csproj", "{3DE17662-DCD6-4F49-AF06-D39AACC8649A}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Xamarin.Android.Tools.AndroidSdk", "external\xamarin-android-tools\src\Xamarin.Android.Tools.AndroidSdk\Xamarin.Android.Tools.AndroidSdk.csproj", "{E34BCFA0-CAA4-412C-AA1C-75DB8D67D157}"
Expand Down Expand Up @@ -296,6 +298,12 @@ Global
{B8105878-D423-4159-A3E7-028298281EC6}.Debug|AnyCPU.Build.0 = Debug|Any CPU
{B8105878-D423-4159-A3E7-028298281EC6}.Release|AnyCPU.ActiveCfg = Release|Any CPU
{B8105878-D423-4159-A3E7-028298281EC6}.Release|AnyCPU.Build.0 = Release|Any CPU

{43564FB3-0F79-4FF4-A2B0-B1637072FF01}.Debug|AnyCPU.ActiveCfg = Debug|Any CPU
{43564FB3-0F79-4FF4-A2B0-B1637072FF01}.Debug|AnyCPU.Build.0 = Debug|Any CPU
{43564FB3-0F79-4FF4-A2B0-B1637072FF01}.Release|AnyCPU.ActiveCfg = Release|Any CPU
{43564FB3-0F79-4FF4-A2B0-B1637072FF01}.Release|AnyCPU.Build.0 = Release|Any CPU

{3DE17662-DCD6-4F49-AF06-D39AACC8649A}.Debug|AnyCPU.ActiveCfg = Debug|Any CPU
{3DE17662-DCD6-4F49-AF06-D39AACC8649A}.Debug|AnyCPU.Build.0 = Debug|Any CPU
{3DE17662-DCD6-4F49-AF06-D39AACC8649A}.Release|AnyCPU.ActiveCfg = Release|Any CPU
Expand Down Expand Up @@ -456,6 +464,7 @@ Global
{73DF9E10-E933-4222-B8E1-F4536FFF9FAD} = {864062D3-A415-4A6F-9324-5820237BA058}
{66CF299A-CE95-4131-BCD8-DB66E30C4BF7} = {04E3E11E-B47D-4599-8AFC-50515A95E715}
{B8105878-D423-4159-A3E7-028298281EC6} = {04E3E11E-B47D-4599-8AFC-50515A95E715}
{43564FB3-0F79-4FF4-A2B0-B1637072FF01} = {04E3E11E-B47D-4599-8AFC-50515A95E715}
{3DE17662-DCD6-4F49-AF06-D39AACC8649A} = {04E3E11E-B47D-4599-8AFC-50515A95E715}
{E34BCFA0-CAA4-412C-AA1C-75DB8D67D157} = {04E3E11E-B47D-4599-8AFC-50515A95E715}
{1E5501E8-49C1-4659-838D-CC9720C5208F} = {CAB438D8-B0F5-4AF0-BEBD-9E2ADBD7B483}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,10 @@ steps:
displayName: 'Copy binlogs'
inputs:
sourceFolder: ${{ parameters.designerSourcePath }}/Xamarin.Designer.Android
contents: '**/*.binlog'
contents: |
**/*.binlog
**/hs*.log
**/hs*.mdmp
targetFolder: $(Build.ArtifactStagingDirectory)/designer-binlogs
overWrite: true
flattenFolders: true
Expand Down
1 change: 1 addition & 0 deletions build-tools/create-packs/Microsoft.Android.Ref.proj
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ by projects that use the Microsoft.Android framework in .NET 6+.
<ItemGroup>
<_AndroidRefPackAssemblies Include="$(JavaInteropSourceDirectory)\bin\$(Configuration)-net7.0\ref\Java.Interop.dll" />
<_AndroidRefPackAssemblies Include="$(_MonoAndroidNETDefaultOutDir)ref\Mono.Android.dll" />
<_AndroidRefPackAssemblies Include="$(_MonoAndroidNETDefaultOutDir)ref\Mono.Android.Runtime.dll" />
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I fear that I'm gonna be "bikeshedding" half the naming here -- and I am! -- but…

Mono.Android.Runtime is not "future-facing". We may stick with Mono.Android.dll "forever", but there are equal odds that we may do a Microsoft.Android.dll name in the future (.NET 10?).

As such, we should choose names which are unlikely to need changing. Possible suggestions:

  • Microsoft.Android.Startup.dll
  • Microsoft.Android.Internals.dll
  • Microsoft.Android.Interop.dll

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd rather keep it Mono.Android.Runtime for now, since it pairs nicely with Mono.Android (and that was the reason I chose this name)

<!-- Always include stable Mono.Android.Export.dll -->
<_AndroidRefPackAssemblies Include="$(_MonoAndroidNETOutputRoot)$(AndroidLatestStableApiLevel)\ref\Mono.Android.Export.dll" />
<FrameworkListFileClass Include="@(_AndroidRefPackAssemblies->'%(Filename)%(Extension)')" Profile="Android" />
Expand Down
1 change: 1 addition & 0 deletions build-tools/create-packs/Microsoft.Android.Runtime.proj
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ projects that use the Microsoft.Android framework in .NET 6+.
<ItemGroup>
<_AndroidRuntimePackAssemblies Include="$(_MonoAndroidNETDefaultOutDir)Java.Interop.dll" />
<_AndroidRuntimePackAssemblies Include="$(_MonoAndroidNETDefaultOutDir)Mono.Android.dll" />
<_AndroidRuntimePackAssemblies Include="$(_MonoAndroidNETDefaultOutDir)Mono.Android.Runtime.dll" />
<!-- Always include stable Mono.Android.Export.dll -->
<_AndroidRuntimePackAssemblies Include="$(_MonoAndroidNETOutputRoot)$(AndroidLatestStableApiLevel)\Mono.Android.Export.dll" />
<_AndroidRuntimePackAssets Include="$(MicrosoftAndroidSdkOutDir)lib\$(AndroidRID)\libmono-android.debug.so" />
Expand Down
1 change: 0 additions & 1 deletion build-tools/scripts/JavaCallableWrappers.targets
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
/>
<ItemGroup>
<_JavaSources Include="$(IntermediateOutputPath)jcw\src\**\*.java" />
<_JavaSources Include="$(JavaInteropSourceDirectory)\src\Java.Interop\java\com\xamarin\**\*.java" />
</ItemGroup>
<WriteLinesToFile
File="$(IntermediateOutputPath)jcw/classes.txt"
Expand Down
2 changes: 1 addition & 1 deletion build-tools/scripts/TestApks.targets
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@
WriteOutputAsMessage="True"
/>
<Xamarin.Android.Tools.BootstrapTasks.Adb
Arguments="$(_AdbTarget) shell setprop debug.mono.log timing"
Arguments="$(_AdbTarget) shell setprop debug.mono.log default,assembly,timing=bare"
IgnoreExitCode="True"
ToolExe="$(AdbToolExe)"
ToolPath="$(AdbToolPath)"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<linker>
<assembly fullname="Mono.Android.Runtime" preserve="all" />
</linker>
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,17 @@
<type fullname="Android.Runtime.InputStreamInvoker" preserve="methods" />
<type fullname="Android.Runtime.JNIEnv">
<method name="Exit" />
<method name="Initialize" />
<method name="PropagateUncaughtException" />
</type>
<type fullname="Android.Runtime.JNIEnvInit">
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I forget; does JNIEnvInit need to remain in Mono.Android.dll? Or can it be moved to the assembly containing AndroidRuntimeInternal?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It remains there for classic Xamarin, it is moved to the new assembly for .NET

<method name="Initialize" />
<method name="RegisterJniNatives" />
</type>
<type fullname="Android.Runtime.JNINativeWrapper" />
<type fullname="Android.Runtime.JObjectRefType" />
<type fullname="Android.Runtime.JValue" />
<type fullname="Android.Runtime.JniHandleOwnership" />
<type fullname="Android.Runtime.Logger" />
<type fullname="Android.Runtime.LogLevel" />
<type fullname="Android.Runtime.LogCategories" />
<type fullname="Android.Runtime.NamespaceMappingAttribute" />
<type fullname="Android.Runtime.OutputStreamAdapter" preserve="methods" />
<type fullname="Android.Runtime.OutputStreamInvoker" preserve="methods" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using System;

namespace Android.Runtime
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

…and more name bikeshedding: I think it was a historical mistake to use Android.Runtime; we're lucky that Google never introduced an android.runtime package.

I think Microsoft.Android.Internals would be a good namespace, or just Microsoft.Android, as all the types here are internal.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Likewise, I'd rather keep the Android.Runtime namespace, because this assembly includes sources from Mono.Android that are in this namespace. If we want to rename it, we should rename it all at once one day.

{
internal static class AndroidEnvironmentInternal
{
internal static Action<Exception>? UnhandledExceptionHandler;

internal static void UnhandledException (Exception e)
{
if (UnhandledExceptionHandler == null) {
return;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if this should abort; if we hit here, either we're very early in startup -- which means aborts would be bad ;-) -- or something is Very Wrong™.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wouldn't abort explicitly here. Hitting it during startup is very unlikely, and if it's not properly initialized, the app will crash anyway, implicitly aborting.

}

UnhandledExceptionHandler (e);
}
}
}
62 changes: 62 additions & 0 deletions src/Mono.Android.Runtime/Mono.Android.Runtime.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<Project>
<UsingTask AssemblyFile="$(PrepTasksAssembly)" TaskName="Xamarin.Android.BuildTools.PrepTasks.ReplaceFileContents" />
<Import Project="Sdk.props" Sdk="Microsoft.NET.Sdk" />
<Import Project="..\..\Configuration.props" />
<Import Project="..\..\build-tools\scripts\XAVersionInfo.targets" />

<PropertyGroup>
<TargetFrameworks>$(DotNetTargetFramework)</TargetFrameworks>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
<AssemblyOriginatorKeyFile>..\..\product.snk</AssemblyOriginatorKeyFile>
<EnableDefaultCompileItems>false</EnableDefaultCompileItems>
<EnableSingleFileAnalyzer>true</EnableSingleFileAnalyzer>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
<ImplicitlyExpandDesignTimeFacades>false</ImplicitlyExpandDesignTimeFacades>
<LangVersion>10</LangVersion>
<NoStdLib>true</NoStdLib>
<Nullable>enable</Nullable>
<ProduceReferenceAssembly>true</ProduceReferenceAssembly>
<SignAssembly>true</SignAssembly>

<!-- Ignore "unused member" warnings from code that originates from Mono.CodeGeneration -->
<NoWarn>$(NoWarn);CS0169;CS0414;CS0649</NoWarn>

<DefineConstants>$(DefineConstants);INSIDE_MONO_ANDROID_RUNTIME;JAVA_INTEROP</DefineConstants>
</PropertyGroup>

<PropertyGroup>
<OutputPath>$(_MonoAndroidNETDefaultOutDir)</OutputPath>
</PropertyGroup>

<Import Project="Sdk.targets" Sdk="Microsoft.NET.Sdk" />

<!-- Only build the .NET 6+ version of 'Mono.Android.Export.dll' for the latest stable Android version. -->
<PropertyGroup Condition=" '$(AndroidApiLevel)' != '$(AndroidLatestStableApiLevel)' ">
<BuildDependsOn></BuildDependsOn>
</PropertyGroup>

<!-- Copy .NET ref/runtime assemblies to bin/$(Configuration)/dotnet/packs folder -->
<PropertyGroup Condition=" '$(AndroidApiLevel)' == '$(AndroidLatestStableApiLevel)' ">
<BuildDependsOn>
$(BuildDependsOn);
_CopyToPackDirs;
</BuildDependsOn>
</PropertyGroup>

<ItemGroup>
<Compile Include="$(IntermediateOutputPath)AssemblyInfo.cs" />
<Compile Include="..\Mono.Android\Android.Runtime\AndroidRuntimeInternal.cs" />
<Compile Include="..\Mono.Android\Android.Runtime\LogCategories.cs" />
<Compile Include="..\Mono.Android\Android.Runtime\LogLevel.cs" />
<Compile Include="..\Mono.Android\Android.Runtime\RuntimeConstants.cs" />
<Compile Include="..\Mono.Android\Android.Runtime\RuntimeNativeMethods.cs" />
<Compile Include="Android.Runtime\AndroidEnvironmentInternal.cs" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\external\Java.Interop\src\Java.Interop\Java.Interop.csproj" />
</ItemGroup>

<Import Project="Mono.Android.Runtime.targets" />
</Project>
52 changes: 52 additions & 0 deletions src/Mono.Android.Runtime/Mono.Android.Runtime.targets
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<!-- Creates 'AssemblyInfo.cs' with appropriate version information -->
<Target Name="_BuildAssemblyInfo_cs"
DependsOnTargets="GetXAVersionInfo"
BeforeTargets="CoreCompile"
Condition="!Exists ('$(IntermediateOutputPath)AssemblyInfo.cs')"
Inputs="Properties\AssemblyInfo.cs.in"
Outputs="$(IntermediateOutputPath)AssemblyInfo.cs">
<PropertyGroup Condition=" '$(TargetFramework)' == 'monoandroid10' ">
<_PackageVersion>$(ProductVersion)</_PackageVersion>
<_PackageVersionBuild>$(XAVersionCommitCount)</_PackageVersionBuild>
</PropertyGroup>
<PropertyGroup Condition=" '$(TargetFramework)' != 'monoandroid10' ">
<_PackageVersion>$(AndroidPackVersion)</_PackageVersion>
<_PackageVersionBuild>$(PackVersionCommitCount)</_PackageVersionBuild>
</PropertyGroup>
<ReplaceFileContents
SourceFile="Properties\AssemblyInfo.cs.in"
DestinationFile="$(IntermediateOutputPath)AssemblyInfo.cs"
Replacements="@PACKAGE_VERSION@=$(_PackageVersion);@PACKAGE_VERSION_BUILD@=$(_PackageVersionBuild);@PACKAGE_HEAD_REV@=$(XAVersionHash);@PACKAGE_HEAD_BRANCH@=$(XAVersionBranch);@API_LEVEL@=$(AndroidApiLevel);@MIN_API_LEVEL@=$(AndroidMinimumDotNetApiLevel)">
</ReplaceFileContents>
</Target>

<Target Name="_CopyToPackDirs" >
<Copy
SourceFiles="$(OutputPath)ref\Mono.Android.Runtime.dll"
DestinationFolder="$(MicrosoftAndroidRefPackDir)"
SkipUnchangedFiles="true"
/>
<Copy
SourceFiles="$(OutputPath)Mono.Android.Runtime.dll"
DestinationFolder="$(MicrosoftAndroidArmPackDir)lib\$(DotNetTargetFramework)"
SkipUnchangedFiles="true"
/>
<Copy
SourceFiles="$(OutputPath)Mono.Android.Runtime.dll"
DestinationFolder="$(MicrosoftAndroidArm64PackDir)lib\$(DotNetTargetFramework)"
SkipUnchangedFiles="true"
/>
<Copy
SourceFiles="$(OutputPath)Mono.Android.Runtime.dll"
DestinationFolder="$(MicrosoftAndroidx86PackDir)lib\$(DotNetTargetFramework)"
SkipUnchangedFiles="true"
/>
<Copy
SourceFiles="$(OutputPath)Mono.Android.Runtime.dll"
DestinationFolder="$(MicrosoftAndroidx64PackDir)lib\$(DotNetTargetFramework)"
SkipUnchangedFiles="true"
/>
</Target>
</Project>
21 changes: 21 additions & 0 deletions src/Mono.Android.Runtime/Properties/AssemblyInfo.cs.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//
// AssemblyInfo.cs.in
//
// Authors:
// Jonathan Pryor (jonp@xamarin.com)
//
// Copyright 2014 Xamarin, Inc.
// Copyright 2016 Microsoft Corporation.

using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;

[assembly: AssemblyInformationalVersion ("@PACKAGE_VERSION@.@PACKAGE_VERSION_BUILD@; git-rev-head:@PACKAGE_HEAD_REV@; git-branch:@PACKAGE_HEAD_BRANCH@")]
[assembly: AssemblyTitle ("Mono.Android.Runtime.dll")]
[assembly: AssemblyProduct ("Xamarin.Android")]
[assembly: AssemblyCompany ("Microsoft Corporation")]
[assembly: TargetPlatform("Android@API_LEVEL@.0")]
[assembly: SupportedOSPlatform("Android@MIN_API_LEVEL@.0")]

[assembly: InternalsVisibleTo("Mono.Android, PublicKey=0024000004800000940000000602000000240000525341310004000011000000438ac2a5acfbf16cbd2b2b47a62762f273df9cb2795ceccdf77d10bf508e69e7a362ea7a45455bbf3ac955e1f2e2814f144e5d817efc4c6502cc012df310783348304e3ae38573c6d658c234025821fda87a0be8a0d504df564e2c93b2b878925f42503e9d54dfef9f9586d9e6f38a305769587b1de01f6c0410328b2c9733db")]
2 changes: 1 addition & 1 deletion src/Mono.Android/Android.App/SyncContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ static bool EnsureLooper ([NotNullWhen (true)]Looper? looper, SendOrPostCallback
{
if (looper == null) {
var message = $"No Android message loop is available. Skipping invocation of `{d.Method.DeclaringType?.FullName}.{d.Method.Name}`!";
if (JNIEnv.IsRunningOnDesktop)
if (JNIEnvInit.IsRunningOnDesktop)
message += " Using `await` when running on the Android Designer is not currently supported. Please use the `View.IsInEditMode` property.";
Logger.Log (LogLevel.Error, "monodroid-synccontext", message);
return false;
Expand Down
22 changes: 5 additions & 17 deletions src/Mono.Android/Android.Runtime/AndroidEnvironment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -264,17 +264,14 @@ static void GetDisplayDPI (out float x_dpi, out float y_dpi)
//
static string GetDefaultTimeZone ()
{
IntPtr id = _monodroid_timezone_get_default_id ();
IntPtr id = RuntimeNativeMethods._monodroid_timezone_get_default_id ();
try {
return Marshal.PtrToStringAnsi (id)!;
} finally {
JNIEnv.monodroid_free (id);
RuntimeNativeMethods.monodroid_free (id);
}
}

[DllImport (AndroidRuntime.InternalDllName, CallingConvention = CallingConvention.Cdecl)]
static extern IntPtr _monodroid_timezone_get_default_id ();

// This is invoked by
// mscorlib.dll!System.AndroidPlatform.GetDefaultSyncContext()
// DO NOT REMOVE
Expand All @@ -293,35 +290,26 @@ static string GetDefaultTimeZone ()
// These are invoked by
// System.dll!System.AndroidPlatform.getifaddrs
// DO NOT REMOVE
[DllImport (AndroidRuntime.InternalDllName, CallingConvention = CallingConvention.Cdecl)]
static extern int _monodroid_getifaddrs (out IntPtr ifap);

static int GetInterfaceAddresses (out IntPtr ifap)
{
return _monodroid_getifaddrs (out ifap);
return RuntimeNativeMethods._monodroid_getifaddrs (out ifap);
}

// These are invoked by
// System.dll!System.AndroidPlatform.freeifaddrs
// DO NOT REMOVE
[DllImport (AndroidRuntime.InternalDllName, CallingConvention = CallingConvention.Cdecl)]
static extern void _monodroid_freeifaddrs (IntPtr ifap);

static void FreeInterfaceAddresses (IntPtr ifap)
{
_monodroid_freeifaddrs (ifap);
RuntimeNativeMethods._monodroid_freeifaddrs (ifap);
}

[DllImport (AndroidRuntime.InternalDllName, CallingConvention = CallingConvention.Cdecl)]
static extern void _monodroid_detect_cpu_and_architecture (ref ushort built_for_cpu, ref ushort running_on_cpu, ref byte is64bit);

static void DetectCPUAndArchitecture (out ushort builtForCPU, out ushort runningOnCPU, out bool is64bit)
{
ushort built_for_cpu = 0;
ushort running_on_cpu = 0;
byte _is64bit = 0;

_monodroid_detect_cpu_and_architecture (ref built_for_cpu, ref running_on_cpu, ref _is64bit);
RuntimeNativeMethods._monodroid_detect_cpu_and_architecture (ref built_for_cpu, ref running_on_cpu, ref _is64bit);
builtForCPU = built_for_cpu;
runningOnCPU = running_on_cpu;
is64bit = _is64bit != 0;
Expand Down
Loading