Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
40 changes: 1 addition & 39 deletions src/Xamarin.Android.Build.Tasks/Utilities/JCWGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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<AndroidTargetArch, NativeCodeGenState> javaStubStates)
{
if (javaStubStates.Count <= 1) {
Expand Down
13 changes: 12 additions & 1 deletion src/java-runtime/java/mono/android/MonoPackageManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Copy link
Member Author

Choose a reason for hiding this comment

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

This API is "internal" and fine to change parameters?

Copy link
Contributor

Choose a reason for hiding this comment

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

It should be "internal", in that "nobody other than us" should be invoking it…

If nobody hits it in .NET 10 previews, it's fine! 🤪

{
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;
}
Expand Down
Loading