Forum Xamarin Xamarin.Android

All Xamarin.Android applications crash on launch

I just wrote my first Xamarin.Android app. Everything worked fine during testing on the emulator in both Debug and Release mode but when I generate the apk and install the app on my actual device, the application crashes immediately (although installation succeeded with no errors).

My app is very simple so there's not much that could have gone wrong from my point of view, so I tested the "blank" application template with literally just a button that says Click Me. Again, it works on the emulator but on my phone it crashes on startup. I don't know if I can get some kind of log that helps me with this and I couldn't find any resource online that helps me, so I'm asking here.

My phone is an Honor 5X with Android 5.1.1

Answers

  • cpt_bubblescpt_bubbles DEMember

    Update: I found out about Logcat two lines I've noticed right before the Process dies are:

    monodroid-assembly(16221): Assembly 'assemblies/Java.Interop.dll' is located at a bad address 0x7f648f0efd
    monodroid-assembly(16221): You MUST run `zipalign` on base.apk
    
  • RobertBruceRobertBruce USMember ✭✭
    edited August 2016

    There appears to be a bug in the Tools|Android|”Publish Android App…” process (assuming you’re using Visual Studio).

    At least I’ve never been able to get it to work. I get the same error messages you get indicating the zipalignment did not work.

    The work-around is to manually sign and zipalign your APK.

    Here are the steps I use (they assume you have already established your keystore and alias/key for your app. If not, see the end of this post):

    (1) Load project in Visual Studio.
    (2) Set the build to Release.
    (3) Clean and Build.
    (4) Click on the project in the Solution Explorer (otherwise, you won’t see the next menu option)
    (5) Select “Export Android Package (.apk)” from the Build menu. This will create two .APK files in your /bin/Release folder (you can disregard/delete the one that has “-Signed.apk” as we won’t use it).
    (6) Manually Sign the APK using the Java SDK “jarsigner” utility. For my environment, I run the following command:

    C:\Program Files (x86)\Java\jdk1.7.0_55\bin>jarsigner -verbose -sigalg MD5withRS A -digestalg SHA1 -keystore c:\users\robert\workspace\pi.keystore C:\Projects\Pi\Pi\bin\Release\com.mydomainname.pi.apk pi

    Where “pi” at the end is the name of the associated alias/key in my keystore.

    (7) Manually ZipAlign the Signed APK using the Android SDK “zipalign” utility (see link below for details). For my environment, I run the following command:

    C:\Program Files (x86)\Android\android-sdk\build-tools\23.0.3>zipalign -f 4 c:\projects\pi\pi\bin\Release\com.mydomainname.pi.apk c:\projects\pi\pi\bin\Release\pi.apk

    Where “pi.apk” is the final zipaligned .apk ready for installation.

    See the following Xamarin guide for more details on manually signing and zipaligning:

    https://developer.xamarin.com/guides/android/deployment,testing,_and_metrics/publishing_an_application/part_2-_signing_the_android_application_package/manually-signing-the-apk/

    For the steps above, I am assuming that you have already established your keystore and created an alias/key for your application. If not, the easiest way I've found is to use the Tools|Android|Publish AndroidApp... process (that we're ironically working around above!) which will first bring up a user interface to create/use a keystore and create the application key (aka alias) -- and then you can cancel out of that dialog after creation). This link has more information on that interface as well.

    See this link for more details on configuring a keystore:

    https://developer.xamarin.com/guides/android/deployment,testing,_and_metrics/publishing_an_application/part_2-_signing_the_android_application_package/

    Hope this helps!

  • JohnClaveyJohnClavey GBMember

    Thanks.

    Unfortunately I wasted a month trying to figure this one out :(

    But eventually managed to resolve this the way you have explained above.

    I have reported this to Xamarin and Microsoft. But no apology as yet.

    I appears this has all been a problem for just new VS2015 users who haven't already been customers of Xamarin, this also affected their demo code which was tied into Xamarin Studio and wouldn't work for new VS2015 customers.

    For now I am sticking with B4X to develop Android and iOS as it simply works as expected.

    Once Xamarin get this sorted I will revisit this.

    One click is should be all that is required for this process. Come on Microsoft/Xamarin get this sorted....

    Once again thanks to Robert Bruce for explaining this for other developers caught in this trap.

  • harrys_utilsharrys_utils Member ✭✭
    Remember you need to use archive and not deploy. . You also need to create your own signing key. . Save ad hoc And you will get prompted to create a key. .
Sign In or Register to comment.