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

Related to "proguard rules embedded in binding projects are lost" #4449 #5310 #8523

Closed
awattar opened this issue Nov 19, 2023 · 14 comments
Closed
Assignees
Labels
Area: App+Library Build Issues when building Library projects or Application projects. need-info Issues that need more information from the author.

Comments

@awattar
Copy link

awattar commented Nov 19, 2023

Android application type

.NET Android (net7.0-android, etc.)

Affected platform version

VSMac 17.6.7 (build 417), VSWin 17.8.0, .NET 7.0.402

Description

When building MS.Android net7 Platfrom/Maui app with ProGuard/R8 enabled in release rules from dependent binding library containing library level ProGuard are not taken into account or malformed.

App crashes on runtime.

Related to #4449 and #5310.

Steps to Reproduce

  1. Remove bin/obj from relevant projects/subprojects.
  2. Clean project in VSMac/VSWin/CLI.
  3. Restore project in VSMac/VSWIn/CLI.
  4. Build project in VSMac/VSWin/CLI.
  5. Deploy project in VSMac/VSWIn/CLI.
  6. Run app in VSMac/VSWin/CLI.
  7. Runtime crash.

Going straight to VS deploy (CLI -t:Run) for the removed bin/obj folders also doesn't work.

It seems that restore + build causes creation of malformed mapping.txt (in bin framework/platform/architecture subfolder) file. FIle is significantly smaller than the working file +- 20%.

Did you find any workaround?

App must be explicitly rebuild (instead of build) or additional --no-incremental option must be added to CLI dotnet build. It seems that some targets related to the ProGuard/R8 are not invoked fully or in the wrong moment for builds after project restore. Probably those builds are treated as incremental and due to some performance optimisations not all rules are taken into account.

Relevant log output

No response

@awattar awattar added Area: App+Library Build Issues when building Library projects or Application projects. needs-triage Issues that need to be assigned. labels Nov 19, 2023
@jonathanpeppers
Copy link
Member

Can you share a sample project that shows this problem? Thanks!

@jonathanpeppers jonathanpeppers added need-info Issues that need more information from the author. and removed needs-triage Issues that need to be assigned. labels Nov 27, 2023
@awattar
Copy link
Author

awattar commented Nov 30, 2023

@jonathanpeppers Will try to share something but first will check it on net8.

@microsoft-github-policy-service microsoft-github-policy-service bot added need-attention A xamarin-android contributor needs to review and removed need-info Issues that need more information from the author. labels Nov 30, 2023
@jpobst jpobst added need-info Issues that need more information from the author. and removed need-attention A xamarin-android contributor needs to review labels Dec 13, 2023
@awattar
Copy link
Author

awattar commented Dec 14, 2023

Was able to reproduce it on NET8. Will work on sample to share.

@microsoft-github-policy-service microsoft-github-policy-service bot added need-attention A xamarin-android contributor needs to review and removed need-info Issues that need more information from the author. labels Dec 14, 2023
@jpobst jpobst added need-info Issues that need more information from the author. and removed need-attention A xamarin-android contributor needs to review labels May 17, 2024
@awattar
Copy link
Author

awattar commented May 20, 2024

Will retest on latest workloads and let you know.

@microsoft-github-policy-service microsoft-github-policy-service bot added need-attention A xamarin-android contributor needs to review and removed need-info Issues that need more information from the author. labels May 20, 2024
@awattar
Copy link
Author

awattar commented May 24, 2024

@jpobst @jonathanpeppers I've retested on everything being updated (dotnet, workloads, VSMac, VSWin, etc.) and it can be easily reproduced on VSMac, VSWin and CLI builds.

I've uploaded samples and mappings files in the private comment in this ticket https://developercommunity.visualstudio.com/t/Code-sample-for-https:githubcomxamar/10666925

@jonathanpeppers jonathanpeppers added this to the Under Consideration milestone Jun 18, 2024
@jonathanpeppers
Copy link
Member

@awattar sorry for the delay. I'm able to run XamarinForms\Examples\SampleAppSuite\SampleAppSuite.Droid.csproj in Release mode and make it to this screen:

image

Are there more specific steps to see the problem here? Can you share the steps in terms of dotnet build commands?

A tester was also unsuccessful in reproducing the issue.

@jonathanpeppers jonathanpeppers added need-info Issues that need more information from the author. and removed need-attention A xamarin-android contributor needs to review labels Jul 11, 2024
@awattar
Copy link
Author

awattar commented Jul 12, 2024

@jonathanpeppers tried to reach you on Discord - but no response to my DM.

You need to run into "incremental" mode. Please try this scenario:

  1. Remove bin/obj folders in Droid subfolder.
  2. Open VSMac and restore NuGets for solution using "Restore NuGet Packages" option.
  3. Go to terminal then cd to Droid solution subfolder with Droid csproj and run this command there:
    dotnet build -t:Run -c Release -f net8.0-android34.0
    while only one physical Android device is attached or add -p:AdbTarget="-s insert_SERIAL_here" when more than one physical device is connected.

App will deploy and run and will crash immediately with log entries suggesting proguard issue - also mapping.txt will have different size than normal.

@dotnet-policy-service dotnet-policy-service bot added need-attention A xamarin-android contributor needs to review and removed need-info Issues that need more information from the author. labels Jul 12, 2024
@jonathanpeppers
Copy link
Member

Is VS Mac required to cause the problem here? VS Mac is retiring next month:

You need to run into "incremental" mode

The steps above are a fresh build. In what way is it incremental?

@awattar
Copy link
Author

awattar commented Jul 15, 2024

@jonathanpeppers No VSMac is not required but this is a 100% repro.

This is a "incremental" build in the way that if you add --no-incremental to the above command it will work - see my initial description.

I can provide another scenario if you can't work on this one.

@jonathanpeppers
Copy link
Member

Proguard/R8 rules do not do anything in Debug mode. So, do the above steps need to be done in Release mode?

--no-incremental is equivalent to -t:Rebuild:

So, can your steps above be reduced to:

  • Fresh clone (or unzip) of project
  • dotnet build XamarinForms\Examples\SampleAppSuite\SampleAppSuite.Droid.csproj -c Release -t:Run
  • Application launches successfully
  • dotnet build XamarinForms\Examples\SampleAppSuite\SampleAppSuite.Droid.csproj -c Release -t:Run (a second time)
  • Application crashes on launch

@awattar
Copy link
Author

awattar commented Jul 15, 2024

@jonathanpeppers Yes Release was specified in the previous post #8523 (comment) to make proguard/R8 work.

Regarding the steps you have provided I'm not quite sure - I believe it has something to do with separate initial Restore - so it builds some cache or sth from referenced NuGets then it treats consecutive build and -t:Run incrementally so it does not fully recreate proguard mappings.

Please try scenario with VSMac if you can.

@jonathanpeppers
Copy link
Member

@awattar now that VS Mac is sunset, unsupported. Is there another way to reproduce this issue?

@jonathanpeppers jonathanpeppers added need-info Issues that need more information from the author. and removed need-attention A xamarin-android contributor needs to review labels Nov 6, 2024
Copy link

Hi @awattar. We have added the "need-info" label to this issue, which indicates that we have an open question for you before we can take further action. This issue will be closed automatically in 7 days if we do not hear back from you by then - please feel free to re-open it if you come back to this issue after that time.

Copy link

Hi @awattar. Due to inactivity, we will be closing this issue. Please feel free to re-open this issue if the issue persists. For enhanced visibility, if over 7 days have passed, please open a new issue and link this issue there. Thank you.

@dotnet-policy-service dotnet-policy-service bot removed this from the Under Consideration milestone Nov 14, 2024
@github-actions github-actions bot locked and limited conversation to collaborators Dec 14, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Area: App+Library Build Issues when building Library projects or Application projects. need-info Issues that need more information from the author.
Projects
None yet
Development

No branches or pull requests

4 participants