dotnet / android

.NET for Android provides open-source bindings of the Android SDK for use with .NET managed languages such as C#
MIT License
1.89k stars 525 forks source link

Xamarin.Android application "COMPILETODALVIK : error : no command specified" when using AndroidMultiDexClassListExtraArgs #2585

Open sgong-pdftron opened 5 years ago

sgong-pdftron commented 5 years ago

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

Microsoft Visual Studio Professional 2017 Version 15.9.4 VisualStudio.15.Release/15.9.4+28307.222 Microsoft .NET Framework Version 4.7.03056

Installed Version: Professional

Visual C++ 2017 00370-10250-08191-AA863 Microsoft Visual C++ 2017

Application Insights Tools for Visual Studio Package 8.14.11009.1 Application Insights Tools for Visual Studio

ASP.NET and Web Tools 2017 15.9.04012.0 ASP.NET and Web Tools 2017

ASP.NET Core Razor Language Services 15.8.31590 Provides languages services for ASP.NET Core Razor.

Azure App Service Tools v3.0.0 15.9.03024.0 Azure App Service Tools v3.0.0

C# Tools 2.10.0-beta2-63501-03+b9fb1610c87cccc8ceb74a770dba261a58e39c4a C# components used in the IDE. Depending on your project type and settings, a different version of the compiler may be used.

Common Azure Tools 1.10 Provides common services for use by Azure Mobile Services and Microsoft Azure Tools.

Extensibility Message Bus 1.1.49 (remotes/origin/d15-8@ee674f3) Provides common messaging-based MEF services for loosely coupled Visual Studio extension components communication and integration.

JavaScript Language Service 2.0 JavaScript Language Service

JavaScript Project System 2.0 JavaScript Project System

JavaScript UWP Project System 2.0 JavaScript UWP Project System

Microsoft Continuous Delivery Tools for Visual Studio 0.4 Simplifying the configuration of Azure DevOps pipelines from within the Visual Studio IDE.

Microsoft JVM Debugger 1.0 Provides support for connecting the Visual Studio debugger to JDWP compatible Java Virtual Machines

Microsoft Library Manager 1.0 Install client-side libraries easily to any web project

Microsoft MI-Based Debugger 1.0 Provides support for connecting Visual Studio to MI compatible debuggers

Microsoft Visual C++ Wizards 1.0 Microsoft Visual C++ Wizards

Microsoft Visual Studio Tools for Containers 1.1 Develop, run, validate your ASP.NET Core applications in the target environment. F5 your application directly into a container with debugging, or CTRL + F5 to edit & refresh your app without having to rebuild the container.

Microsoft Visual Studio VC Package 1.0 Microsoft Visual Studio VC Package

MLGen Package Extension 1.0 MLGen Package Visual Studio Extension Detailed Info

Mono Debugging for Visual Studio 4.13.12-pre (9bc9548) Support for debugging Mono processes with Visual Studio.

NuGet Package Manager 4.6.0 NuGet Package Manager in Visual Studio. For more information about NuGet, visit http://docs.nuget.org/.

ProjectServicesPackage Extension 1.0 ProjectServicesPackage Visual Studio Extension Detailed Info

ResourcePackage Extension 1.0 ResourcePackage Visual Studio Extension Detailed Info

ResourcePackage Extension 1.0 ResourcePackage Visual Studio Extension Detailed Info

SQL Server Data Tools 15.1.61810.11040 Microsoft SQL Server Data Tools

Test Adapter for Boost.Test 1.0 Enables Visual Studio's testing tools with unit tests written for Boost.Test. The use terms and Third Party Notices are available in the extension installation directory.

Test Adapter for Google Test 1.0 Enables Visual Studio's testing tools with unit tests written for Google Test. The use terms and Third Party Notices are available in the extension installation directory.

TypeScript Tools 15.9.20918.2001 TypeScript Tools for Microsoft Visual Studio

Visual Basic Tools 2.10.0-beta2-63501-03+b9fb1610c87cccc8ceb74a770dba261a58e39c4a Visual Basic components used in the IDE. Depending on your project type and settings, a different version of the compiler may be used.

Visual F# Tools 10.2 for F# 4.5 15.8.0.0. Commit Hash: 6e26c5bacc8c4201e962f5bdde0a177f82f88691. Microsoft Visual F# Tools 10.2 for F# 4.5

Visual Studio Code Debug Adapter Host Package 1.0 Interop layer for hosting Visual Studio Code debug adapters in Visual Studio

Visual Studio Tools for CMake 1.0 Visual Studio Tools for CMake

Visual Studio Tools for Containers 1.0 Visual Studio Tools for Containers

Visual Studio Tools for Universal Windows Apps 15.0.28307.208 The Visual Studio Tools for Universal Windows apps allow you to build a single universal app experience that can reach every device running Windows 10: phone, tablet, PC, and more. It includes the Microsoft Windows 10 Software Development Kit.

VisualStudio.Mac 1.0 Mac Extension for Visual Studio

Xamarin 4.12.3.77 (d15-9@e3f40b477) Visual Studio extension to enable development for Xamarin.iOS and Xamarin.Android.

Xamarin Designer 4.16.13 (45a16efd4) Visual Studio extension to enable Xamarin Designer tools in Visual Studio.

Xamarin Templates 1.1.128 (6f5ebb2) Templates for building iOS, Android, and Windows apps with Xamarin and Xamarin.Forms.

Xamarin.Android SDK 9.1.4.2 (HEAD/8255f42fc) Xamarin.Android Reference Assemblies and MSBuild support.

Xamarin.iOS and Xamarin.Mac SDK 12.2.1.12 (65ec520) Xamarin.iOS and Xamarin.Mac Reference Assemblies and MSBuild support.

Log File

http://pdftron.s3.amazonaws.com/custom/external/xamarin/dx/full-error-log.txt

winterdouglas commented 5 years ago

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

winterdouglas commented 5 years ago

@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.

sgong-pdftron commented 5 years ago

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

de1081 commented 4 years ago

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