-
Notifications
You must be signed in to change notification settings - Fork 565
[Xamarin.Android.Build.Tasks] The option for multi-dex fails when the path to the Android SDK contains a space #575
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| // Copyright (C) 2011 Xamarin, Inc. All rights reserved. | ||
| // Copyright (C) 2011 Xamarin, Inc. All rights reserved. | ||
|
|
||
| using System; | ||
| using System.Collections.Generic; | ||
|
|
@@ -12,20 +12,27 @@ | |
|
|
||
| namespace Xamarin.Android.Tasks | ||
| { | ||
| public class CreateMultiDexMainDexClassList : ToolTask | ||
| public class CreateMultiDexMainDexClassList : JavaToolTask | ||
| { | ||
| [Required] | ||
| public string ClassesOutputDirectory { get; set; } | ||
|
|
||
| [Required] | ||
| public string ProguardHome { get; set; } | ||
| public string ProguardJarPath { get; set; } | ||
|
|
||
| [Required] | ||
| public string AndroidSdkBuildToolsPath { get; set; } | ||
|
|
||
| [Required] | ||
| public ITaskItem[] JavaLibraries { get; set; } | ||
|
|
||
| public string MultiDexMainDexListFile { get; set; } | ||
| public ITaskItem[] CustomMainDexListFiles { get; set; } | ||
|
|
||
| Action<CommandLineBuilder> commandlineAction; | ||
| string tempJar; | ||
| bool writeOutputToKeepFile = false; | ||
|
|
||
| public override bool Execute () | ||
| { | ||
| Log.LogDebugMessage ("CreateMultiDexMainDexClassList"); | ||
|
|
@@ -35,45 +42,69 @@ public override bool Execute () | |
| Log.LogDebugTaskItems (" CustomMainDexListFiles:", CustomMainDexListFiles); | ||
| Log.LogDebugMessage (" ToolExe: {0}", ToolExe); | ||
| Log.LogDebugMessage (" ToolPath: {0}", ToolPath); | ||
| Log.LogDebugMessage (" ProguardHome: {0}", ProguardHome); | ||
| Log.LogDebugMessage (" ProguardJarPath: {0}", ProguardJarPath); | ||
|
|
||
| if (CustomMainDexListFiles != null && CustomMainDexListFiles.Any ()) { | ||
| var content = string.Concat (CustomMainDexListFiles.Select (i => File.ReadAllText (i.ItemSpec))); | ||
| File.WriteAllText (MultiDexMainDexListFile, content); | ||
| return true; | ||
| } | ||
|
|
||
| EnvironmentVariables = MonoAndroidHelper.GetProguardEnvironmentVaribles (ProguardHome); | ||
| tempJar = Path.Combine (Path.GetTempPath (), Path.GetRandomFileName () + ".jar"); | ||
| commandlineAction = GenerateProguardCommands; | ||
| // run proguard first | ||
| var retval = base.Execute (); | ||
| if (!retval || Log.HasLoggedErrors) | ||
| return false; | ||
|
|
||
| commandlineAction = GenerateMainDexListBuilderCommands; | ||
| // run java second | ||
|
|
||
| return base.Execute () && !Log.HasLoggedErrors; | ||
|
|
||
| return base.Execute (); | ||
| } | ||
|
|
||
| protected override string GenerateCommandLineCommands () | ||
| { | ||
| var cmd = new CommandLineBuilder (); | ||
| commandlineAction (cmd); | ||
| return cmd.ToString (); | ||
| } | ||
|
|
||
| cmd.AppendSwitch ("--output"); | ||
| cmd.AppendFileNameIfNotNull (MultiDexMainDexListFile); | ||
|
|
||
| void GenerateProguardCommands (CommandLineBuilder cmd) | ||
| { | ||
| var enclosingChar = OS.IsWindows ? "\"" : string.Empty; | ||
| var jars = JavaLibraries.Select (i => i.ItemSpec).Concat (new string [] { ClassesOutputDirectory }); | ||
| string files = string.Join (Path.PathSeparator.ToString (), jars.Select (s => '\'' + s + '\'')); | ||
| if (OS.IsWindows) | ||
| cmd.AppendSwitch ('"' + files + '"'); | ||
| else | ||
| cmd.AppendSwitch (files); | ||
|
|
||
| return cmd.ToString (); | ||
| cmd.AppendSwitchIfNotNull ("-jar ", ProguardJarPath); | ||
| cmd.AppendSwitchUnquotedIfNotNull ("-injars ", $"{enclosingChar}'" + string.Join ($"'{Path.PathSeparator}'", jars) + $"'{enclosingChar}"); | ||
| cmd.AppendSwitch ("-dontwarn"); | ||
| cmd.AppendSwitch ("-forceprocessing"); | ||
| cmd.AppendSwitchIfNotNull ("-outjars ", tempJar); | ||
| cmd.AppendSwitchIfNotNull ("-libraryjars ", $"'{Path.Combine (AndroidSdkBuildToolsPath, "lib", "shrinkedAndroid.jar")}'"); | ||
| cmd.AppendSwitch ("-dontoptimize"); | ||
| cmd.AppendSwitch ("-dontobfuscate"); | ||
| cmd.AppendSwitch ("-dontpreverify"); | ||
| cmd.AppendSwitchIfNotNull ("-include ", $"'{Path.Combine (AndroidSdkBuildToolsPath, "mainDexClasses.rules")}'"); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ditto. |
||
| } | ||
|
|
||
| protected override string ToolName { | ||
| get { | ||
| return OS.IsWindows ? "mainDexClasses.bat" : "mainDexClasses"; | ||
| } | ||
| void GenerateMainDexListBuilderCommands(CommandLineBuilder cmd) | ||
| { | ||
| var jars = JavaLibraries.Select (i => i.ItemSpec).Concat (new string [] { ClassesOutputDirectory }); | ||
| cmd.AppendSwitchIfNotNull ("-Djava.ext.dirs=", Path.Combine (AndroidSdkBuildToolsPath, "lib")); | ||
| cmd.AppendSwitch ("com.android.multidex.MainDexListBuilder"); | ||
| cmd.AppendSwitch (tempJar); | ||
| cmd.AppendSwitchUnquotedIfNotNull ("", "\"" + string.Join ($"{Path.PathSeparator}", jars) + "\""); | ||
| writeOutputToKeepFile = true; | ||
| } | ||
|
|
||
| protected override string GenerateFullPathToTool () | ||
| protected override void LogEventsFromTextOutput (string singleLine, MessageImportance messageImportance) | ||
| { | ||
| return Path.Combine (ToolPath, ToolExe); | ||
| var match = CodeErrorRegEx.Match (singleLine); | ||
| var exceptionMatch = ExceptionRegEx.Match (singleLine); | ||
|
|
||
| if (writeOutputToKeepFile && !match.Success && !exceptionMatch.Success) | ||
| File.AppendAllText (MultiDexMainDexListFile, singleLine); | ||
| base.LogEventsFromTextOutput (singleLine, messageImportance); | ||
| } | ||
| } | ||
| } | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't appear to be used anywhere. I think it's vestigial.