Search code examples
androidxamarinmvvmcrossandroid-multidex

Xamarin MultiDex in VisualStudio 2015


Hi everybody I'm in a dead end!

Develop a PCL application using VisualStudio 2015, Xamarin and MvvmCross. The Android app exceeds the 65K limit. I need to use Multidex!

For its implementation I have undertaken these guidelines:

  • Enabled checkbox for MultiDex
  • Extended MultiDexApplication class

General considerations:

Debug mode

MinSdk: 21

TargetSdk: 25

BuildTools: 23.0.3

Jdk 1.8.0_121

Xamarin.Android 7.3

Results:

"java.exe" exited with code 2.  C:\Program Files (x86)\MSBuild\Xamarin    \Android\Xamarin.Android.Common.targets   1965

<!-- Compile java code to dalvik -->
  <CompileToDalvik 
    DxJarPath="$(DxJarPath)"
    JavaToolPath="$(JavaToolPath)"
    JavaMaximumHeapSize="$(JavaMaximumHeapSize)"
    JavaOptions="$(JavaOptions)"
    ClassesOutputDirectory="$(IntermediateOutputPath)android\bin\classes"
    ToolPath="$(DxToolPath)"
    ToolExe="$(DxToolExe)"
    UseDx="$(UseDx)"
    MultiDexEnabled="$(AndroidEnableMultiDex)"
    MultiDexMainDexListFile="$(_AndroidMainDexListFile)"
    JavaLibrariesToCompile="@(_JavaLibrariesToCompileForAppDx)"
OptionalObfuscatedJarFile="$(IntermediateOutputPath)proguard\__proguard_output__.jar"
/>

The error occurs during the compilation process.

I have consulted these sources:

"https://developer.android.com/studio/build/multidex.html"

"http://www.jon-douglas.com/2016/09/05/xamarin-android-multidex/"

"http://www.jon-douglas.com/2016/09/23/xamarin-android-multidex-keep/"

"https://przemekraciborski.eu/"

"https://forums.xamarin.com/discussion/64234/multi-dex-app-with-a-custom-application-class-that-runs-on-pre-lollipop"

"http://frogermcs.github.io/MultiDex-solution-for-64k-limit-in-Dalvik/"

I also have the ClassyShark.jar tool, but no dex or apk file is generated to explore it. Only the mono.android.jar file exists

enter image description here

Please I need help.

Thank you very much.


Responding to answer 1 and Luke Pothier's commentary are the results:

Setting output verbosity = Diagnostic


Case 1:

Using Android Sdk Location: C:\Program Files (x86)\Android\android-sdk installed with Visual Studio 2015.

4>_CompileToDalvikWithDx:
4>  Creating directory "obj\Debug\proguard".
4>  C:\Program Files\Java\jdk1.8.0_121\\bin\java.exe -Xmx1G -jar "C:\Program Files (x86)\Android\android-sdk\build-tools\25.0.3\\lib\dx.jar" --no-strict --dex --output= ... 
4>  trouble writing output: Too many field references: 68102; max is 65536.
4>  You may try using --multi-dex option.
4>  References by package:
(list of references by packages)
4>C:\Program Files (x86)\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(1965,3): error MSB6006: "java.exe" exited with code 2.

Case 2:

Using Android Sdk Location: c:\android\sdk with last proguard version 5.3.3 installed with Android Studio.

4>_CompileToDalvikWithDx:
4>  Creating directory "obj\Debug\proguard".
4>  C:\Program Files\Java\jdk1.8.0_121\\bin\java.exe -Xmx1G -jar C:\Android\sdk\build-tools\25.0.0\\lib\dx.jar --no-strict --dex --output=
4>  trouble writing output: Too many field references: 68102; max is 65536.
4>  You may try using --multi-dex option.
4>  References by package:
(list of references by packages)
4>C:\Program Files (x86)\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(1965,3): error MSB6006: "java.exe" exited with code 2.

Solution

  • After adjusting the path to the android sdk, removing the spaces and setting in the project file for the Droid platform the property AndroidEnableMultiDex in all configurations (appeared AndroidEnableMultipleDex) in true, I was able to compile without errors. Also, I have been able to check the contents of the generated dex files and both have references to Mvvmcross.

    When I execute the application, it shows the splash view (ok!!!), but, an exception occurs when processing the view (activity) that has a binded viewmodel. Now, the viewmodel has null value. (Until the moment of having to activate the multidex, the application executed without any incidence)

    My challenge now is to know if all the reference to Mvvmcross should be in the main dex, or is it due to another problem that I have overlooked?

    Thanks in advance for his time to @LukePothier.

    My self response:

    After compiling and generate dex classes:

    I already have the application running !!!