Skip to content

[Xamarin.Android.Build.Tasks] [VSM][Android] Build error observed with MultiDex + Custom configuration have spaces. #725

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 1 commit into from
Aug 10, 2017
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 @@ -89,12 +89,15 @@ void GenerateProguardCommands (CommandLineBuilder cmd)

void GenerateMainDexListBuilderCommands(CommandLineBuilder cmd)
{
var enclosingChar = OS.IsWindows ? "\"" : string.Empty;
var enclosingDoubleQuote = OS.IsWindows ? "\"" : string.Empty;
var enclosingQuote = OS.IsWindows ? string.Empty : "'";
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 ($"{enclosingChar}{tempJar}{enclosingChar}");
cmd.AppendSwitchUnquotedIfNotNull ("", $"{enclosingChar}" + string.Join ($"{Path.PathSeparator}", jars) + $"{enclosingChar}");
cmd.AppendSwitch ($"{enclosingDoubleQuote}{tempJar}{enclosingDoubleQuote}");
cmd.AppendSwitchUnquotedIfNotNull ("", $"{enclosingDoubleQuote}{enclosingQuote}" +
string.Join ($"{enclosingQuote}{Path.PathSeparator}{enclosingQuote}", jars) +
$"{enclosingQuote}{enclosingDoubleQuote}");
writeOutputToKeepFile = true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -300,9 +300,9 @@ public void BuildProguardEnabledProject (bool isRelease, bool enableProguard, bo
}
}

XamarinAndroidApplicationProject CreateMultiDexRequiredApplication ()
XamarinAndroidApplicationProject CreateMultiDexRequiredApplication (string debugConfigurationName = "Debug", string releaseConfigurationName = "Release")
{
var proj = new XamarinAndroidApplicationProject ();
var proj = new XamarinAndroidApplicationProject (debugConfigurationName, releaseConfigurationName);
proj.OtherBuildItems.Add (new BuildItem (AndroidBuildActions.AndroidJavaSource, "ManyMethods.java") {
TextContent = () => "public class ManyMethods { \n"
+ string.Join (Environment.NewLine, Enumerable.Range (0, 32768).Select (i => "public void method" + i + "() {}"))
Expand Down Expand Up @@ -330,6 +330,17 @@ public void BuildApplicationOver65536Methods ()
}
}

[Test]
public void CreateMultiDexWithSpacesInConfig ()
{
var proj = CreateMultiDexRequiredApplication (releaseConfigurationName: "Test Config");
proj.IsRelease = true;
proj.SetProperty ("AndroidEnableMultiDex", "True");
using (var b = CreateApkBuilder ("temp/CreateMultiDexWithSpacesInConfig")) {
Assert.IsTrue (b.Build (proj), "Build should have succeeded.");
}
}

[Test]
[TestCaseSource ("JackFlagAndFxVersion")]
public void BuildMultiDexApplication (bool useJackAndJill, string fxVersion)
Expand Down Expand Up @@ -1949,7 +1960,7 @@ public void BuildAMassiveApp()
TextContent = () => @"using System;

namespace "+ libName + @" {

public class " + libName + @" {
public static void Foo () {
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ static XamarinAndroidApplicationProject ()

}

public XamarinAndroidApplicationProject ()
public XamarinAndroidApplicationProject (string debugConfigurationName = "Debug", string releaseConfigurationName = "Release")
: base (debugConfigurationName, releaseConfigurationName)
{
SetProperty ("AndroidApplication", "True");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ public override string ProjectTypeGuid {
public IList<BuildItem> Jars { get; private set; }
public IList<BuildItem> Transforms { get; private set; }

public XamarinAndroidBindingProject ()
public XamarinAndroidBindingProject (string debugConfigurationName = "Debug", string releaseConfigurationName = "Release")
: base (debugConfigurationName, releaseConfigurationName)
{
SetProperty ("MonoAndroidJavaPrefix", "Java");
SetProperty ("MonoAndroidTransformPrefix", "Transforms");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ static XamarinAndroidCommonProject ()
}
}

protected XamarinAndroidCommonProject ()
protected XamarinAndroidCommonProject (string debugConfigurationName = "Debug", string releaseConfigurationName = "Release")
: base (debugConfigurationName, releaseConfigurationName)
{
AndroidResources = new List<BuildItem> ();
ItemGroupList.Add (AndroidResources);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ public class XamarinAndroidLibraryProject : XamarinAndroidCommonProject
</resources>
";

public XamarinAndroidLibraryProject ()
public XamarinAndroidLibraryProject (string debugConfigurationName = "Debug", string releaseConfigurationName = "Release")
: base (debugConfigurationName, releaseConfigurationName)
{
SetProperty ("AndroidApplication", "False");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ namespace Xamarin.ProjectTools
{
public abstract class XamarinAndroidProject : XamarinProject
{
protected XamarinAndroidProject ()
protected XamarinAndroidProject (string debugConfigurationName = "Debug", string releaseConfigurationName = "Release")
: base (debugConfigurationName, releaseConfigurationName)
{
Language = XamarinAndroidProjectLanguage.CSharp;
TargetFrameworkVersion = Versions.Marshmallow;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ static XamarinAndroidWearApplicationProject ()
default_layout_round_main = sr.ReadToEnd ();
}

public XamarinAndroidWearApplicationProject ()
public XamarinAndroidWearApplicationProject (string debugConfigurationName = "Debug", string releaseConfigurationName = "Release")
: base (debugConfigurationName, releaseConfigurationName)
{
TargetFrameworkVersion = Versions.KitkatWatch;
UseLatestPlatformSdk = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,13 +124,13 @@ protected bool BuildInternal (string projectOrSolution, string target, string []
ndkPath = Path.GetFullPath (Path.Combine (androidSdkToolPath, "ndk"));
StringBuilder args = new StringBuilder ();
var psi = new ProcessStartInfo (MSBuildExe);
if (Directory.Exists (sdkPath)) {
args.AppendFormat ("/p:AndroidSdkDirectory=\"{0}\" ", sdkPath);
}
if (Directory.Exists (ndkPath)) {
args.AppendFormat ("/p:AndroidNdkDirectory=\"{0}\" ", ndkPath);
}
if (RunXBuild) {
if (Directory.Exists (sdkPath)) {
args.AppendFormat ("/p:AndroidSdkDirectory=\"{0}\" ", sdkPath);
}
if (Directory.Exists (ndkPath)) {
args.AppendFormat ("/p:AndroidNdkDirectory=\"{0}\" ", ndkPath);
}
var outdir = Path.GetFullPath (Path.Combine (FrameworkLibDirectory, "..", ".."));
var targetsdir = Path.Combine (FrameworkLibDirectory, "xbuild");
args.AppendFormat (" {0} ", logger);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,16 @@ public abstract class XamarinProject

public ProjectLanguage Language { get; set; }

protected XamarinProject ()
string debugConfigurationName;
string releaseConfigurationName;

protected XamarinProject (string debugConfigurationName = "Debug", string releaseConfigurationName = "Release")
{
ProjectName = "UnnamedProject";

this.debugConfigurationName = debugConfigurationName;
this.releaseConfigurationName = releaseConfigurationName;

Sources = new List<BuildItem> ();
References = new List<BuildItem> ();
OtherBuildItems = new List<BuildItem> ();
Expand All @@ -37,9 +43,9 @@ protected XamarinProject ()
CommonProperties = new List<Property> ();
common = new PropertyGroup (null, CommonProperties);
DebugProperties = new List<Property> ();
debug = new PropertyGroup ("'$(Configuration)|$(Platform)' == 'Debug|AnyCPU'", DebugProperties);
debug = new PropertyGroup ($"'$(Configuration)|$(Platform)' == '{debugConfigurationName}|AnyCPU'", DebugProperties);
ReleaseProperties = new List<Property> ();
release = new PropertyGroup ("'$(Configuration)|$(Platform)' == 'Release|AnyCPU'", ReleaseProperties);
release = new PropertyGroup ($"'$(Configuration)|$(Platform)' == '{releaseConfigurationName}|AnyCPU'", ReleaseProperties);

PropertyGroups = new List<PropertyGroup> ();
PropertyGroups.Add (common);
Expand All @@ -48,7 +54,7 @@ protected XamarinProject ()

Packages = new List<Package> ();

SetProperty (KnownProperties.Configuration, "Debug", "'$(Configuration)' == ''");
SetProperty (KnownProperties.Configuration, debugConfigurationName, "'$(Configuration)' == ''");
SetProperty ("Platform", "AnyCPU", "'$(Platform)' == ''");
SetProperty ("ErrorReport", "prompt");
SetProperty ("WarningLevel", "4");
Expand All @@ -60,16 +66,16 @@ protected XamarinProject ()
SetProperty (DebugProperties, "DebugSymbols", "true");
SetProperty (DebugProperties, "DebugType", "full");
SetProperty (DebugProperties, "Optimize", "false");
SetProperty (DebugProperties, KnownProperties.OutputPath, Path.Combine ("bin", "Debug"));
SetProperty (DebugProperties, KnownProperties.OutputPath, Path.Combine ("bin", debugConfigurationName));
SetProperty (DebugProperties, "DefineConstants", "DEBUG;");
SetProperty (DebugProperties, KnownProperties.IntermediateOutputPath, Path.Combine ("obj", "Debug"));
SetProperty (DebugProperties, KnownProperties.IntermediateOutputPath, Path.Combine ("obj", debugConfigurationName));

SetProperty (ReleaseProperties, "Optimize", "true");
SetProperty (ReleaseProperties, "ErrorReport", "prompt");
SetProperty (ReleaseProperties, "WarningLevel", "4");
SetProperty (ReleaseProperties, "ConsolePause", "false");
SetProperty (ReleaseProperties, KnownProperties.OutputPath, Path.Combine ("bin", "Release"));
SetProperty (ReleaseProperties, KnownProperties.IntermediateOutputPath, Path.Combine ("obj", "Release"));
SetProperty (ReleaseProperties, KnownProperties.OutputPath, Path.Combine ("bin", releaseConfigurationName));
SetProperty (ReleaseProperties, KnownProperties.IntermediateOutputPath, Path.Combine ("obj", releaseConfigurationName));

Sources.Add (new BuildItem.Source (() => "Properties\\AssemblyInfo" + Language.DefaultExtension) { TextContent = () => ProcessSourceTemplate (AssemblyInfo ?? Language.DefaultAssemblyInfo) });

Expand Down Expand Up @@ -102,8 +108,8 @@ void AddProperties (IList<Property> list, string condition, KeyValuePair<string,
public abstract string ProjectTypeGuid { get; }

public bool IsRelease {
get { return GetProperty (KnownProperties.Configuration) == "Release"; }
set { SetProperty ("Configuration", value ? "Release" : "Debug"); }
get { return GetProperty (KnownProperties.Configuration) == releaseConfigurationName; }
set { SetProperty ("Configuration", value ? releaseConfigurationName : debugConfigurationName); }
}

public IList<Property> ActiveConfigurationProperties {
Expand Down Expand Up @@ -277,6 +283,7 @@ public virtual List<ProjectResource> Save (bool saveProject = true)
list.Add (new ProjectResource () {
Path = import.Project (),
Content = import.TextContent == null ? null : import.TextContent (),
Encoding = System.Text.Encoding.UTF8,
});

return list;
Expand Down