maui
maui copied to clipboard
App crashes on startup when R8 shrinker is set in Maui - Release mode
Description
**App crashes on startup when R8 shrinker is set in Maui - Release mode #12330 --> reopening this issue **
Steps to Reproduce
1.Create a Maui app for net7.0-android/net6.0-android. 2.Enable R8 for Release configuration. 3.Set sample values in secure storage in App.xaml.cs file 3.Build the app for Release configuration. 4.Check the device log
Link to public reproduction project repository
https://github.com/Banurega/MauiSampleApp
Version with bug
7.0 (current)
Last version that worked well
Unknown/Other
Affected platforms
iOS, Android
Affected platform versions
Android 11 and up, VS2022
Did you find any workaround?
No response
Relevant log output
No response
@Banurega the previous issue was closed because we gave you some information and asked if you could let us know if that information helped. You can see it here: https://github.com/dotnet/maui/issues/12330#issuecomment-1372646577
Could you please have a look at that and see if it helps, if not, please let us know what the outcome is of what you tried? Did it change anything? Got any additional information? Thanks
Hi @Banurega. We have added the "s/needs-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.
Hi @jfversluis, Thank you for your response. Yes, I have tried the solution that given for closed issue (https://github.com/dotnet/runtime/issues/79910#issuecomment-1363180624). but solution does not work in my case. The issue I encounter is only when I enable R8 Code Shrinker and use SecureStorage (Maui.Essential) in my code. I guess there was a relation between these two. I wondee, to deploy app there may need basic security. Appreciate your response and please try the scenario that I mentioned.
@jonathanpeppers
We've moved this issue to the Backlog milestone. This means that it is not going to be worked on for the coming release. We will reassess the backlog following the current release and consider this item at that time. To learn more about our issue management process and to have better expectation regarding different types of issues you can read our Triage Process.
@Banurega can you share a log of the crash?
adb logcat -c
adb shell setprop debug.mono.log default,assembly,mono_log_level=debug,mono_log_mask=all
# Launch the app, cause the crash
adb logcat -d > log.txt
There is likely just a Java type missing that needs to be preserved via a proguard.cfg file. There are some old details on this doc that apply to r8:
https://learn.microsoft.com/xamarin/android/deploy-test/release-prep/proguard
This is pretty standard for enabling r8 in apps, but we could potentially add this to the built-in proguard rules for MAUI. The issue is it would unconditionally preserve Java code for all MAUI apps, even apps not using Maui.Essentials.SecureStorage.
Hi @Banurega. We have added the "s/needs-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.
This issue has been automatically marked as stale because it has been marked as requiring author feedback but has not had any activity for 4 days. It will be closed if no further activity occurs within 3 days of this comment. If it is closed, feel free to comment when you are able to provide the additional information and we will re-investigate.
@jonathanpeppers Please find attached log file for your reference. log.txt
The error is:
java.lang.NoSuchFieldError: no "Landroidx/security/crypto/EncryptedSharedPreferences$PrefKeyEncryptionScheme;" field "AES256_SIV" in class "Landroidx/security/crypto/EncryptedSharedPreferences$PrefKeyEncryptionScheme;" or its superclasses
@Banurega have you already tried adding a proguard.cfg file to preserve this?
-keepmembers public class androidx.security.crypto.** {
public <fields>;
}
This should preserve all fields for types in the androidx.security.crypto package.
In .NET 7, you should be able to just put a proguard.cfg file in your project to be picked up automatically:
https://github.com/xamarin/xamarin-android/commit/c537dd28c30f482f365ef756214be35aa1553da2
There are some other examples of ProGuard rules here: https://stackoverflow.com/questions/48509393/proguard-keep-public-classes-fields-and-methods
Hi @Banurega. We have added the "s/needs-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.
This issue has been automatically marked as stale because it has been marked as requiring author feedback but has not had any activity for 4 days. It will be closed if no further activity occurs within 3 days of this comment. If it is closed, feel free to comment when you are able to provide the additional information and we will re-investigate.
Hi, Sorry for the late response.. I have tried adding prograud.cfg file in main project though still app crashes.. I have attached sample file [https://github.com/Banurega/MauiApp4] that I tried to reproduce. Please take a look.
@Banurega what is the new error?
Do you still see java.lang.NoSuchFieldError: no "Landroidx/security/crypto/EncryptedSharedPreferences$PrefKeyEncryptionScheme;" field "AES256_SIV" in class "Landroidx/security/crypto/EncryptedSharedPreferences$PrefKeyEncryptionScheme;" or its superclasses?
@jonathanpeppers Yes, I encounter the same error.. U can check my sample project attached on my previous comment. Please let me know if u need any additional info
@Banurega the sample above does not have any proguard rules. Can you update with the file you actually used?
It sounds like the AES256_SIV field was not preserved if you got the same error.