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
1 change: 1 addition & 0 deletions src/tasks/AndroidAppBuilder/AndroidAppBuilder.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<EnableDefaultCompileItems>false</EnableDefaultCompileItems>
<Nullable>enable</Nullable>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<NoWarn>$(NoWarn),CA1050,CA1850</NoWarn>
</PropertyGroup>
<ItemGroup>
Expand Down
28 changes: 21 additions & 7 deletions src/tasks/AndroidAppBuilder/ApkBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.IO;
using System.IO.Compression;
using System.Linq;
using System.Reflection.Metadata;
using System.Text;
using System.Text.Json;
using System.Text.RegularExpressions;
Expand Down Expand Up @@ -705,19 +706,32 @@ private string RenderMonodroidCoreClrTemplate(string monodroidContent)

private Dictionary<string, string> ParseRuntimeConfigProperties()
{
// This method reads the binary runtimeconfig.bin file created by RuntimeConfigParserTask.ConvertDictionaryToBlob.
// The binary format is: compressed integer count, followed by count pairs of length-prefixed UTF8 strings (key, value).
// See src/tasks/MonoTargetsTasks/RuntimeConfigParser/RuntimeConfigParser.cs for the corresponding write logic.

var configProperties = new Dictionary<string, string>();
string runtimeConfigPath = Path.Combine(AppDir ?? throw new InvalidOperationException("AppDir is not set"), $"{ProjectName}.runtimeconfig.json");
string runtimeConfigPath = Path.Combine(AppDir ?? throw new InvalidOperationException("AppDir is not set"), "runtimeconfig.bin");

try
{
string jsonContent = File.ReadAllText(runtimeConfigPath);
using JsonDocument doc = JsonDocument.Parse(jsonContent);
JsonElement root = doc.RootElement;
if (root.TryGetProperty("runtimeOptions", out JsonElement runtimeOptions) && runtimeOptions.TryGetProperty("configProperties", out JsonElement propertiesJson))
byte[] fileBytes = File.ReadAllBytes(runtimeConfigPath);
unsafe
{
foreach (JsonProperty property in propertiesJson.EnumerateObject())
fixed (byte* ptr = fileBytes)
{
configProperties[property.Name] = property.Value.ToString();
var blobReader = new BlobReader(ptr, fileBytes.Length);

// Read the compressed integer count
int count = blobReader.ReadCompressedInteger();

// Read each key-value pair
for (int i = 0; i < count; i++)
{
string key = blobReader.ReadSerializedString() ?? string.Empty;
string value = blobReader.ReadSerializedString() ?? string.Empty;
configProperties[key] = value;
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
<EnableDefaultCompileItems>false</EnableDefaultCompileItems>
<Nullable>enable</Nullable>
<NoWarn>$(NoWarn),CA1050,CA1850</NoWarn>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>

<ItemGroup>
Expand Down
Loading