Skip to content

[Android][CoreCLR] Use runtimeconfig.bin for runtime configuration lookup in ApkBuilder #118674

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Aug 14, 2025

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Aug 13, 2025

The AndroidAppBuilder was incorrectly looking for {ProjectName}.runtimeconfig.json when the actual generated file is named {AssemblyName}.runtimeconfig.json, causing the CoreCLR Android test host to fail finding the runtime configuration file.

Problem

When building Android apps and especially when running tests:

  • The assembly name differs from the project name
  • For tests, mainLibraryFileName is set to AndroidTestRunner.dll
  • Looking for AndroidTestRunner.runtimeconfig.json for all tests is incorrect as each test project has its own configuration
  • This resulted in errors like: Could not find file 'HelloAndroid.runtimeconfig.json'

Solution

Modified the ParseRuntimeConfigProperties method to use the standardized runtimeconfig.bin file instead of trying to guess the correct JSON filename. This binary file is created by MSBuild's RuntimeConfigParserTask and contains the same configuration properties in a binary format.

The implementation uses the existing BlobReader from System.Reflection.Metadata to read the binary format, which provides the necessary ReadCompressedInteger() and ReadSerializedString() methods that mirror the BlobBuilder write operations.

Before:

string runtimeConfigPath = Path.Combine(AppDir, $"{ProjectName}.runtimeconfig.json");

After:

string runtimeConfigPath = Path.Combine(AppDir, "runtimeconfig.bin");

The solution maintains the same functionality of extracting configProperties for the CoreCLR Android template while working reliably for both apps and test scenarios.

Fixes #118162.


💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.

@Copilot Copilot AI changed the title [WIP] [Android][CoreCLR] Test host has trouble finding runtimeconfig.json Fix AndroidAppBuilder to use assembly name for runtimeconfig.json lookup Aug 13, 2025
@Copilot Copilot AI requested a review from davidnguyen-tech August 13, 2025 12:10
Copilot finished work on behalf of davidnguyen-tech August 13, 2025 12:10
…-specific runtimeconfig.json

Co-authored-by: davidnguyen-tech <[email protected]>
@Copilot Copilot AI changed the title Fix AndroidAppBuilder to use assembly name for runtimeconfig.json lookup Fix AndroidAppBuilder to use runtimeconfig.bin for runtime configuration lookup Aug 13, 2025
@Copilot Copilot AI requested a review from davidnguyen-tech August 13, 2025 12:48
Copilot finished work on behalf of davidnguyen-tech August 13, 2025 12:48
Copilot finished work on behalf of davidnguyen-tech August 13, 2025 13:58
@davidnguyen-tech
Copy link
Member

/azp run runtime-android,runtime-androidemulator

Copy link

Azure Pipelines successfully started running 2 pipeline(s).

@davidnguyen-tech
Copy link
Member

/azp run runtime-android,runtime-androidemulator

Copy link

Azure Pipelines successfully started running 2 pipeline(s).

Copy link
Member

@davidnguyen-tech davidnguyen-tech left a comment

Choose a reason for hiding this comment

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

LGTM

@davidnguyen-tech davidnguyen-tech marked this pull request as ready for review August 14, 2025 10:15
@Copilot Copilot AI review requested due to automatic review settings August 14, 2025 10:15
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR fixes a critical bug in the AndroidAppBuilder where it was incorrectly looking for {ProjectName}.runtimeconfig.json instead of the actual generated file {AssemblyName}.runtimeconfig.json, causing test failures. The solution switches to using the standardized runtimeconfig.bin binary format for runtime configuration lookup.

Key Changes:

  • Modified ParseRuntimeConfigProperties method to read from runtimeconfig.bin instead of guessing JSON filenames
  • Implemented binary format parsing using BlobReader from System.Reflection.Metadata
  • Added unsafe code support to enable direct memory access for efficient binary reading

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

File Description
src/tasks/AndroidAppBuilder/ApkBuilder.cs Replaced JSON-based runtime config parsing with binary format reading using BlobReader
src/tasks/AndroidAppBuilder/AndroidAppBuilder.csproj Added AllowUnsafeBlocks property to enable unsafe code for binary reading
src/tasks/TestExclusionListTasks/TestExclusionListTasks.csproj Added AllowUnsafeBlocks property (appears unrelated to main changes)

You can also share your feedback on Copilot code review for a chance to win a $100 gift card. Take the survey.

Copy link
Contributor

Tagging subscribers to this area: @hoyosjs
See info in area-owners.md if you want to be subscribed.

@davidnguyen-tech davidnguyen-tech merged commit edb570c into main Aug 14, 2025
158 of 167 checks passed
@davidnguyen-tech davidnguyen-tech deleted the copilot/fix-118162 branch August 14, 2025 15:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

[Android][CoreCLR] Test host has trouble finding runtimeconfig.json
4 participants