Same Android app who runs on Debug mode, crashes on release mode

こ雲淡風輕ζ 提交于 2019-12-24 17:00:02

问题


I've written a simple app using Xamarin for Visual Studio and C# language. The code is:

    HubConnection hubConnection;
    IHubProxy chatHubProxy;
    async void btnConnect_Click(object sender, EventArgs e)
    {
        try
        {
            TextView log = FindViewById<TextView>(Resource.Id.txtLog);
            base.OnResume();

            hubConnection = new HubConnection("http://192.168.1.3:2010/signalr");

            chatHubProxy = hubConnection.CreateHubProxy("MyHub");

            chatHubProxy.On<string>("AddMessage", (message) =>
            {
                TextView text = FindViewById<TextView>(Resource.Id.txtLog);
                text.Text = message;
            });

            var localIP = "192.168.1.104"; //the android device has this IP

            await hubConnection.Start();

            var srvrMessage = chatHubProxy.Invoke<string>("LoginFromMobile", "mahdi", "p@SsW0Rd",
                hubConnection.ConnectionId, localIP);
            if (srvrMessage != null)
            {
                log.Text = srvrMessage.Result;
            }
            else
                log.Text = "can't connect to server";
        }
        catch (Exception ex)
        {
            TextView text = FindViewById<TextView>(Resource.Id.txtLog);
            text.Text = ex.StackTrace;
        }
    }

When I click the "Connect" button, I get connected to a SignalR Hub located on my pc in the network, and everything works fine in DEBUG mode. But unfortunately, when I compile the same app in RELEASE mode, I get the following error:

I can't see why... Please tell me what I need to consider to make the app work right in Release mode too. Is there any permission problem? Some config or setting missing? Your guides are truly helpful and appreciated.


回答1:


If something works in Debug mode but does not in Release mode then most likely the issue is that the Linker is not including your dll when it generates the Release binary.

If you double click on your Android project in the Solution Explorer you can change the setting under Build -> Android Build.

You'll need to select Release for your configuration and then select the Linker tab. If you select "Don't Link" all dlls your project reference will be include in the Release binary. This will lead to a larger binary size but will help you diagnose if this it the problem.

You can read more about the Linker from the Xamarin docs: https://developer.xamarin.com/guides/ios/advanced_topics/linker/




回答2:


Linking to "Sdk Assemblies only" fixed my problem.



来源:https://stackoverflow.com/questions/35521878/same-android-app-who-runs-on-debug-mode-crashes-on-release-mode

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!