diff --git a/src/Xamarin.Android.Build.Tasks/Tasks/CreateMultiDexMainDexClassList.cs b/src/Xamarin.Android.Build.Tasks/Tasks/CreateMultiDexMainDexClassList.cs index d2a21bd3ed5..745541847bf 100644 --- a/src/Xamarin.Android.Build.Tasks/Tasks/CreateMultiDexMainDexClassList.cs +++ b/src/Xamarin.Android.Build.Tasks/Tasks/CreateMultiDexMainDexClassList.cs @@ -75,31 +75,28 @@ protected override string GenerateCommandLineCommands () void GenerateProguardCommands (CommandLineBuilder cmd) { - var enclosingChar = OS.IsWindows ? "\"" : string.Empty; + var enclosingChar = OS.IsWindows ? "\"" : "'"; var jars = JavaLibraries.Select (i => i.ItemSpec).Concat (new string [] { Path.Combine (ClassesOutputDirectory, "classes.zip") }); cmd.AppendSwitchIfNotNull ("-jar ", ProguardJarPath); - cmd.AppendSwitchUnquotedIfNotNull ("-injars ", $"{enclosingChar}'" + string.Join ($"{ProguardInputJarFilter}'{Path.PathSeparator}'", jars) + $"{ProguardInputJarFilter}'{enclosingChar}"); + cmd.AppendSwitchUnquotedIfNotNull ("-injars ", $"{enclosingChar}" + string.Join ($"{ProguardInputJarFilter}{enclosingChar}{Path.PathSeparator}{enclosingChar}", jars) + $"{ProguardInputJarFilter}{enclosingChar}"); cmd.AppendSwitch ("-dontwarn"); cmd.AppendSwitch ("-forceprocessing"); cmd.AppendSwitchIfNotNull ("-outjars ", tempJar); - cmd.AppendSwitchIfNotNull ("-libraryjars ", $"'{Path.Combine (AndroidSdkBuildToolsPath, "lib", "shrinkedAndroid.jar")}'"); + cmd.AppendSwitchIfNotNull ("-libraryjars ", $"{enclosingChar}{Path.Combine (AndroidSdkBuildToolsPath, "lib", "shrinkedAndroid.jar")}{enclosingChar}"); cmd.AppendSwitch ("-dontoptimize"); cmd.AppendSwitch ("-dontobfuscate"); cmd.AppendSwitch ("-dontpreverify"); - cmd.AppendSwitchUnquotedIfNotNull ("-include ", $"{enclosingChar}'{Path.Combine (AndroidSdkBuildToolsPath, "mainDexClasses.rules")}'{enclosingChar}"); + cmd.AppendSwitchUnquotedIfNotNull ("-include ", $"{enclosingChar}{Path.Combine (AndroidSdkBuildToolsPath, "mainDexClasses.rules")}{enclosingChar}"); } void GenerateMainDexListBuilderCommands(CommandLineBuilder cmd) { - var enclosingDoubleQuote = OS.IsWindows ? "\"" : string.Empty; - var enclosingQuote = OS.IsWindows ? string.Empty : "'"; + var enclosingChar = OS.IsWindows ? "\"" : "'"; var jars = JavaLibraries.Select (i => i.ItemSpec).Concat (new string [] { Path.Combine (ClassesOutputDirectory, "classes.zip") }); cmd.AppendSwitchIfNotNull ("-Djava.ext.dirs=", Path.Combine (AndroidSdkBuildToolsPath, "lib")); cmd.AppendSwitch ("com.android.multidex.MainDexListBuilder"); - cmd.AppendSwitch ($"{enclosingDoubleQuote}{tempJar}{enclosingDoubleQuote}"); - cmd.AppendSwitchUnquotedIfNotNull ("", $"{enclosingDoubleQuote}{enclosingQuote}" + - string.Join ($"{enclosingQuote}{Path.PathSeparator}{enclosingQuote}", jars) + - $"{enclosingQuote}{enclosingDoubleQuote}"); + cmd.AppendSwitchUnquotedIfNotNull ("", $"{enclosingChar}{tempJar}{enclosingChar}"); + cmd.AppendSwitchUnquotedIfNotNull ("", enclosingChar + string.Join ($"{enclosingChar}{Path.PathSeparator}{enclosingChar}", jars) + enclosingChar); writeOutputToKeepFile = true; } diff --git a/src/Xamarin.Android.Build.Tasks/Tasks/Proguard.cs b/src/Xamarin.Android.Build.Tasks/Tasks/Proguard.cs index 31f716edc09..29ed6b14a35 100644 --- a/src/Xamarin.Android.Build.Tasks/Tasks/Proguard.cs +++ b/src/Xamarin.Android.Build.Tasks/Tasks/Proguard.cs @@ -140,10 +140,10 @@ protected override string GenerateCommandLineCommands () var injars = new List (); var libjars = new List (); - injars.Add (classesZip); + injars.Add (classesZip + ProguardInputJarFilter); if (JavaLibrariesToEmbed != null) foreach (var jarfile in JavaLibrariesToEmbed) - injars.Add (jarfile.ItemSpec); + injars.Add (jarfile.ItemSpec + ProguardInputJarFilter); using (var xamcfg = File.Create (ProguardCommonXamarinConfiguration)) GetType ().Assembly.GetManifestResourceStream ("proguard_xamarin.cfg").CopyTo (xamcfg); @@ -158,11 +158,11 @@ protected override string GenerateCommandLineCommands () .Select (s => s.Trim ()) .Where (s => !string.IsNullOrWhiteSpace (s)); - var enclosingChar = OS.IsWindows ? "\"" : string.Empty; + var enclosingChar = OS.IsWindows ? "\"" : "'"; foreach (var file in configs) { if (File.Exists (file)) - cmd.AppendSwitchUnquotedIfNotNull ("-include ", $"{enclosingChar}'{file}'{enclosingChar}"); + cmd.AppendSwitchUnquotedIfNotNull ("-include ", $"{enclosingChar}{file}{enclosingChar}"); else Log.LogWarning ("Proguard configuration file '{0}' was not found.", file); } @@ -172,10 +172,9 @@ protected override string GenerateCommandLineCommands () foreach (var jarfile in ExternalJavaLibraries.Select (p => p.ItemSpec)) libjars.Add (jarfile); - cmd.AppendSwitchUnquotedIfNotNull ("-injars ", $"{enclosingChar}'" + string.Join ($"{ProguardInputJarFilter}'{Path.PathSeparator}'", injars.Distinct ()) + $"{ProguardInputJarFilter}'{enclosingChar}"); - - cmd.AppendSwitchUnquotedIfNotNull ("-libraryjars ", $"{enclosingChar}'" + string.Join ($"'{Path.PathSeparator}'", libjars.Distinct ()) + $"'{enclosingChar}"); - + string delimiter = $"{enclosingChar}{Path.PathSeparator}{enclosingChar}"; + cmd.AppendSwitchUnquotedIfNotNull ("-injars ", enclosingChar + string.Join (delimiter, injars.Distinct ()) + enclosingChar); + cmd.AppendSwitchUnquotedIfNotNull ("-libraryjars ", enclosingChar + string.Join (delimiter, libjars.Distinct ()) + enclosingChar); cmd.AppendSwitchIfNotNull ("-outjars ", ProguardJarOutput); if (EnableLogging) { diff --git a/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/BuildTest.cs b/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/BuildTest.cs index a30f1f963c6..d77afb397cb 100644 --- a/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/BuildTest.cs +++ b/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/BuildTest.cs @@ -1656,25 +1656,31 @@ public void BuildReleaseApplication () } [Test] - public void BuildReleaseApplicationWithSpacesInPath () + public void BuildApplicationWithSpacesInPath ([Values (true, false)] bool isRelease, [Values (true, false)] bool enableProguard, [Values (true, false)] bool enableMultiDex) { var proj = new XamarinAndroidApplicationProject () { - IsRelease = true, - AotAssemblies = true, + IsRelease = isRelease, + AotAssemblies = isRelease, + EnableProguard = enableProguard, }; - proj.Imports.Add (new Import ("foo.targets") { - TextContent = () => @" + if (enableMultiDex) + proj.SetProperty ("AndroidEnableMultiDex", "True"); + + if (isRelease) { + proj.Imports.Add (new Import ("foo.targets") { + TextContent = () => @" - False + False ", - }); - using (var b = CreateApkBuilder (Path.Combine ("temp", "BuildReleaseAppWithA InIt(1)"))) { + }); + } + using (var b = CreateApkBuilder (Path.Combine ("temp", $"BuildReleaseAppWithA InIt({isRelease}{enableProguard}{enableMultiDex})"))) { Assert.IsTrue (b.Build (proj), "Build should have succeeded."); } } @@ -2209,6 +2215,7 @@ public void foo() using (var builder = CreateApkBuilder (Path.Combine ("temp", TestContext.CurrentContext.Test.Name))) { builder.ThrowOnBuildFailure = false; Assert.AreEqual (enableDesugar, builder.Build (proj), "Unexpected build result"); + Assert.IsFalse (builder.LastBuildOutput.ContainsText ("Duplicate zip entry"), "Should not get warning about [META-INF/MANIFEST.MF]"); } } }