Open Closed

ABP 8.1.3 or 8.2.2 MAUI app hangs on splash screen with Android release #7766


User avatar
0
richard.harrison@brightserve.com created
  • ABP Framework version: v8.1.3 or 8.2.2
  • UI Type: MAUI
  • Database System: EF Core SQL Server
  • Tiered (for MVC) or Auth Server Separated (for Angular): yes/no
  • Steps to reproduce the issue:
  • Visual Studio 2022
  • .NET SDK 8.0.401
  • Create new project using ABP SUITE. Run app in Release on Android emulator or Android Device; splash screen displays and app hangs; logcat shows no activity

I've tried this with both the old ABP SUITE (web based) and the new ABP suite beta app.


8 Answer(s)
  • User Avatar
    0
    liangshiwei created
    Support Team Fullstack Developer

    Hi,

    Maybe related to this: https://abp.io/support/questions/6409/Mobile-MAUI-Android-Release-build-stuck-on-splash

  • User Avatar
    0

    I will investigate this thanks for the link

  • User Avatar
    0
    liangshiwei created
    Support Team Fullstack Developer

    okay

  • User Avatar
    0

    Using AsyncHelper.RunAsync is possibly not a good idea as I think it could lead to deadlocks; however I cannot prove that this is happening.

    The last comment in the thread https://abp.io/support/questions/6409/Mobile-MAUI-Android-Release-build-stuck-on-splash said "we'll update the template according to this information, thanks for this key point" and yet 8 months later GetClaimsPrincipal still isn't async.

    After much debugging and experimentation it appears that SecureStorage is the problem; if I change the DefaultStorage.cs module to use SecureStorage instead of Preferences then the debug app also locks up; not sure why but possibly because it is called too early in the startup sequence or maybe because it is called from GetClaimsPrincipal which is not an async method and using AsyncHelper.RunSync(() => is probably not a safe way of using an async method.

    I think it is therefore sensible to change GetClaimsPrincipal to be async.

    I've tried on different Android versions, API 27 and API 30

  • User Avatar
    0
    liangshiwei created
    Support Team Fullstack Developer

    Hi

    Using AsyncHelper.RunAsync is possibly not a good idea as I think it could lead to deadlocks; however I cannot prove that this is happening.

    AsyncHelper is designed for this situations, so it won't be a problem.

    The last comment in the thread https://abp.io/support/questions/6409/Mobile-MAUI-Android-Release-build-stuck-on-splash said "we'll update the template according to this information, thanks for this key point" and yet 8 months later GetClaimsPrincipal still isn't async.

    Unfortunately, this is the framework's design, and it's not easy to change it.

    I will test it locally

  • User Avatar
    0
    liangshiwei created
    Support Team Fullstack Developer

    Hi,

    i could not reproduce the problem.

    • create a new project via suite
    • adb reverse tcp:port tcp:port
    • run backend

    Update DefaultStorage

    public class DefaultStorage : IStorage, ITransientDependency
    {
        public async Task<string> GetAsync(string key)
        {
            return Preferences.Get(key, string.Empty);
        }
    
        public async Task SetAsync(string key, string value)
        {
            if (value.IsNullOrEmpty())
            {
                await RemoveAsync(key);
                return;
            }
    
            Preferences.Set(key, value);
        }
    
        public Task RemoveAsync(string key)
        {
            Preferences.Remove(key);
            return Task.CompletedTask;
        }
    }
    
    • Remove #if DEBUG code block
    • Change mode to Release
  • User Avatar
    0

    That's effectively what I did to get it to run; however it would be nice to understand why SecureStorage doesn't work in a clean ABP suite generated application (8.2.2)

    #define USE_PREFERENCES
    
    using Volo.Abp.DependencyInjection;
    
    namespace BrightServe.Maui.Shared.Storage;
    
    public class DefaultStorage : IStorage, ITransientDependency
    {
        public async Task<string> GetAsync(string key)
        {
    #if USE_PREFERENCES
            return Preferences.Get(key, string.Empty);
    #else
            return await SecureStorage.Default.GetAsync(key);
    #endif
        }
    
        public async Task SetAsync(string key, string value)
        {
            if (value.IsNullOrEmpty())
            {
                await RemoveAsync(key);
                return;
            }
    #if USE_PREFERENCES
            Preferences.Set(key, value);
    #else
            await SecureStorage.Default.SetAsync(key, value);
    #endif
        }
    
        public Task RemoveAsync(string key)
        {
    #if USE_PREFERENCES
            Preferences.Remove(key);
    #else
            SecureStorage.Default.Remove(key);
    #endif
            return Task.CompletedTask;
        }
    }
    

    As for the use of AsyncHelpers.RunSync my experience is that when being called frequently (especially from methods that themselves are async) a deadlock can result. I've had this a few times both using .Result and my own code which was almost identical to what AsyncHelper.RunSync does (see https://github.com/aspnet/AspNetIdentity/blob/main/src/Microsoft.AspNet.Identity.Core/AsyncHelper.cs); however I don't think that this the cause of this problem.

  • User Avatar
    0
    liangshiwei created
    Support Team Fullstack Developer

    Hi,

    i will keep checking this problem

Made with ❤️ on ABP v9.0.0-preview Updated on September 19, 2024, 10:13