Open mosammo opened 1 year ago
@mosammo from your description it appears that trimming is removing some type that your application uses. In order to be certain, we will need two kinds of logs from you:
Build log. In order to create it, build your application from the VS developer prompt using the command below:
dotnet build -c Release -bl
and attach the resulting msbuild.binlog
file
The Android logcat output. From the VS developer prompt, follow these steps:
dotnet build -c Release -t Install
adb logcat -G 16M
adb shell setprop debug.mono.log default,assembly,mono_log_level=debug,mono_log_mask=all
adb logcat -c
adb logcat -d > logcat.txt
and attach the resulting logcat.txt
file.
Please find the logs attached: "msbuild.binlog" and the "logcat.txt" (saved the logcat 3 times after 3 crashes just to make sure everything is logged) logs.zip
@mosammo thank you for the logs. It seems that assemblies are packaged into the apk but then they don't appear to be found in it on device. Could you repeat the steps in 2.
above, but replace the installation step with:
dotnet build -c Release -t Install -bl
and attach the resulting msbuild.binlog
@mosammo
Generally speaking using PublishTrimmed
in a Debug configuration might cause some issues. Its not a configuration we would expect to use when debugging.
I would take a look at https://learn.microsoft.com/en-us/dotnet/maui/android/linking?tabs=vs. It talks about maui, but it applies to typical .net andorid apps too. Specifically sections on preserving code and assemblies.
What I suspect is happening is some of your types are being removed and your app crashed when using PublishTrimmed, so you turned that setting on in debug mode to see if you can debug the issue in the IDE. I'm not sure that will work. That you can do is look at the adb logcat
output and find the point where its crashing in Release mode. It should mention the types which are missing (because the linker removed them), then you can follow the advice in the links provided to add additional instructions to the linker to preserve the code which is needed.
@dellis1972 @grendello I followed the same steps on the real project and got the following logcat error "failed to load assembly System.Private.CoreLib.dll" although I already have <TrimmerRootAssembly Include="System.Private.CoreLib" />
in the project file so i don't know why it's not included in the published release apk
please find the logs from the real project :
logs 1810 main.zip
The msbuild.binlog contains the following error.
The imported project "C:\Program Files\dotnet\sdk\7.0.400-preview.23330.10\Microsoft\Portable\v4.6\Microsoft.Portable.CSharp.targets" was not found. Confirm that the expression in the Import declaration "C:\Program Files\dotnet\sdk\7.0.400-preview.23330.10\Microsoft\Portable\v4.6\Microsoft.Portable.CSharp.targets" is correct, and that the file exists on disk.
Are you trying to build a PCL library with dotnet
? I'm not sure that is even supported. Looks like you are trying to mix sdk style projects with the old classic project system. You will need to upgrade all your projects to be sdk style (the short which uses <Project Sdk="Microsoft.NET.Sdk">
) in order to upgrde to .net 7.
The project was previously portable but i already converted it and the android project to .net SDK, so all projects in the solution are now .net sdk. I got the error "Microsoft.Portable.CSharp.targets" before but after clean and rebuild the error was gone. Here's a clean binary log after clean and rebuild
Thanks for the logs. One slight issue is it wasn't from a clean build. So some of the targets were skipped. The result is we cannot figure out what was added to the apk in this instance.
Any chance you can do the same again but this time from a completely clean build ?
Sure, I'll do anything needed. This time manually deleted both "bin" and "obj" folders from all projects, then cleaned solution then rebuilt solution. logs 1018 -3.zip
@grendello something weird is going on. The blob
is not making it into the apk. Its not even in the list of files given to the BuildApk
task.
Hmm UseAssemblyStore
is false.
any clue?
is there a way to not trim the platform specific blob and only trim the main "assemblies.blob"? if not is there a way the we can replace the "assemblies.blob" of the not trimmed apk with the "assemblies.blob" of the trimmed apk? as i checked "assemblies.blob" alone is 60 MB and in trimmed apk it's 30 MB so if we can only trim "assemblies.blob" it will be enough for most people having this trimming issue
Android application type
.NET Android (net7.0-android, etc.)
Affected platform version
VS 2022 17.6.2+, .Net for Android 7+
Description
Enabling "Publish trimmed" without "fast-deployment debug" with Xamain forms apk causes the apk to crash without showing any errors.
Expected Behavior: Apk should work normally without crashing. especially that it works without crashing if we disabled "Publish Trimmed" or if we enable "Fast-deployment debug".
Steps to Reproduce
Steps to Reproduce:
Did you find any workaround?
No
Relevant log output
No response