Xamarin-android: Xamarin.Android application "COMPILETODALVIK : error : no command specified" when using AndroidMultiDexClassListExtraArgs

Created on 4 Jan 2019  路  4Comments  路  Source: xamarin/xamarin-android

Steps to Reproduce

When using AndroidMultiDexClassListExtraArgs mentioned in tutorial article: https://docs.microsoft.com/en-us/xamarin/android/deploy-test/building-apps/build-process, the application project would not build.

  1. Download sample project here:
    http://pdftron.s3.amazonaws.com/custom/external/xamarin/dx/to-xamarin.zip
  2. Open solution projectSrc\PDFNetAndroidXamarin\PDFNetAndroidXamarin.sln
  3. Clean and Build CompleteReaderAndroid project
  4. The following error occurs:
6>COMPILETODALVIK : error : no command specified
6>  usage: (TaskId:522)
6>    dx --dex [--debug] [--verbose] [--positions=<style>] [--no-locals] (TaskId:522)
6>    [--no-optimize] [--statistics] [--[no-]optimize-list=<file>] [--no-strict] (TaskId:522)
6>    [--keep-classes] [--output=<file>] [--dump-to=<file>] [--dump-width=<n>] (TaskId:522)
6>    [--dump-method=<name>[*]] [--verbose-dump] [--no-files] [--core-library] (TaskId:522)
6>    [--num-threads=<n>] [--incremental] [--force-jumbo] [--no-warning] (TaskId:522)
6>    [--multi-dex [--main-dex-list=<file> [--minimal-main-dex]] (TaskId:522)
6>    [--input-list=<file>] [--min-sdk-version=<n>] (TaskId:522)
6>    [<file>.class | <file>.{zip,jar,apk} | <directory>] ... (TaskId:522)
6>      Convert a set of classfiles into a dex file, optionally embedded in a (TaskId:522)
6>      jar/zip. Output name must end with one of: .dex .jar .zip .apk or be a (TaskId:522)
6>      directory. (TaskId:522)
6>      Positions options: none, important, lines. (TaskId:522)
6>      --multi-dex: allows to generate several dex files if needed. This option is (TaskId:522)
6>      exclusive with --incremental, causes --num-threads to be ignored and only (TaskId:522)
6>      supports folder or archive output. (TaskId:522)
6>      --main-dex-list=<file>: <file> is a list of class file names, classes (TaskId:522)
6>      defined by those class files are put in classes.dex. (TaskId:522)
6>      --minimal-main-dex: only classes selected by --main-dex-list are to be put (TaskId:522)
6>      in the main dex. (TaskId:522)
6>      --input-list: <file> is a list of inputs. (TaskId:522)
6>      Each line in <file> must end with one of: .class .jar .zip .apk or be a (TaskId:522)
6>      directory. (TaskId:522)
6>      --min-sdk-version=<n>: Enable dex file features that require at least sdk (TaskId:522)
6>      version <n>. (TaskId:522)
6>    dx --annotool --annotation=<class> [--element=<element types>] (TaskId:522)
6>    [--print=<print types>] (TaskId:522)
6>    dx --dump [--debug] [--strict] [--bytes] [--optimize] (TaskId:522)
6>    [--basic-blocks | --rop-blocks | --ssa-blocks | --dot] [--ssa-step=<step>] (TaskId:522)
6>    [--width=<n>] [<file>.class | <file>.txt] ... (TaskId:522)
6>      Dump classfiles, or transformations thereof, in a human-oriented format. (TaskId:522)
6>    dx --find-usages <file.dex> <declaring type> <member> (TaskId:522)
6>      Find references and declarations to a field or method. (TaskId:522)
6>      <declaring type> is a class name in internal form, like Ljava/lang/Object; (TaskId:522)
6>      <member> is a field or method name, like hashCode. (TaskId:522)
6>    dx -J<option> ... <arguments, in one of the above forms> (TaskId:522)
6>      Pass VM-specific options to the virtual machine that runs dx. (TaskId:522)
6>    dx --version (TaskId:522)
6>      Print the version of this tool (1.14). (TaskId:522)
6>    dx --help (TaskId:522)
6>      Print this message. (TaskId:522)
6>  The command exited with code 1. (TaskId:522)
6>    DexOutputs:  (TaskId:522)
6>Done executing task "CompileToDalvik" -- FAILED. (TaskId:522)
6>Done building target "_CompileToDalvikWithDx" in project "CompleteReaderAndroid.csproj" -- FAILED.: (TargetId:484)

Expected Behavior

Should build

Actual Behavior

Build fails

Version Information

Most helpful comment

@sgong-pdftron I managed to make the build work.
I've been analyzing the generated commands before and after setting those switches for the DxExtraArguments and I noticed that there are differences between them.
Without the switches set, the dx command runs like dx --dex --no-strict {other arguments},
when I set the switches as suggested by the documentation the --dex --no-strict switches are simply ignored, which means that an invalid command is running.

To achieve the same effect as the original command I set the switches as following:

    <DxExtraArguments>--dex --no-strict --force-jumbo</DxExtraArguments>
    <AndroidMultiDexClassListExtraArgs>--disable-annotation-resolution-workaround</AndroidMultiDexClassListExtraArgs>

To make that work I had to cleanup the bin and obj folders.

Now related to the problem itself, I just found out that the DxExtraArguments has those two switches I mentioned above as default:
https://github.com/xamarin/xamarin-android/blob/7c9dea81e5a4abdbe910e227493be95d89456017/src/Xamarin.Android.Build.Tasks/Xamarin.Android.Common.targets#L981
so when we set its value through our .csprj file it simply overrides the default value, which means that the documentation is wrong. That's my assumption.

I hope that was clear enough!

Thank you.

All 4 comments

I'm having the exact same issue here. Looking forward to have an answer on that :)

@sgong-pdftron I managed to make the build work.
I've been analyzing the generated commands before and after setting those switches for the DxExtraArguments and I noticed that there are differences between them.
Without the switches set, the dx command runs like dx --dex --no-strict {other arguments},
when I set the switches as suggested by the documentation the --dex --no-strict switches are simply ignored, which means that an invalid command is running.

To achieve the same effect as the original command I set the switches as following:

    <DxExtraArguments>--dex --no-strict --force-jumbo</DxExtraArguments>
    <AndroidMultiDexClassListExtraArgs>--disable-annotation-resolution-workaround</AndroidMultiDexClassListExtraArgs>

To make that work I had to cleanup the bin and obj folders.

Now related to the problem itself, I just found out that the DxExtraArguments has those two switches I mentioned above as default:
https://github.com/xamarin/xamarin-android/blob/7c9dea81e5a4abdbe910e227493be95d89456017/src/Xamarin.Android.Build.Tasks/Xamarin.Android.Common.targets#L981
so when we set its value through our .csprj file it simply overrides the default value, which means that the documentation is wrong. That's my assumption.

I hope that was clear enough!

Thank you.

@winterdouglas Thank you! Yes your solution is working perfectly for me! Thanks for the help!

@winterdouglas Sorry I'm not following exactly. Should I paste that last line of code into my CSProj file?

Was this page helpful?
0 / 5 - 0 ratings