App runs in debug mode, crashes in release mode

Hi!

When running my xamarin forms app on android in debug mode, all works fine.
But when running it in release mode the app crashes after showing the splash screen. (I have deleted the debug version from phone before installing the release version).
Below you can see the application output.
If i delete "Mono Android-23 Support" and "Mono shared Runtime" and reinstall the release version my app does NOT crash in release mode.
So far okay - but will it work later when somebody installs my app from Play store?

What are your experiences with debug and release mode?

Thanks a lot and have a nice day!
Andreas

Application Output: [AndroidRuntime] Shutting down VM [AndroidRuntime] FATAL EXCEPTION: main [AndroidRuntime] Process: Alarm.Droid, PID: 8858 [AndroidRuntime] java.lang.RuntimeException: java.lang.reflect.InvocationTargetException [AndroidRuntime] at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:811) [AndroidRuntime] Caused by: java.lang.reflect.InvocationTargetException [AndroidRuntime] at java.lang.reflect.Method.invoke(Native Method) [AndroidRuntime] at java.lang.reflect.Method.invoke(Method.java:372) [AndroidRuntime] at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1016) [AndroidRuntime] ... 1 more [AndroidRuntime] Caused by: md52ce486a14f4bcd95899665e9d932190b.JavaProxyThrowable: System.IO.FileNotFoundException: Could not load file or assembly 'alarm' or one of its dependencies. The system cannot find the file specified. [AndroidRuntime] File name: 'alarm' [AndroidRuntime] at System.AppDomain.Load (System.Reflection.AssemblyName,System.Security.Policy.Evidence) <0x003d4> [AndroidRuntime] at System.AppDomain.Load (System.Reflection.AssemblyName) <0x0001f> [AndroidRuntime] at (wrapper remoting-invoke-with-check) System.AppDomain.Load (System.Reflection.AssemblyName) <0x0007b> [AndroidRuntime] at System.Reflection.Assembly.Load (System.Reflection.AssemblyName) <0x0001f> .....

«1

Posts

  • Hi!

    I have found another solution - i had to make the PCL-Project assembly name lower case!

    Now the app runs without problem also in release mode (without the linkskip option)!

    Thanks for help!

    Andreas

  • Okay, at another point in my application i get now the message "Coult not load file or assembly 'Alarm'...."
    With upper case!
    Seems that i have to include an upper case version and a lower case version of my PCL project assembly.

    Wired!

    Has anybody else such a problem?

    Thanks!
    Andreas

  • SebastianElingSebastianEling DEMember

    Hey Andreas,

    do you have any solution for this? I have something similiar but maybe quite different. Can't watch the logs at the moment i will check this at evening. Iam using Android app with portable library. In debugmode all is working as expected but in releasemode the app is crashing when access the portable library first time. I try to load some data from REST Service and using async/await and Newton.Json API. I think some of this components are the problem. I have granted Network_Status and Internet Permission.

    If you have some new experiences let me know ;-)

  • RofiqSetiawanRofiqSetiawan USMember ✭✭✭

    @SebastianEling said:
    Hey Andreas,

    do you have any solution for this? I have something similiar but maybe quite different. Can't watch the logs at the moment i will check this at evening. Iam using Android app with portable library. In debugmode all is working as expected but in releasemode the app is crashing when access the portable library first time. I try to load some data from REST Service and using async/await and Newton.Json API. I think some of this components are the problem. I have granted Network_Status and Internet Permission.

    If you have some new experiences let me know ;-)

    maybe you need try and catch to catch exceptions.
    pay attention to NullReferenceException.

  • AndreasWettl.6258AndreasWettl.6258 ATMember ✭✭

    Hi!
    The problem was that all assembly names had to be lower case. I had lower/upper case mixed. Don't why it works in debug mode but not in release mode (project options / output / assembly name).
    Hope it helps!
    Best regards
    Andreas

  • PonsundarSinghPonsundarSingh INMember

    In our case, we switched Linking to 'None' in Linker properties to get it work in release mode.

  • ViggoLViggoL SEMember ✭✭

    @Sivamuralidhar said:
    check the internet permission property in Android manifest file.

    This solved it for me! Thanks a ton Siva.

  • JPHochbaumJPHochbaum USMember ✭✭✭

    I am having the same problem. I added internet permissions and linking to SDk assemblies only. Still not working and no way to tell what causes the crash.

  • @PonsundarSingh said:
    In our case, we switched Linking to 'None' in Linker properties to get it work in release mode.

    Thanks! That solved my problem.

  • JavedKalaniyaJavedKalaniya USMember ✭✭

    @PonsundarSingh said:
    In our case, we switched Linking to 'None' in Linker properties to get it work in release mode.

    Thanks! That solved my problem.

  • @Sivamuralidhar said:
    check the internet permission property in Android manifest file.

    Added to AndroidManifest.xml following line and worked. Thanks Shiva

  • WinSomeLoseSomeWinSomeLoseSome USMember ✭✭
    edited February 2017

    In our case, we switched Linking to 'None' in Linker properties to get it work in release mode. None of the other suggestions worked. Currently using VS 2017 RC Enterprise version released today. I renamed all assemblies to lower case as suggested but that alone didn't get the release build to work. Debug works fine, which is confusing. I've been tweaking the android build properties all day and with this final tweak, I'm able to get it working with "Use shared runtime", "Bundle assemblies into native code" and "Enable ProGuard" all checked.
    (NOTE: "Use shared runtime" had to be unchecked as apps cannot be archived with this setting checked. Unfortunately, this caused the apk file to balloon from 15mb to 41mb).

    I don't mind having to use a few tricks to get around anomolies given the tremendous benefits xamarin offers. What I do mind is the list constantly changing and expanding. reading the troubleshooting section is a great start to the checklist of things to try. I am surprised Xamarin doesn't offer a consolidated troubleshooting page to save everyone from having to search endlessly for the numerous workarounds.

    https://github.com/NowBI/Xamarin-Forms-Mobile-Template/blob/master/README.md

    You want to see a discussion of xamarin viability I suggest

    https://www.reddit.com/r/dotnet/comments/55cp6a/xamarin_the_latest_release_is_unusable_and_i_need/

    and

    http://www.estaun.net/blog/some-thoughts-after-almost-a-year-of-real-xamarin-use/

    The tremendous respect mentioned in these posts for the creators of xamarin is warranted IMHO. It is an unbelievably difficult challenge to do what they are doing. That respect is dimmed by the tremendous waste of time I have experienced accumulating a list of workarounds to environment instability, time that I could have spent coding.

  • JaraJara PHMember ✭✭

    I'm having this weird issue as well but the other way around.

    The app works in Release, but not in Debug.
    My original question is in here
    http://stackoverflow.com/questions/42605200/xamarin-android-immediately-terminates

  • @Sivamuralidhar : Internet enable in manifest works.

  • AugustinBockenAugustinBocken USMember ✭✭
    edited April 2017

    Hello !
    I have the same problem, but none of the solutions above worked for me...

    Is there any other option to fix this ? I even implemented HockeyApp in the hope of some metrics, but the app crash even before it register to the service.

    EDIT :
    Finally I wass able to make it work by unselecting (is that a word ?) the option Bundle Assemblies into native code. I had to try everything to find this. Apparently there is very little documentation about what this option really does, so if somebody would provide a link, that would be great !

  • DFoulkDFoulk USMember ✭✭✭

    Just in case the above solutions don't work for someone:

    1. Clean your solution (Debug & Release)
    2. Uninstall the application on your device (or emulator)
    3. Deploy your solution

    These steps (somehow) fixed the crashing for me. No changes were made to anything in my solution- it simply resolved itself after completing the steps above!

    Hope this helps...

  • SnehalJadhav.7507SnehalJadhav.7507 USMember ✭✭

    My app is running properly in release mode but getting crashed in Debug mode. Please help.
    I'm new to this stuff.

  • EsamSherifEsamSherif EGUniversity ✭✭

    for me using Shared project... the conditional compilation symbol was set for debug mode and not release.

  • st0jst0j NZMember
    edited June 2017

    I was able to solve this issue in VS 2017/Xamarin 4.5.

    Firstly I created a new Platform for x86 within Configuration Manager (Platform > New...). I then changed all build options to reference Release/x86 in the project properties. I also set Linker properties "Linking" to None.

    And lastly, I had to enable x86 within Android Options > Advanced > Supported Architectures. Hope this helps someone...

  • MarcusIMarcusI SEMember ✭✭

    @DFoulk said:
    Just in case the above solutions don't work for someone:

    1. Clean your solution (Debug & Release)
    2. Uninstall the application on your device (or emulator)
    3. Deploy your solution

    For me this worked. I only needed to right-click the solution and choose Clean Solution and everything worked. Didn't even need to uninstall the app first. Must have been some leftovers in the solution/project since my previous updates and upgrades of Xamarin and Visual Studio. Seems like I always run into some kind of problem after installing Xamarin updates so now I don't know if I dare update anything again unless I really have to.

  • DFoulkDFoulk USMember ✭✭✭
    edited October 2017

    @MarcusI - Glad to hear it. Yes, there is something out of alignment between the installation on the device (perhaps left over settings, data in the cache, etc.)- or some code gremlin who wants to ruin our sprints...

    We all run into issues after updating NuGet packages. I have a few tips that may prevent future issues for peeps:

    1) Only upgrade to stable packages
    2) Do not upgrade to a newer major version of a package (1.0.0 => 1.0.1 is okay, but not 1.0.0 => 2.0.0) as major versions indicate that backwards incompatible changes are introduced to the public API (usually)
    3) Do your best to make sure that your packages are compatible with installed packages (NuGet Package Manager is supposed to do this, but I have experienced issues with being able to upgrade dependencies that are unsupported)
    4) Read this post before tinkering with Xamarin.Android.Support libraries (upgrading these libraries without understanding why has caused me heartache many-a-time)
    5) If you find yourself having a lot of build and/or deployment errors, close Visual Studio and delete all bin & obj folders AND your packages folder (manually) in your solution (use your file browser)

    If the only remaining explanation is a corrupt package; you can clear your NuGet global cache by deleting the following folders (substitute your user name):

    C:\Users\user\AppData\Local\NuGet\
    C:\Users\user.nuget\packages\
    C:\Users\user\AppData\Local\Temp\NuGetScratch\

    Anyways, gotta get back to the grind- glad you were able to get things working again!

    @MarcusI said:

    @DFoulk said:
    Just in case the above solutions don't work for someone:

    1. Clean your solution (Debug & Release)
    2. Uninstall the application on your device (or emulator)
    3. Deploy your solution

    For me this worked. I only needed to right-click the solution and choose Clean Solution and everything worked. Didn't even need to uninstall the app first. Must have been some leftovers in the solution/project since my previous updates and upgrades of Xamarin and Visual Studio. Seems like I always run into some kind of problem after installing Xamarin updates so now I don't know if I dare update anything again unless I really have to.

  • msdYqbmsdYqb USMember ✭✭

    @DFoulk said:
    Just in case the above solutions don't work for someone:

    1. Clean your solution (Debug & Release)
    2. Uninstall the application on your device (or emulator)
    3. Deploy your solution

    These steps (somehow) fixed the crashing for me. No changes were made to anything in my solution- it simply resolved itself after completing the steps above!

    Hope this helps...

    thank you so much this really solved my problem
    it happened after I change linking to (sdk and user assemblies) and enable proguard

    I notice changing project settings causes some problems
    last time I've only changed the version number and suddenly the App page disappeared! had to add it again but then it gives me error "The name 'InitializeComponent' does not exist in the current context" so I had to remove InitializeComponent(); method from app

  • DFoulkDFoulk USMember ✭✭✭
    edited October 2017

    @msdYqb said:

    @DFoulk said:
    Just in case the above solutions don't work for someone:

    1. Clean your solution (Debug & Release)
    2. Uninstall the application on your device (or emulator)
    3. Deploy your solution

    These steps (somehow) fixed the crashing for me. No changes were made to anything in my solution- it simply resolved itself after completing the steps above!

    Hope this helps...

    thank you so much this really solved my problem
    it happened after I change linking to (sdk and user assemblies) and enable proguard

    I notice changing project settings causes some problems
    last time I've only changed the version number and suddenly the App page disappeared! had to add it again but then it gives me error "The name 'InitializeComponent' does not exist in the current context" so I had to remove InitializeComponent(); method from app

    I'm glad that helped you. I would put the InitializeComponent() method back where it was... That's an important call for XAML Compilation!

    The reason that method was throwing an error was because you cleaned your solution- but did not (yet) rebuild the solution. After you rebuild the solution- that error will go away and the call for that method will no longer throw an error.

    See any of these threads for details:
    Google Search Results

    Let me know if you have any questions man!

  • msdYqbmsdYqb USMember ✭✭

    @DFoulk said:

    @msdYqb said:

    @DFoulk said:
    Just in case the above solutions don't work for someone:

    1. Clean your solution (Debug & Release)
    2. Uninstall the application on your device (or emulator)
    3. Deploy your solution

    These steps (somehow) fixed the crashing for me. No changes were made to anything in my solution- it simply resolved itself after completing the steps above!

    Hope this helps...

    thank you so much this really solved my problem
    it happened after I change linking to (sdk and user assemblies) and enable proguard

    I notice changing project settings causes some problems
    last time I've only changed the version number and suddenly the App page disappeared! had to add it again but then it gives me error "The name 'InitializeComponent' does not exist in the current context" so I had to remove InitializeComponent(); method from app

    I'm glad that helped you. I would put the InitializeComponent() method back where it was... That's an important call for XAML Compilation!

    The reason that method was throwing an error was because you cleaned your solution- but did not (yet) rebuild the solution. After you rebuild the solution- that error will go away and the call for that method will no longer throw an error.

    See any of these threads for details:
    Google Search Results

    Let me know if you have any questions man!

    Fixed
    after changing the build action to embedded resource and the error gone ... thank you again!
    it turns out after re adding the page the build action wasn't the same
    I still don't understand why we need InitializeComponent(); in App
    my application runs fine without it

  • DFoulkDFoulk USMember ✭✭✭
    edited October 2017

    As well as setting the MainPage property, the code-behind must also call the InitializeComponent method in order to load and parse the associated XAML.

    Source: Xamarin.Forms Application Fundamentals

    You must not be using XAML, because if you remove this method from any view- said view will not load your XAML. Though this results in no compilation nor runtime errors- it does result in missing content in your application. It can be a bit confusing (no compilation/runtime exceptions == stable, right?) lol...

    @msdYqb

  • AssuroMoraisAssuroMorais USMember
    edited November 2017

    It seems that there is no solution for me, I've tried everything and nothing works

  • OnedayOneday GBMember ✭✭

    Hi All, I found this thread online looking for a soolution.

    I had my app working and deployed, both release and debug, but kept tidying up code to improve speed and recompiled using the latest version of VS 2017 comunity preview .

    Then , suddenly, this bizarre issue,

    Works in debug, but will not work in release.

    @DFoulk

    Did you mean select debug, the clean followed by select release clean, uninstall from device ?

  • DFoulkDFoulk USMember ✭✭✭

    @Oneday said:
    Hi All, I found this thread online looking for a soolution.

    I had my app working and deployed, both release and debug, but kept tidying up code to improve speed and recompiled using the latest version of VS 2017 comunity preview .

    Then , suddenly, this bizarre issue,

    Works in debug, but will not work in release.

    @DFoulk

    Did you mean select debug, the clean followed by select release clean, uninstall from device ?

    That's the gist of it. Alternatively, you can perform step 5 in my comment above.

    If you are comfortable with the actions I recommended above; you can use these helpful PowerShell scripts to clean your app & fix the EmbeddedResource bug:

    Clean-App.ps1

    Fix-EmbeddedResource-Bug.ps1

    Please review the contents of these scripts before running them, confirm that they will work in your environment and most importantly: MAKE A BACKUP OF YOUR SOLUTION BEFORE RUNNING!

    The scripts above are what I use to fix these issues when they come across my desk (seems like every other day)...

    Clean-App.ps1 Instructions:

    1. Select the root folder for your Xamarin.Forms app in the folder browser dialog
    2. Answer any questions that the script asks (via prompt)

    Fix-EmbeddedResource-Bug.ps1 Instructions:

    1. If using Git, make sure your repo has a clean working copy (no uncommited changes)
    2. Run the script
    3. Select the root folder for your Xamarin.Forms app in the folder browser dialog
    4. If using Git, click 'Yes' when prompted to run 'git reset'
  • OnedayOneday GBMember ✭✭
    edited December 2017

    @DFoulk

    Thanks for that.

    I got it to work eventually, by switching the linker off(Release AND debug mode). I had fundamentally misunderstood what linker does.

    However, I have reason to believe that using the linker in debug mode affects the same setting in release mode

    initially i only selected "none" for linking in Release mode. The App only worked after I went back and also selected "none" for linking in debug mode

    A bug perhaps, hope my description makes some sense

    Plus I did multiple cleans in both modes and uninstalls

  • DFoulkDFoulk USMember ✭✭✭
    edited December 2017

    @Oneday said:
    @DFoulk

    Thanks for that.

    I got it to work eventually, by switching the linker off(Release AND debug mode). I had fundamentally misunderstood what linker does.

    However, I have reason to believe that using the linker in debug mode affects the same setting in release mode

    initially i only selected "none" for linking in Release mode. The App only worked after I went back and also selected "none" for linking in debug mode

    A bug perhaps, hope my description makes some sense

    Plus I did multiple cleans in both modes and uninstalls

    Yeah man, if you are releasing an app to the public- then you will want to utilize linking. Specifically, you'll want to link 'Sdk and User Assemblies'. I enable this in both Debug & Release. By enabling this in Debug mode, you will be able to see any exceptions caused by linking in your debugger. AKA- no more invisible exceptions in Release builds.

    By linking all assemblies, you can shrink your apps size to 30% of the original (unlinked) package. Literally.

    Sounds like you've found this already, but in case others need it: Linking on Android - Xamarin

    If you haven't already noticed: ProGuard will cause similar issues for you if not configured properly. But (yet again) is recommended for production apps.

    Glad you got your app up and running again!

  • nedimkpelinedimkpeli USMember ✭✭

    Thank you @rzee7.
    Your solution solved my problem.

  • EldoseEldose USMember

    Thank you @rzee7 .
    I got the same issue. Now It is working fine with your solution.
    But, why this sdk assembly only ?

  • BlueCoder77BlueCoder77 USMember ✭✭

    @DFoulk said:
    Just in case the above solutions don't work for someone:

    1. Clean your solution (Debug & Release)
    2. Uninstall the application on your device (or emulator)
    3. Deploy your solution

    These steps (somehow) fixed the crashing for me. No changes were made to anything in my solution- it simply resolved itself after completing the steps above!

    Hope this helps...

    This worked for me. I have run into this issue before and changing the Linking options and setting internet worked to resolve this issue for me originally, but this time around the solution I quoted above is what finally did the trick. Thanks for that!

  • DFoulkDFoulk USMember ✭✭✭
    edited June 2018

    @BlueCoder77 - Glad it got you sorted. The OP's exception appears to have been caused by the linker removing some logic that the app needed to run. The solution provided by @rzee7 tells the linker to skip the "alarm" assembly- thus said logic is not stripped out of the build (which fixes the exception).

    If the exception just showed up (without you dinking around with linker or after you've built successfully in Release config and haven't changed your code) then the solution provided by @rzee7 probably won't help ya!

    Again, the recommended solution to exceptions related to linking is to try to configure linker to link as much of your code as possible- without removing stuff that you need. The package size difference can be pretty dramatic if you skip entire assemblies (instead of trying to solve the problem via configuration). Just read the docs on linking and if you really want to be serious; checkout Custom Linker Configuration.

  • API2018API2018 Member ✭✭

    I've got same issue. My app is working well on many android emulator but when I install a real device, it crashes after launching and gets error like "Application Name" has stopped. Also application Icon seems black. I need a help.

  • allotmentsallotments Member

    My android xamarin forms app stopped working immediately after release build & deployment. What fixed this for me was to first build the Portable parent project together with the Android project. The tick box to build Portable was in Solution Properties > Configuration Properties > Configuration.

  • nivibhatnivibhat Member ✭✭
    edited June 2018

    If I use Don't Link linker option, the app runs in release mode but the size of the app is huge. If I change the linker property to Link all assemblies then the size reduces dramatically, but the app crashes right after the launch screen.

Sign In or Register to comment.