Skip to content
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

[Xamarin.Android.Build.Tasks] fix Debug mode and $(PublishTrimmed) #9452

Merged
merged 2 commits into from
Oct 30, 2024

Conversation

jonathanpeppers
Copy link
Member

@jonathanpeppers jonathanpeppers commented Oct 23, 2024

There is a problem if you have the combination:

  • Configuration=Debug

  • PublishTrimmed=true

We emit an XA0119 warning with this combination, as there is not a good reason to do it.

But unfortunately, the build will be completely broken as all the .NET assemblies don't make it to the .apk! I could reproduce this in a test.

The fix is that the logic in the <ProcessAssemblies/> MSBuild task:

if (PublishTrimmed && !AndroidIncludeDebugSymbols) {
    //...
    ShrunkAssemblies = shrunkAssemblies.ToArray ();
}

Has a case, where we did not fill out the ShrunkAssemblies [Output] item group:

if (!AndroidIncludeDebugSymbols) {
    // existing logic...
} else {
    ShrunkAssemblies = OutputAssemblies;
}

Going forward, we could probably refactor some of this logic to make things simpler, but this is a reasonable fix for now.

[Test]
public void CheckDebugModeWithTrimming ()
{
bool usesAssemblyStores = false;
Copy link
Contributor

Choose a reason for hiding this comment

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

Did you want to make this a parameter? The value never changes from false.

Copy link
Member Author

Choose a reason for hiding this comment

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

The test didn't work with true, it doesn't seem to find any assembly stores. This could be another bug? But I manually checked and saw the assemblies inside.

Copy link
Contributor

Choose a reason for hiding this comment

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

It doesn't find any assembly stores because there are no assemblies in the build (the _Shrunk* item groups are empty)

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 change fixes the @(_Shrunk*) item groups, I see them inside the _PrepareAssemblies target now:

image

Copy link
Contributor

Choose a reason for hiding this comment

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

Must be with FastDev enabled, because without it I don't see the _Shrunk* groups populated :(

@jonathanpeppers

This comment was marked as outdated.

@jonathanpeppers jonathanpeppers marked this pull request as draft October 23, 2024 15:36
@grendello

This comment was marked as outdated.

There is a problem if you have the combination:

* `Configuration=Debug`

* `PublishTrimmed=true`

We emit an `XA0119` warning with this combination, as there is not a
good reason to do it.

But unfortunately, the build will be completely broken as all the .NET
assemblies don't make it to the `.apk`! I could reproduce this in a
test.

The fix is that the logic in the `<ProcessAssemblies/>` MSBuild task
needs to match the logic in the `_PrepareAssemblies` MSBuild target:

    if (PublishTrimmed && !AndroidIncludeDebugSymbols) {
        //...
        ShrunkAssemblies = shrunkAssemblies.ToArray ();
    }

Should match:

    <ItemGroup Condition=" '$(PublishTrimmed)' == 'true' and '$(AndroidIncludeDebugSymbols)' != 'true' ">

With the preceding `<ItemGroup>` having the inverse of this `Condition`.

Going forward, we could probably refactor some of this logic to make
things simpler, but this is a reasonable fix for now.
@jonathanpeppers

This comment was marked as outdated.

Try the fix a different way
@jonathanpeppers
Copy link
Member Author

Ok, the fix was actually in C#, in the <ProcessAssemblies/> task. I updated the PR description.

@jonathanpeppers jonathanpeppers marked this pull request as ready for review October 28, 2024 18:02
grendello added a commit that referenced this pull request Oct 28, 2024
@grendello grendello merged commit 1417776 into dotnet:main Oct 30, 2024
55 of 57 checks passed
@jonathanpeppers jonathanpeppers deleted the DebugModeTrimming branch October 30, 2024 16:29
jonathanpeppers added a commit that referenced this pull request Nov 8, 2024
…9452)

There is a problem if you have the combination:

* `Configuration=Debug`

* `PublishTrimmed=true`

We emit an `XA0119` warning with this combination, as there is not a good reason to do it.

But unfortunately, the build will be completely broken as all the .NET assemblies don't make it to the `.apk`! I could reproduce this in a test.

The fix is that the logic in the `<ProcessAssemblies/>` MSBuild task:

    if (PublishTrimmed && !AndroidIncludeDebugSymbols) {
        //...
        ShrunkAssemblies = shrunkAssemblies.ToArray ();
    }

Has a case, where we did not fill out the `ShrunkAssemblies` `[Output]` item group:

    if (!AndroidIncludeDebugSymbols) {
        // existing logic...
    } else {
        ShrunkAssemblies = OutputAssemblies;
    }

Going forward, we could probably refactor some of this logic to make things simpler, but this is a reasonable fix for now.
@github-actions github-actions bot locked and limited conversation to collaborators Nov 30, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants