maui icon indicating copy to clipboard operation
maui copied to clipboard

App crashes on startup when R8 shrinker is set in Maui - Release mode

Open Banurega opened this issue 2 years ago • 12 comments
trafficstars

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 avatar Feb 17 '23 09:02 Banurega

@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

jfversluis avatar Feb 17 '23 14:02 jfversluis

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.

ghost avatar Feb 17 '23 14:02 ghost

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.

Banurega avatar Feb 17 '23 15:02 Banurega

@jonathanpeppers

PureWeen avatar Feb 23 '23 19:02 PureWeen

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.

ghost avatar Feb 23 '23 19:02 ghost

@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.

jonathanpeppers avatar Feb 23 '23 20:02 jonathanpeppers

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.

ghost avatar Feb 24 '23 19:02 ghost

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.

ghost avatar Feb 28 '23 20:02 ghost

@jonathanpeppers Please find attached log file for your reference. log.txt

Banurega avatar Mar 02 '23 09:03 Banurega

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

jonathanpeppers avatar Mar 06 '23 18:03 jonathanpeppers

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.

ghost avatar Mar 06 '23 18:03 ghost

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.

ghost avatar Mar 10 '23 19:03 ghost

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 avatar Mar 14 '23 07:03 Banurega

@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 avatar Mar 14 '23 15:03 jonathanpeppers

@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 avatar Mar 20 '23 01:03 Banurega

@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.

jonathanpeppers avatar Mar 20 '23 13:03 jonathanpeppers