Getting error "java.exe exited with code 2"

RonNYCRonNYC Member ✭✭✭
edited March 4 in Xamarin.Android

I think I'm in deployment hell. After several months of coding, all of which went great (thanks Xamarin devs!!!) now I'm in deployment hell. I can build no problem. But when I deploy I get this java.exe error. I have turned Multi-Dex on, turned it off, tried (and failed) to run keystore. I created a key but when I run Keystore I get that DerInputStream is too long. Not sure what to do with that, either.

I have deleted the bin and obj folders many times.

It seems within VS the Keystore (as I have it) is the problem. If I unselect sign the apk then I can deploy to my phones and test.

So, if someone can help me solve the KeyStore issue that would be great.

Tagged:

Best Answer

  • RonNYCRonNYC ✭✭✭
    Accepted Answer

    It's fixed. Here's the procedure:

    Create a Release
    Archive
    Create an Archive
    Add New or Use a Key
    Save As
    That's it.

Answers

  • jezhjezh Member, Xamarin Team Xamurai

    Could you please post the steps of reproducing this problem?

  • RonNYCRonNYC Member ✭✭✭

    Clean the project
    Rebuilt (release)
    Check SIgn the apk with the keystore
    Check MultiDex (But doesn't matter; same error with it unchecked)
    Deploy
    JAVA.EXE error 2<===

    That's all. And then the APK will not install.

    I believe the issue is the keystore creation. Just a guess.

    Are there other steps I've missed?

  • MalcolmJackMalcolmJack USMember ✭✭

    Have you tried increasing the Java Max Heap size to 1G?

  • RonNYCRonNYC Member ✭✭✭

    NOPE!!! Sorry.

  • RonNYCRonNYC Member ✭✭✭

    I did all that. Here's my Manifest file:

    I changed the Heap to 1G. I clicked on the link for the Keyfile and used that location (in c:\users\user....etc.)

    Doesn't seem to matter. All builds OK. Just the deploy gets that error.

    I see a lot of other people get that error. Some people (here, stackoverflow) offer "solutions" and for some that works, others not. What gets me is that we are all stumped by some cryptic java.exe error that SEEMS unrelated to anything. Like, use MultiDex or not, what should the heap size be, etc. Just weird.

  • RonNYCRonNYC Member ✭✭✭

    Here's my Android Options page, including Advanced Options.

  • RonNYCRonNYC Member ✭✭✭

    I see a lot of people get this error.

    I've
    Enabled/Disabled MultiDex
    Enabled/Disabled Proguard
    Changed the Heap size to 2G
    Validated I'm using Java SE Dev Kit 8 Update 181 (in Programs and Features)
    Burned incense and lit candles

    What's next? Anyone? Desperate!!!

  • RonNYCRonNYC Member ✭✭✭

    I created an entirely new app. Built and deployed no problem.
    Went to Distribute
    Ad Hoc
    Created a keystore
    added the pwd
    Alias
    pwd for Alias
    saved
    deployed
    GOT JAVA.EXE Error 2

    SO....why?

  • MalcolmJackMalcolmJack USMember ✭✭

    see accepted answer here? https://forums.xamarin.com/discussion/84125/how-to-fix-java-exe-exited-with-code-2#latest

    suggested answer:

    • upgrade proguard
    • make sure you're only using JDK 1.8
  • RonNYCRonNYC Member ✭✭✭
    edited March 19

    The version is jdk1.8.0_181. It's in c:\program files (86)\java

    How does VS find java? I don't see any reference to it. Should I?

    When I go to a normal command prompt, or even the dev cmd prompt, and type java -version I get an error, as Java cannot be found.

    HOWEVER, VS must know where it is because the error is java.exe exited with error 2, so VS called Java.

    This occurs in every app I create. Even a bare bones one.

    Also I did not select Proguard

    RON

  • RonNYCRonNYC Member ✭✭✭

    This app (mostly copied from the web) has the same problem. Java.exe error 2.

  • RonNYCRonNYC Member ✭✭✭
    Accepted Answer

    It's fixed. Here's the procedure:

    Create a Release
    Archive
    Create an Archive
    Add New or Use a Key
    Save As
    That's it.

Sign In or Register to comment.