Skip to content

Optimize type & member remapping storage, lookup #7020

@jonpryor

Description

@jonpryor

Android application type

Android for .NET (net6.0-android, etc.)

Affected platform version

Description

Context: #6591

Background

PR #6591 fixes dotnet/java-interop#867, but it's largely a "prototype" with great cost to app size:

  • It uses XML as the intermediate format.
  • This XML is parsed during app startup, before most other managed init.
  • Which caused the CheckIncludedAssemblies() test to require updates, adding the assemblies System.Collections.dll, System.Collections.Concurrent.dll, System.Collections.NonGeneric.dll, System.Console.dll, System.IO.Compression.dll, System.Net.Http.dll, System.Net.Primitives.dll, System.Net.Requests.dll, System.Private.Uri.dll, System.Private.Xml.dll, System.Security.Cryptography.dll, and System.Text.RegularExpressions.dll
  • which in turn increase the .apk size; BuildReleaseArm64SimpleDotNet.apkdesc saw PackageSize increase from 2,959,252 bytes to 3,451,764 bytes, an increase of ~17%.

PR #6591 exists to allow further testing. It is not the end state of how things should be.

Proposal

Instead of using XML as an intermediary packaged and parsed within the app, the data should instead be stored within libxamarin-app.so, a'la typemap data.

We would add two new exports to libmonodroid.so:

extern "C" const char *
_monodroid_lookup_replacement_type (const char *jniSimpleReference);

extern "C" const char *
_monodroid_lookup_replacement_method_info (const char *key);

Update/extend the _CollectAndroidRemapMembers target so that instead of creating xa-remap-members.xml as an @(AndroidAsset), xa-remap-members.xml is instead provided as input into whatever creates libxamarin-app.so.

The assembly generator will read <replace-type/> to populate the table used by _monodroid_lookup_replacement_type(). //replace-type/@from will be the key, while //replace-type/@to will be the value.

The assembly generator will read <replace-method/> to populate the table used by _monodroid_lookup_replacement_method_info(). The key to search on will be a tab separated value of:

{@source-type}\t{@source-method-name}\t{@source-method-signature}

The value will be a tab separated value of:

{@target-type}\t{@target-method-name}\t{@target-method-signature}\t{@target-method-parameter-count}\t{@target-method-instance-to-static}

Placing the data into libxamarin-app.so will allow us to revert all changes to JNIEnv.cs, most changes to src/monodroid. AndroidRuntime.cs will need to be updated to use the new _monodroid_lookup_replacement_*() functions instead of the current dictionaries.

Steps to Reproduce

Did you find any workaround?

No response

Relevant log output

No response

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions