2

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.
Helper
  • 125
  • 1
  • 8

2 Answers2

1

This is likely to be caused by an issue between Xamarin and ProGuard, the fix to which is detailed here. Essentially, you need to replace the proguard.jar file that is in your Android SDK directory with the latest one from SourceForge (v5.3.3 currently).

EDIT: Per the error messages in your edits, the --multi-dex option isn't being passed during compilation. I would check your Android .csproj to make sure that the <AndroidEnableMultiDex> option is set to True for all build configurations. If that doesn't help, you may need to upload a reproducible sample somewhere.

EDIT 2: Per the comments, your Android SDK location needs to be somewhere where the path does not contain spaces. Program Files is no good. Personally I put mine in C:\Android\android-sdk.

Luke Pothier
  • 1,030
  • 1
  • 7
  • 19
  • In this link "https://developer.xamarin.com/releases/android/xamarin.android_7/xamarin.android_7.3/#proguard", it is explained that with Xamarin.Android 7.3 is no longer necessary to update. However, previously to know this, already had updated the Proguard to the last version. – Helper Jun 10 '17 at 15:12
  • Good point - if you're using the SDK from the default location Xamarin puts it in with Xamarin.Android >=v7.3 you shouldn't have the ProGuard issue. If you try to build with your output verbosity set to Diagnostic, is the error seem any more detailed? – Luke Pothier Jun 10 '17 at 15:21
  • Using true in all configurations appears java error code 2 – Helper Jun 10 '17 at 17:13
  • Using appears: Expecting class path separator ';' before '\Android\android-sdk\build-tools\25.0.3\lib\shrinkedAndroid.jar' in argument number 8 ... D:\\CREATEMULTIDEXMAINDEXCLASSLIST – Helper Jun 10 '17 at 17:15
  • Your Android SDK needs to be somewhere without a space in the path. So `Program Files` is no good. – Luke Pothier Jun 10 '17 at 17:42
  • Thanks @LukePothier, that's right, spaces = headache, I'm compiling well! Now I have to solve other problems that have arisen, I guess with the lists that should be generated in each dex file because I work with Mvvmcross and other plugins as support. – Helper Jun 12 '17 at 07:07
0

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 !!!

Helper
  • 125
  • 1
  • 8