diff --git a/src/Xamarin.Android.Build.Tasks/Resources/MonoRuntimeProvider.Bundled.java b/src/Xamarin.Android.Build.Tasks/Resources/MonoRuntimeProvider.Bundled.java index 2af2fef566b..5660876e513 100644 --- a/src/Xamarin.Android.Build.Tasks/Resources/MonoRuntimeProvider.Bundled.java +++ b/src/Xamarin.Android.Build.Tasks/Resources/MonoRuntimeProvider.Bundled.java @@ -18,19 +18,7 @@ public boolean onCreate () @Override public void attachInfo (android.content.Context context, android.content.pm.ProviderInfo info) { - // Mono Runtime Initialization {{{ - android.content.pm.ApplicationInfo applicationInfo = context.getApplicationInfo (); - String[] apks = null; - String[] splitApks = applicationInfo.splitSourceDirs; - if (splitApks != null && splitApks.length > 0) { - apks = new String[splitApks.length + 1]; - apks [0] = applicationInfo.sourceDir; - System.arraycopy (splitApks, 0, apks, 1, splitApks.length); - } else { - apks = new String[] { applicationInfo.sourceDir }; - } - mono.MonoPackageManager.LoadApplication (context, applicationInfo, apks); - // }}} + mono.MonoPackageManager.LoadApplication (context); super.attachInfo (context, info); } diff --git a/src/Xamarin.Android.Build.Tasks/Utilities/JCWGenerator.cs b/src/Xamarin.Android.Build.Tasks/Utilities/JCWGenerator.cs index ba9e9bde3a5..f088c6be137 100644 --- a/src/Xamarin.Android.Build.Tasks/Utilities/JCWGenerator.cs +++ b/src/Xamarin.Android.Build.Tasks/Utilities/JCWGenerator.cs @@ -99,7 +99,7 @@ bool ProcessTypes (bool generateCode, string androidSdkPlatform, MarshalMethodsC throw new ArgumentException ("must not be null or empty", nameof (outputPath)); } - string monoInit = GetMonoInitSource (androidSdkPlatform); + string monoInit = "mono.MonoPackageManager.LoadApplication (context);"; bool hasExportReference = context.ResolvedAssemblies.Any (assembly => Path.GetFileName (assembly.ItemSpec) == "Mono.Android.Export.dll"); bool ok = true; @@ -185,44 +185,6 @@ CallableWrapperType CreateGenerator (TypeDefinition type, MarshalMethodsClassifi return CecilImporter.CreateType (type, context.TypeDefinitionCache, reader_options); } - static string GetMonoInitSource (string androidSdkPlatform) - { - if (String.IsNullOrEmpty (androidSdkPlatform)) { - throw new ArgumentException ("must not be null or empty", nameof (androidSdkPlatform)); - } - - // Lookup the mono init section from MonoRuntimeProvider: - // Mono Runtime Initialization {{{ - // }}} - var builder = new StringBuilder (); - var runtime = "Bundled"; - var api = ""; - if (int.TryParse (androidSdkPlatform, out int apiLevel) && apiLevel < 21) { - api = ".20"; - } - - var assembly = Assembly.GetExecutingAssembly (); - using var s = assembly.GetManifestResourceStream ($"MonoRuntimeProvider.{runtime}{api}.java"); - using var reader = new StreamReader (s); - bool copy = false; - string? line; - while ((line = reader.ReadLine ()) != null) { - if (string.CompareOrdinal ("\t\t// Mono Runtime Initialization {{{", line) == 0) { - copy = true; - } - - if (copy) { - builder.AppendLine (line); - } - - if (string.CompareOrdinal ("\t\t// }}}", line) == 0) { - break; - } - } - - return builder.ToString (); - } - public static void EnsureAllArchitecturesAreIdentical (TaskLoggingHelper logger, ConcurrentDictionary javaStubStates) { if (javaStubStates.Count <= 1) { diff --git a/src/java-runtime/java/mono/android/MonoPackageManager.java b/src/java-runtime/java/mono/android/MonoPackageManager.java index fa6ed7be7fc..eb751da3a82 100644 --- a/src/java-runtime/java/mono/android/MonoPackageManager.java +++ b/src/java-runtime/java/mono/android/MonoPackageManager.java @@ -26,9 +26,20 @@ public class MonoPackageManager { static android.content.Context Context; - public static void LoadApplication (Context context, ApplicationInfo runtimePackage, String[] apks) + public static void LoadApplication (Context context) { synchronized (lock) { + android.content.pm.ApplicationInfo runtimePackage = context.getApplicationInfo (); + String[] apks = null; + String[] splitApks = runtimePackage.splitSourceDirs; + if (splitApks != null && splitApks.length > 0) { + apks = new String[splitApks.length + 1]; + apks [0] = runtimePackage.sourceDir; + System.arraycopy (splitApks, 0, apks, 1, splitApks.length); + } else { + apks = new String[] { runtimePackage.sourceDir }; + } + if (context instanceof android.app.Application) { Context = context; }