Xamarin.Forms.Maps COMPILETODALVIK : error : Could not create the Java Virtual Machine

StephenGrahamStephenGraham GBMember ✭✭
edited June 2016 in Xamarin.Forms

Hi all,

I have created a blank cross platform project in VS2015 and have added the Xamarin.Forms.Maps package. This caused various GooglePlay services to also install. Without having written a line of code this essentially blank project fails to compile with the message "COMPILETODALVIK : error : Could not create the Java Virtual Machine".

Any information about the location of diagnostic information (log files etc.) indicating the precise cause of the problem would be appreciated. Does anyone know which version(s) of Java (runtimes of development kit) are compatible with the latest version of Xamarin.Maps? I have tried other solutions proposed on the forums but so far without success.

I am using Visual Studio 2015 with Update 2 and I have Java 7 runtimes Updates 65 and 72 installed and Java SE 7 Development Kit Updates 17, 65 and 72 installed (the latest update 72 is 64-bit for both runtimes and JDK). The Max Heap Size for the Android project is set to 2G. I also have a number of other Xamarin projects under development and they all compile and run OK. It's only when I try to add Xamarin.Forms.Maps to a project that I get this COMPILETODALVIK error.

Thanks

Answers

  • fortinguillaumefortinguillaume FRBeta ✭✭

    I have the same problem at this time but only in release mode. but i have link Xamarin.Forms.Map.
    I investigate too...

  • fortinguillaumefortinguillaume FRBeta ✭✭

    just add this fix
    <JavaMaximumHeapSize>1G</JavaMaximumHeapSize>
    inside my project for debug and release mode

  • StephenGrahamStephenGraham GBMember ✭✭

    Thank you fortinguillaume for your input. I regret to say that all modes for my project already set the JavaMaximumHeapSize. I had previously tried 1G without success, and later increased it to 4G as proposed by another solution again without success. What versions of Xamarin.Forms.Maps and JRE / JDK are you using?

  • StephenGrahamStephenGraham GBMember ✭✭

    UPDATE:
    Until recently this problem had not affected my main development project, but whilst making some changes to PCL code, the Android platform project inexplicably suddenly suffered build failures with the same error message. So for anyone else who is suffering from the same issue the steps I took to resolve the problem were as follows:-

    1. In Android SDK Manager I installed the latest version of the Android SDK Build tools to match the Android platform that I was compiling against (in my case I installed Android SDK Build-tools 23.0.3 matching "Use Latest Platform (Android 6.0 (Marshmallow))" shown in my Android project properties "Compile using Android version:".
    2. After closing the Android SDK Manager and Visual Studio 2015, I removed all 32 and 64 bit versions of the JDK / JRE from my Windows 8.1 Pro PC via Control Panel, Programs and Features applet. These were mostly Java version 1.7 (JDK 7)
    3. Then I downloaded and installed the most recent 32-bit version of JDK 8 from oracle http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html (you must install the 32-bit version even though your version of windows may be 64-bit).
    4. Finally I rebooted my PC and on restart I went back into Visual Studio 2015 and checked the Tools | Options | Xamarin | Android Settings | Java Development Kit location to make sure it pointed to the newly installed JDK.

    So my main development project is now building again but unfortunately the original problem with the blank Xamarin.Forms.Maps persists.

  • fortinguillaumefortinguillaume FRBeta ✭✭

    today, I have this problem already appear.
    i have clean all projects. rebuild failed with this message "COMPILETODALVIK : error : Could not create the Java Virtual Machine"

    i reboot visual studio 2015 with administor rights and it compile.

    PS: yesterday, i have generate apk for test signed apk in release mode. so, VS 2015 have load project on release mode (without JavaMaximumHeapSize 1G).
    I think : change compilation mode doesn't reload JavaMaximumHeapSize properties.

  • DylanSchoenmakersDylanSchoenmakers NLMember ✭✭

    @StephenGraham thanks! Works to solve the issue Unsupported class version number [52.0] (maximum 51.0, Java 1.7) like in https://forums.xamarin.com/discussion/70361/java-exe-exited-with-code-1

  • FranciscoGGFranciscoGG ESMember ✭✭

    @StephenGraham I followed all the steps and I sill get the same error...

    Here is the output:

    8> Elfo.VisionShop.Droid -> C:\Projects\VisionPoint\VisionShop\Client\DEV\SprintM06\Elfo.VisionShop.Droid\bin\Release\Elfo.VisionShop.Droid.dll
    8> It is recommended that the compiler be upgraded.
    8> warning: C:\Users\FranciscoJavier\AppData\Local\Android\android-sdk\platforms\android-24\android.jar(android/widget/AdapterView$OnItemLongClickListener.class): major version 52 is newer than 51, the highest major version supported by this compiler.
    8> It is recommended that the compiler be upgraded.
    8> Note: Some input files use or override a deprecated API.
    8> Note: Recompile with -Xlint:deprecation for details.
    8> Note: Some input files use unchecked or unsafe operations.
    8> Note: Recompile with -Xlint:unchecked for details.
    8> 100 warnings
    8>PROGUARD : warning : okio.Okio: can't find referenced class java.nio.file.Files
    8>PROGUARD : warning : okio.Okio: can't find referenced class java.nio.file.Files
    8>PROGUARD : warning : okio.Okio: can't find referenced class java.nio.file.Files
    8>PROGUARD : warning : okio.Okio: can't find referenced class java.nio.file.Path
    8>PROGUARD : warning : okio.Okio: can't find referenced class java.nio.file.OpenOption
    8>PROGUARD : warning : okio.Okio: can't find referenced class java.nio.file.Path
    8>PROGUARD : warning : okio.Okio: can't find referenced class java.nio.file.OpenOption
    8>PROGUARD : warning : okio.Okio: can't find referenced class org.codehaus.mojo.animal_sniffer.IgnoreJRERequirement
    8>PROGUARD : warning : okio.Okio: can't find referenced class java.nio.file.Path
    8>PROGUARD : warning : okio.Okio: can't find referenced class java.nio.file.OpenOption
    8>PROGUARD : warning : okio.Okio: can't find referenced class java.nio.file.Path
    8>PROGUARD : warning : okio.Okio: can't find referenced class java.nio.file.OpenOption
    8>PROGUARD : warning : okio.Okio: can't find referenced class org.codehaus.mojo.animal_sniffer.IgnoreJRERequirement
    8>PROGUARD : warning : there were 24 unresolved references to classes or interfaces.
    8>C:\Program Files (x86)\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(2118,3): error MSB6006: "java.exe" exited with code 1.
    ========== Rebuild All: 7 succeeded, 1 failed, 0 skipped ==========

  • StephenGrahamStephenGraham GBMember ✭✭

    Hi Francisco,

    Most of the MSBuild output is warnings and so shouldn't be causing a build failure. If you haven't already done so can I suggest that you increase the level of MSBuild output verbosity? You can do this in Visual Studio by:-

    1. Going to Tools > Options > Projects and Solutions > Build and Run.
    2. Setting MSBuild project build output verbosity to Diagnostic.

    In verbose mode my modest PCL and Android project together produce over 111,000 lines of diagnostic output.

    Hope this helps identify the cause of your problem.

  • RonFreschiRonFreschi USUniversity ✭✭

    @StephenGraham yes, thanks again! Your instructions worked. Had not seen this issue until today. Probably related to the update of all my packages yesterday.

  • rbguravrbgurav INMember

    Rebuild the solution solved my issue. :smile:

  • BrandonMinnickBrandonMinnick USXamarin Team Xamurai

    I had a problem where Proguard was removing the Google Play Services libraries from my app.

    I had to add the following lines of text to the proguard-android.txt file found in this folder:
    /(Path to your Android SDK Folder)/tools/proguard

    -keep public class com.google.android.gms.* { public *; }
    -dontwarn com.google.android.gms.**
    

    Complete proguard-android.txt File

    -keep public class com.google.android.gms.* { public *; }
    -dontwarn com.google.android.gms.**
    
    # This is a configuration file for ProGuard.
    # http://proguard.sourceforge.net/index.html#manual/usage.html
    
    -dontusemixedcaseclassnames
    -dontskipnonpubliclibraryclasses
    -verbose
    
    # Optimization is turned off by default. Dex does not like code run
    # through the ProGuard optimize and preverify steps (and performs some
    # of these optimizations on its own).
    -dontoptimize
    -dontpreverify
    # Note that if you want to enable optimization, you cannot just
    # include optimization flags in your own project configuration file;
    # instead you will need to point to the
    # "proguard-android-optimize.txt" file instead of this one from your
    # project.properties file.
    
    -keepattributes *Annotation*
    -keep public class com.google.vending.licensing.ILicensingService
    -keep public class com.android.vending.licensing.ILicensingService
    
    # For native methods, see http://proguard.sourceforge.net/manual/examples.html#native
    -keepclasseswithmembernames class * {
        native <methods>;
    }
    
    # keep setters in Views so that animations can still work.
    # see http://proguard.sourceforge.net/manual/examples.html#beans
    -keepclassmembers public class * extends android.view.View {
       void set*(***);
       *** get*();
    }
    
    # We want to keep methods in Activity that could be used in the XML attribute onClick
    -keepclassmembers class * extends android.app.Activity {
       public void *(android.view.View);
    }
    
    # For enumeration classes, see http://proguard.sourceforge.net/manual/examples.html#enumerations
    -keepclassmembers enum * {
        public static **[] values();
        public static ** valueOf(java.lang.String);
    }
    
    -keepclassmembers class * implements android.os.Parcelable {
      public static final android.os.Parcelable$Creator CREATOR;
    }
    
    -keepclassmembers class **.R$* {
        public static <fields>;
    }
    
    # The support library contains references to newer platform versions.
    # Don't warn about those in case this app is linking against an older
    # platform version.  We know about them, and they are safe.
    -dontwarn android.support.**
    
    # Understand the @Keep support annotation.
    -keep class android.support.annotation.Keep
    
    -keep @android.support.annotation.Keep class * {*;}
    
    -keepclasseswithmembers class * {
        @android.support.annotation.Keep <methods>;
    }
    
    -keepclasseswithmembers class * {
        @android.support.annotation.Keep <fields>;
    }
    
    -keepclasseswithmembers class * {
        @android.support.annotation.Keep <init>(...);
    }
    
  • MelbourneDeveloperMelbourneDeveloper AUMember ✭✭✭

    This is just insane. I've been trying for almost a week to get an Android app compiling which references the Xamarin Forms Maps NuGet package. In the end, I thought, I might as well just try to get the WorkingWithMaps sample app to run. It has to run because it's maintained by the Xamarin Forms team right? Well, no!

    I've done a full Git Clean. I've also deleted all the Xamarin related stuff here:
    C:\Users[USERNAME]\AppData\Local

    I get this compilation error Could not create the Java Virtual Machine.

    Can someone at Xamarin please pull the sample apps repo and fix it until it compiles and runs on Android? Some people actually need to deliver apps.

  • StephenGrahamStephenGraham GBMember ✭✭

    @MelbourneDeveloper in the last 30 minutes I have downloaded the latest xamarin-forms-samples-master.zip from github. The WorkingWithMaps project loads and compiles OK on my Windows 8.1 PC. The only extra steps that I followed were:-

    • unloading all other projects except the WorkingWithMaps PCL and WorkingWithMaps.Android.
    • cleaning the two remaining projects before compiling.
      I did get 20 project warnings but these didn't stop the program from compiling. I can deploy to the Visual Studio Android Emulator running KitKat (4.4) and the app will run, but I don't have Google Play services installed so I couldn't go much further to prove that map tiles will download. My Java/JDK configuration hasn't changed since this thread started.
  • MelbourneDeveloperMelbourneDeveloper AUMember ✭✭✭

    @StephenGraham , I have fixed my problem by installing the latest version of Xamarin. For some reason, in Visual Studio 2017, I was no longer being prompted to download the latest version, then, when I opened the project in Visual Studio 2015, it told me there was an update.

    So, as a general rule, if you can inexplicable compilation/deployment problems like this, I recommend these steps (which include Stephen's "cleaning the two remaining projects".

    -Ensure the latest Xamarin sdk version is installed. (Don't ask me how to do this)
    -Clean your entire solution with a Git clean, or some other method that deletes all binaries and generated code (bin/obj/NuGet packages folders).
    -Delete all temp Xamarin/Android SDK related files here: C:\Users[USERNAME]\AppData\Local
    -Build 3 or 4 times. Visual Studio will probably error the first few times until all the NuGet packages are restored.

  • JoshuaGrassJoshuaGrass USMember

    Interesting point of info. I tried setting my Java Max Heap size to 2G and 4G and it DID NOT work. Setting it to 1G did work. So the exact size matters.

  • MelbourneDeveloperMelbourneDeveloper AUMember ✭✭✭

    Yes. I've had this problem lately too. I remember a time when 1gig wasn't enough. Getting Xamarin apps to compile is liking having jigsaw pieces that morph while you're not looking.

  • Enigma.6140Enigma.6140 LBMember ✭✭

    @BrandonMinnick solution works for me

  • fredyadriano90fredyadriano90 Member ✭✭

    @BrandonMinnick solution works for me

Sign In or Register to comment.