Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
15 changes: 7 additions & 8 deletions src/Xamarin.Android.Build.Tasks/Tasks/Proguard.cs
Original file line number Diff line number Diff line change
Expand Up @@ -140,10 +140,10 @@ protected override string GenerateCommandLineCommands ()

var injars = new List<string> ();
var libjars = new List<string> ();
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);
Expand All @@ -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);
}
Expand All @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 = () => @"<?xml version=""1.0"" encoding=""utf-16""?>
if (enableMultiDex)
proj.SetProperty ("AndroidEnableMultiDex", "True");

if (isRelease) {
proj.Imports.Add (new Import ("foo.targets") {
TextContent = () => @"<?xml version=""1.0"" encoding=""utf-16""?>
<Project ToolsVersion=""4.0"" xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
<Target Name=""_Foo"" AfterTargets=""_SetLatestTargetFrameworkVersion"">
<PropertyGroup>
<AotAssemblies Condition=""!Exists('$(MonoAndroidBinDirectory)"+ Path.DirectorySeparatorChar + @"cross-arm')"">False</AotAssemblies>
<AotAssemblies Condition=""!Exists('$(MonoAndroidBinDirectory)" + Path.DirectorySeparatorChar + @"cross-arm')"">False</AotAssemblies>
</PropertyGroup>
<Message Text=""$(AotAssemblies)"" />
</Target>
</Project>
",
});
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.");
}
}
Expand Down Expand Up @@ -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]");
}
}
}
Expand Down