Skip to content

Commit 4d17d92

Browse files
committed
Try to make it work at run time
1 parent 4b784e1 commit 4d17d92

File tree

7 files changed

+46
-19
lines changed

7 files changed

+46
-19
lines changed

src/Xamarin.Android.Build.Tasks/Microsoft.Android.Sdk/targets/Microsoft.Android.Sdk.AssemblyResolution.targets

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,7 @@ _ResolveAssemblies MSBuild target.
236236
<_ExcludedNativeLibraries Condition=" '$(_AndroidEnableNativeStackTracing)' != 'true' " Include="libxamarin-native-tracing" />
237237
</ItemGroup>
238238
<ProcessNativeLibraries
239+
NativeRuntimeLinking="$(_AndroidEnableNativeRuntimeLinking)"
239240
InputLibraries="@(_ResolvedNativeLibraries)"
240241
ExcludedLibraries="@(_ExcludedNativeLibraries)"
241242
Components="@(_MonoComponent->Distinct())"

src/Xamarin.Android.Build.Tasks/Microsoft.Android.Sdk/targets/Microsoft.Android.Sdk.NativeRuntime.targets

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,13 @@ Contains code to build and link the native runtime at application build time.
1414
<ItemGroup>
1515
<_UnifiedNativeRuntime Include="$(_AndroidApplicationSharedLibraryPath)%(_BuildTargetAbis.Identity)\libmonodroid-unified.so">
1616
<abi>%(_BuildTargetAbis.Identity)</abi>
17+
<ArchiveFileName>libmonodroid.so</ArchiveFileName>
1718
</_UnifiedNativeRuntime>
1819
</ItemGroup>
1920

2021
<ItemGroup>
2122
<_ResolvedNativeArchive Include="@(ResolvedFileToPublish)" Condition=" '%(ResolvedFileToPublish.Extension)' == '.a' " />
23+
<_ApplicationSharedLibrary Include="@(_UnifiedNativeRuntime)" />
2224
</ItemGroup>
2325

2426
<GetNativeRuntimeComponents

src/Xamarin.Android.Build.Tasks/Tasks/BuildApk.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -713,7 +713,12 @@ void AddRuntimeLibraries (ZipArchiveEx apk, string [] supportedAbis)
713713
foreach (ITaskItem item in ApplicationSharedLibraries) {
714714
if (String.Compare (abi, item.GetMetadata ("abi"), StringComparison.Ordinal) != 0)
715715
continue;
716-
AddNativeLibraryToArchive (apk, abi, item.ItemSpec, Path.GetFileName (item.ItemSpec), item);
716+
string? inArchiveFileName = item.GetMetadata ("ArchiveFileName");
717+
if (String.IsNullOrEmpty (inArchiveFileName)) {
718+
inArchiveFileName = Path.GetFileName (item.ItemSpec);
719+
}
720+
721+
AddNativeLibraryToArchive (apk, abi, item.ItemSpec, inArchiveFileName, item);
717722
}
718723
}
719724
}

src/Xamarin.Android.Build.Tasks/Tasks/ProcessNativeLibraries.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ public class ProcessNativeLibraries : AndroidTask
3030
public string [] ExcludedLibraries { get; set; }
3131

3232
public bool IncludeDebugSymbols { get; set; }
33+
public bool NativeRuntimeLinking { get; set; }
3334

3435
[Output]
3536
public ITaskItem [] OutputLibraries { get; set; }
@@ -64,6 +65,11 @@ public override bool RunTask ()
6465
// We may eventually have files such as `libmono-android-checked+asan.release.so` as well.
6566
var fileName = Path.GetFileNameWithoutExtension (library.ItemSpec);
6667
if (fileName.StartsWith ("libmono-android", StringComparison.Ordinal)) {
68+
if (NativeRuntimeLinking) {
69+
// We don't need the precompiled runtime, it will be linked during application build
70+
continue;
71+
}
72+
6773
if (fileName.EndsWith (".debug", StringComparison.Ordinal)) {
6874
if (!IncludeDebugSymbols)
6975
continue;

src/Xamarin.Android.Build.Tasks/Utilities/NativeRuntimeComponents.cs

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -58,26 +58,29 @@ public NativeRuntimeComponents (ITaskItem[] monoComponents)
5858
this.monoComponents = monoComponents;
5959
KnownArchives = new () {
6060
// Mono components
61-
new MonoComponentArchive ("libmono-component-diagnostics_tracing-static.a", "diagnostics_tracing", MonoComponentPresent),
62-
new MonoComponentArchive ("libmono-component-diagnostics_tracing-stub-static.a", "diagnostics_tracing", MonoComponentAbsent),
63-
new MonoComponentArchive ("libmono-component-marshal-ilgen-static.a", "marshal-ilgen", MonoComponentPresent),
64-
new MonoComponentArchive ("libmono-component-marshal-ilgen-stub-static.a", "marshal-ilgen", MonoComponentAbsent),
61+
new MonoComponentArchive ("libmono-component-debugger-static.a", "debugger", IncludeIfMonoComponentPresent),
62+
new MonoComponentArchive ("libmono-component-debugger-stub-static.a", "debugger", IncludeIfMonoComponentAbsent),
63+
new MonoComponentArchive ("libmono-component-diagnostics_tracing-static.a", "diagnostics_tracing", IncludeIfMonoComponentPresent),
64+
new MonoComponentArchive ("libmono-component-diagnostics_tracing-stub-static.a", "diagnostics_tracing", IncludeIfMonoComponentAbsent),
65+
new MonoComponentArchive ("libmono-component-hot_reload-static.a", "hot_reload", IncludeIfMonoComponentPresent),
66+
new MonoComponentArchive ("libmono-component-hot_reload-stub-static.a", "hot_reload", IncludeIfMonoComponentAbsent),
67+
new MonoComponentArchive ("libmono-component-marshal-ilgen-static.a", "marshal-ilgen", IncludeIfMonoComponentPresent),
68+
new MonoComponentArchive ("libmono-component-marshal-ilgen-stub-static.a", "marshal-ilgen", IncludeIfMonoComponentAbsent),
6569

6670
// MonoVM runtime + BCL
6771
new Archive ("libmonosgen-2.0.a"),
6872
new BclArchive ("libSystem.Globalization.Native.a"),
6973
new BclArchive ("libSystem.IO.Compression.Native.a"),
7074
new BclArchive ("libSystem.Native.a"),
71-
72-
// Can't link whole archive for this one because it contains conflicting JNI_OnLoad
73-
new BclArchive ("libSystem.Security.Cryptography.Native.Android.a", wholeArchive: false),
75+
new BclArchive ("libSystem.Security.Cryptography.Native.Android.a"),
7476

7577
// .NET for Android
76-
new AndroidArchive ("libruntime-base.a"),
77-
new AndroidArchive ("libxa-java-interop.a"),
78-
new AndroidArchive ("libxa-lz4.a"),
79-
new AndroidArchive ("libxa-shared-bits.a"),
80-
new AndroidArchive ("libmono-android.release-static.a"),
78+
new AndroidArchive ("libpinvoke-override-dynamic-release.a"),
79+
new AndroidArchive ("libruntime-base-release.a"),
80+
new AndroidArchive ("libxa-java-interop-release.a"),
81+
new AndroidArchive ("libxa-lz4-release.a"),
82+
new AndroidArchive ("libxa-shared-bits-release.a"),
83+
new AndroidArchive ("libmono-android.release-static-release.a"),
8184
};
8285

8386
// Just the base names of libraries to link into the unified runtime. Must have all the dependencies of all the static archives we
@@ -111,12 +114,12 @@ bool MonoComponentExists (Archive archive)
111114
return false;
112115
}
113116

114-
bool MonoComponentAbsent (Archive archive)
117+
bool IncludeIfMonoComponentAbsent (Archive archive)
115118
{
116119
return !MonoComponentExists (archive);
117120
}
118121

119-
bool MonoComponentPresent (Archive archive)
122+
bool IncludeIfMonoComponentPresent (Archive archive)
120123
{
121124
return MonoComponentExists (archive);
122125
}

src/java-runtime/java/mono/android/MonoPackageManager.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,17 +97,17 @@ public static void LoadApplication (Context context, ApplicationInfo runtimePack
9797
System.loadLibrary ("xamarin-debug-app-helper");
9898
DebugRuntime.init (apks, runtimeDir, appDirs, haveSplitApks);
9999
} else {
100-
System.loadLibrary("monosgen-2.0");
100+
// System.loadLibrary("monosgen-2.0");
101101
}
102-
System.loadLibrary("xamarin-app");
102+
// System.loadLibrary("xamarin-app");
103103

104104
if (!BuildConfig.DotNetRuntime) {
105105
// .net5+ APKs don't contain `libmono-native.so`
106-
System.loadLibrary("mono-native");
106+
// System.loadLibrary("mono-native");
107107
} else {
108108
// for .net6 we temporarily need to load the SSL DSO
109109
// see: https://github.com/dotnet/runtime/issues/51274#issuecomment-832963657
110-
System.loadLibrary("System.Security.Cryptography.Native.Android");
110+
// System.loadLibrary("System.Security.Cryptography.Native.Android");
111111
}
112112

113113
System.loadLibrary("monodroid");
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,12 @@
11
#define PINVOKE_OVERRIDE_INLINE [[gnu::noinline]]
22
#include "pinvoke-override-api.hh"
3+
4+
using namespace xamarin::android;
5+
6+
[[gnu::flatten]]
7+
void*
8+
PinvokeOverride::monodroid_pinvoke_override (const char *library_name, const char *entrypoint_name)
9+
{
10+
// TODO: implement
11+
return nullptr;
12+
}

0 commit comments

Comments
 (0)