Bug 33052 - The option for multi-dex fails when the path to the Android SDK contains a space
Summary: The option for multi-dex fails when the path to the Android SDK contains a space
Status: VERIFIED FIXED
Alias: None
Product: Android
Classification: Xamarin
Component: MSBuild (show other bugs)
Version: unspecified
Hardware: PC Windows
: Normal normal
Target Milestone: 15.3
Assignee: dean.ellis
URL:
: 52975 56614 56983 (view as bug list)
Depends on: 57027
Blocks: 52336 30362 51720
  Show dependency tree
 
Reported: 2015-08-13 09:37 UTC by Dimitar Dobrev
Modified: 2017-06-22 21:31 UTC (History)
23 users (show)

Tags:
Is this bug a regression?: ---
Last known good build:


Attachments
[Verification] Example GOOD diagnostic build output (56.88 KB, application/zip)
2017-06-22 21:30 UTC, Brendan Zagaeski (Xamarin Team, assistant)
Details


Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
VERIFIED FIXED

Description Dimitar Dobrev 2015-08-13 09:37:42 UTC
If the path to the Android SDK contains a space and the option for multi-dex is on for a project, the build fails with:

CREATEMULTIDEXMAINDEXCLASSLIST : error : "part_of_path_before_the_space" (The system cannot find the file specified).

Please tell me which path and where I need to put quotes around so that I can fix it in the mean time.
Comment 1 Udham Singh 2015-08-13 10:16:47 UTC Comment hidden (obsolete)
Comment 2 Dimitar Dobrev 2015-08-13 10:22:23 UTC
Xamarin   3.11.666.0 (ebae43a)
Visual Studio extension to enable development for Xamarin.iOS and Xamarin.Android.

Xamarin.Android   5.1.4.16 (5f55a9ef61c11b6ce0890bc91e4c71b1b92be214)
Visual Studio plugin to enable development for Xamarin.Android.

Xamarin.Forms Intellisense   1.0
Provides intellisense for Xamarin.Forms in the XML editor.

Xamarin.iOS   8.10.2.0 (67b390d0d1bd741582cf7b7fd3ffea08583a3f83)
Visual Studio extension to enable development for Xamarin.iOS.

Xamarin.iOS Unified Migration   1.0
Automated migration for Xamarin iOS Classic projects to Unified

Xamarin.TestCloud.Integration   1.0
Early preview of Xamarin Test Cloud integration



My Xamarin is a little older than yours, could that be the problem?
Also, which one is your OS? Mine is Windows 7 64-bit.
Comment 3 Dimitar Dobrev 2015-08-13 10:23:03 UTC
Oh, you pasted your Windows version. Never mind.
Comment 4 dean.ellis 2015-08-13 11:37:22 UTC
Dimitar

Could you provide the full diagnostic output of the build please, it will help us track down the exact issue. 

http://developer.xamarin.com/guides/android/troubleshooting/troubleshooting/#Diagnostic_MSBuild_Output

Thanks.
Comment 5 Dimitar Dobrev 2015-08-13 12:13:16 UTC
No, I cannot provide it. Your Bugzilla completely refuses to accept the log and so do PasteBin and Pastie. I am also not happy at all that my comment about the difference in versions was completely ignored, especially given that I worked around it by putting single quotes around "ToolPath" in <CreateMultiDexMainDexClassList ... />. To begin with, I find it extremely hard to believe you could not reproduce it. Anyway, this bug is not a problem to me any more. Fix it, if you wish.
Comment 6 Dimitar Dobrev 2015-08-13 13:16:22 UTC
The workaround only works for building, not deploying. Fix this or tell me how to work around it.
Comment 7 Dimitar Dobrev 2015-08-13 13:56:00 UTC
There have been no replies for hours now. This bug blocks my work. Get your act together and fix it.
Comment 8 dean.ellis 2015-08-13 19:25:48 UTC
Dimitar

Sorry for the delay. The most direct work around at this time would be to move your android-sdk and android-ndk to a location which does not contain a space, and then update Visual Studio/Xamarin Studio to use the new locations. Personally I tend to keep those sdks in c:\Android\ as there are known issues on windows and long path names. 

In the mean time we will continue to investigate this issue, the "workaround" of adding quotes to the .targets file would probably not fix all the issues that might arise, we will need to investigate the various Tasks and make sure we update all the locations where this would be a problem. So the chances are other than moving the sdks there is no quick fix as we probably need to change the actual code rather than the .targets file.

So I will investigate this issue, but in the mean time I would recommend moving your sdk installations to a place with no spaces in the path that should enable you to continue working.
Comment 9 Dimitar Dobrev 2015-08-15 07:54:47 UTC
I cannot move it and this blocks my work. Can I get the source code of the task and fix it myself?
Comment 10 Dimitar Dobrev 2015-08-31 12:24:18 UTC
When is this going to be fixed?
Comment 11 dean.ellis 2015-09-03 09:59:35 UTC
Hi Dimitar

I am investigating this issue. Putting the single quotes around the ToolPath did not fix the issue on my development box, so I am having to investigate further. This is going to take some time to figure out and get into a release, I would highly recommend you work around this issue by moving the android ndk and sdks to a location which does not contain a space until we can figure out a way to work around this.
Comment 12 mgwalm 2015-11-18 14:25:48 UTC
I have virtually the same problem, but I slightly different error message:

  CREATEMULTIDEXMAINDEXCLASSLIST : error : Expecting class path separator ';' before '\Android\android-sdk\build-tools\23.0.0\lib\shrinkedAndroid.jar' in argument number 8

My problem has been fixed by doing what was suggested by dean ellis above.

Also, im using V2.* of Xamarin and the bug has still not been fixed.
Comment 13 Dimitar Dobrev 2015-11-20 11:18:39 UTC
When are you finally going to fix this?
Comment 14 Paul Hazlett 2015-12-05 06:12:15 UTC
This bug tripped me up as well even though my SDK path had no spaces in the page, however my project folder did have spaces in it so I removed those as it compiled with multidex enabled.
Comment 15 Mike Rowley 2016-07-15 20:30:10 UTC
This is ridiculous, almost a year and Xamarin can't get a fix for this???

Seriously Xamarin, lets stop with the constant marketing releases and fix the "thousand little cuts" bugs that kill developer productivity!!!
Comment 16 Jon Douglas [MSFT] 2016-09-16 19:43:13 UTC
I can confirm the same behavior with an Android SDK located in C:\Program Files (x86). Moving this directly to C:\ resolves the issue, but it's less than ideal.
Comment 17 Andy 2016-11-16 19:12:56 UTC
This is unbelievably hacky. There should be a real fix.
Comment 18 Andrii Tsok 2016-12-02 23:49:29 UTC Comment hidden (obsolete)
Comment 19 Andrii Tsok 2016-12-02 23:50:57 UTC Comment hidden (obsolete)
Comment 20 Brendan Zagaeski (Xamarin Team, assistant) 2017-03-29 23:09:08 UTC Comment hidden (obsolete)
Comment 21 Brendan Zagaeski (Xamarin Team, assistant) 2017-03-30 02:28:15 UTC
*** Bug 52975 has been marked as a duplicate of this bug. ***
Comment 22 Brendan Zagaeski (Xamarin Team, assistant) 2017-03-30 02:37:49 UTC
## Bookkeeping note

Comment 18 and Comment 19 are about a slightly different problem [1].  The fix for that issue is included in XamarinVS 4.3.0.784, Xamarin.Android 7.1.0.41 (9578cdc) and higher [2].

[1] https://github.com/xamarin/xamarin-android/commit/1c53d6a4e37e82c94a46adfbed89c3d64dfe2cf8

[2] https://developer.xamarin.com/releases/android/xamarin.android_7/xamarin.android_7.1/#Bug_Fixes

I will accordingly tag Comment 18 and Comment 19 as obsolete in the context of this bug report.



The symptoms from Comment 0 and Comment 12 remains the focus of this bug report.
Comment 23 Magnus Johansson 2017-04-25 08:52:45 UTC
Seriously guys?
It is now coming up to 2 years since this bug was reported and you still are not able to fix it?
How many pomp and circumstance, sugar coated marketing circus events featuring J.M. doing a ToDo app in Xamarin Forms on stage surrounded by monkeys do we have to witness before this bug is fixed?
Get your priorities right and fix fundamental bugs in Xamarin!
Comment 24 Ruben Buniatyan 2017-04-25 17:39:47 UTC
Magnus Johansson +1
Comment 25 Chkopo 2017-04-25 19:08:51 UTC
Magnus Johansson +2
Comment 26 dean.ellis 2017-04-26 14:48:56 UTC
a PR is up which should help address this issue [1].
All of the issues in this area were down to the google tooling not being able to handle spaces or escape parameters correctly. Much of the time spent investigating how to fix this was focused on working with or getting fixes for the existing tooling upstream.

However it has become clear that this is not going to happen. So we have reluctantly had to replace the google tools in this area in favour of coding our own solution. This is risky since it means if google changes the way multiplex works between our releases it could potentially break customers until we get a fix out. This has happened before with other tooling such as aapt and build tools.

[1] https://github.com/xamarin/xamarin-android/pull/575
Comment 27 Ruben Buniatyan 2017-04-26 19:32:39 UTC
That makes sense. If this is not a Xamarin-related issue, then I'd prefer to leave this out to avoid potentially worse issues in the future.
Comment 28 Andy 2017-04-26 19:34:51 UTC
You can't just say let it be broken because that's safer. It doesn't work now, so what's safer about it staying broken.
Comment 29 Magnus Johansson 2017-04-26 19:37:42 UTC
Well, the only reason I came across this (pulling my hair out in the process) was that I installed a brand new VS/Xamarin on a PC.

Default Android SDK path seems to be "c:\Program Files(x86)"

With this knowledge in mind, why on earth is that the default location?

(I remember that pre-VS 2017, the default path was %USERPROFILE%\AppData\Local\Xamarin... )
Comment 30 Brendan Zagaeski (Xamarin Team, assistant) 2017-04-26 19:46:36 UTC
> why on earth is that the default location?

See Bug 52336 and Bug 30362 from the "Blocks" list of this bug.  In particular, note that the Android SDK installed by VS 2015 and VS 2017 is shared with tools other than Xamarin.  My understanding is that the upstream Visual Studio team has been discussing changing that default location for future versions of VS 2017.
Comment 31 dean.ellis 2017-04-28 09:17:46 UTC
Interestingly the ndk is installed in 

C:\ProgramData\Microsoft\AndroidNDK

on Windows.
Comment 32 dean.ellis 2017-05-03 13:48:37 UTC
Fixed in Xamarin-android/master/6829b7d1
Comment 34 Valerio Santinelli 2017-05-16 15:47:16 UTC
@dean when is this going to be released? Xamarin 4.5 and the current (at the time I'm writing this) Android 7.1 release still suffers of this same issue.
Comment 35 Brendan Zagaeski (Xamarin Team, assistant) 2017-05-16 17:28:02 UTC
> when is this going to be released?

The "Target Milestone" of the bug is currently set to 15.3 based on the time at which the fix was committed to master.  By default that means that the candidate fix will land as part of the Xamarin 15.3 Release.  A preview version of 15.3 is currently available on Mac [1] and will tentatively be available in the near future on Windows.

[1] https://releases.xamarin.com/alpha-release-15-3-preview-1/

- This Alpha release currently includes Xamarin.Android 7.3.0.13.

- Xamarin.Android 7.3.0.13 is based on xamarin-android commit 7716c28eecbe395da848db0e658061fbddd759ec, which is from about 1 day before the commit mentioned in Comment 32.

- By default the next Alpha preview of the Xamarin 15.3 Release would be very likely to pick up the commit from Comment 32.
Comment 36 Valerio Santinelli 2017-05-16 17:43:59 UTC
Thanks Brendan, so this is likely to be part of the stable 15.3 release. Cheers!
Comment 37 dean.ellis 2017-05-31 15:25:35 UTC
*** Bug 56983 has been marked as a duplicate of this bug. ***
Comment 38 Brendan Zagaeski (Xamarin Team, assistant) 2017-06-01 00:07:24 UTC
## Preliminary verification status: partially verified in development builds, waiting on follow-up Bug 57027

The candidate change from Comment 32 looks good so far to resolve the issue where the Android SDK path contains a space, but it leads to a slightly different issue (Bug 57027) if the _username_ contains a space.
Comment 39 dean.ellis 2017-06-01 08:58:44 UTC
*** Bug 56614 has been marked as a duplicate of this bug. ***
Comment 40 dean.ellis 2017-06-05 09:43:12 UTC Comment hidden (obsolete)
Comment 41 Brendan Zagaeski (Xamarin Team, assistant) 2017-06-22 21:30:32 UTC
Created attachment 23064 [details]
[Verification] Example GOOD diagnostic build output

## Verification status: verified fixed for the 15.3 target release milestone

> GOOD: XamarinVS 4.6.0.271 (a5ed8bf), Xamarin.Android 7.4.0.9 (5f3167a) (unpublished candidate for the _next_ "15.3 release" Beta version)
> GOOD: XamarinVS 4.6.0.240 (60c3d0e), Xamarin.Android 7.4.0.2 (5a73b38) (current "15.3 release" Beta version)
> BAD:  XamarinVS 4.5.0.486 (fec6f88), Xamarin.Android 7.3.1.2 (9dbc4c5) (current "15.2.3 release" Stable version)

(Testing note: The current Beta version Xamarin.Android 7.4.0.2 (5a73b38) produces additional warning messages due to an unrelated issue (tracked in non-public Bug 56882), but that issue is resolved in the new, not-yet-published candidate version Xamarin.Android 7.4.0.9 (5f3167a).)




## Steps followed to test

1. Ensure the Android SDK location set under "Tools > Options > Xamarin > Android Settings > Android SDK Location" in Visual Studio includes at least one space in the path.  For example:

C:\Program Files (x86)\Android\android-sdk


2. Download and unzip attachment 22601 [details] (the test case from Bug 57027).


3. Attempt to build the "MinimalMultidexTest" project in the Release configuration in the Visual Studio IDE.




## GOOD Results

The build succeeds, and the Error List shows no errors.



### Excerpt from the diagnostic build output

>   C:\Program Files\Java\jdk1.8.0_131\\bin\java.exe -Djava.ext.dirs="C:\Program Files (x86)\Android\android-sdk\build-tools\26.0.0\lib" com.android.multidex.MainDexListBuilder "C:\Users\Windows User\AppData\Local\Temp\qar5uthi.nqe.jar" "C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\MonoAndroid\v7.1\mono.android.jar;C:\Program Files (x86)\MSBuild\Xamarin\Android\android-support-multidex.jar;obj\Release\android\bin\classes"  (TaskId:187)
>   android/support/multidex/ZipUtil$CentralDirectory.class (TaskId:187)
>   android/support/multidex/MultiDexApplication.class (TaskId:187)
>   android/support/multidex/MultiDex$V19.class (TaskId:187)
>   android/support/multidex/MultiDex$V4.class (TaskId:187)
>   android/support/multidex/ZipUtil.class (TaskId:187)
>   android/support/multidex/MultiDexExtractor$1.class (TaskId:187)
>   android/support/multidex/MultiDexExtractor.class (TaskId:187)
>   android/support/multidex/MultiDex$V14.class (TaskId:187)
>   android/support/multidex/MultiDex.class (TaskId:187)
> Done executing task "CreateMultiDexMainDexClassList". (TaskId:187)



## BAD Results with the older Xamarin versions (Xamarin.Android 7.3)

The build fails, and the Error List shows the error discussed earlier in the bug report.

> Expecting class path separator ';' before '\Android\android-sdk\build-tools\26.0.0\lib\shrinkedAndroid.jar' in argument number 8


### Excerpts from the diagnostic build output

> C:\Program Files (x86)\Android\android-sdk\build-tools\23.0.3\\mainDexClasses.bat --output obj\Release\multidex.keep "'C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Common7\IDE\ReferenceAssemblies\Microsoft\Framework\MonoAndroid\v7.1\mono.android.jar';'C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\Xamarin\Android\android-support-multidex.jar';'obj\Release\android\bin\classes'"  (TaskId:226)
> CREATEMULTIDEXMAINDEXCLASSLIST : error : Expecting class path separator ';' before '\Android\android-sdk\build-tools\23.0.3\lib\shrinkedAndroid.jar' in argument number 8

> Done executing task "CreateMultiDexMainDexClassList" -- FAILED. (TaskId:226)



## Additional testing environment info (brief)

Microsoft Visual Studio Enterprise 2015
Version 14.0.25431.01 Update 3

Microsoft .NET Framework
Version 4.6.01586

Java JDK 8u131 (1.8.0_131) 64-bit

Android SDK Tools          25.2.5
Android SDK Platform-tools 26
Android SDK Build-tools    26

Android 7.1.1 (API 25) SDK Platform rev. 3

Windows 10 version 1607 (OS Build 14393.0)
US English locale, US Eastern time zone