Skip to content

[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 1 commit into from
Apr 28, 2017

Conversation

dellis1972
Copy link
Contributor

Fixes https://bugzilla.xamarin.com/show_bug.cgi?id=33052
Fixes https://bugzilla.xamarin.com/show_bug.cgi?id=38693

The google tooling around multidex is pretty broken on
windows. It does not handle paths with spaces and has
over quoting path issues. This is one reason why we are
shipping our own Proguard.

This commit completely removes the user of mainDexClasses.bat
and introduces code which will create the multidex.keep by
making the required calls manually.

@@ -66,8 +66,8 @@ at com.android.dx.command.dexer.Main.main(Main.java:215)
at com.android.dx.command.Main.main(Main.java:106)
*/
const string ExceptionRegExString = @"(?<exception>java.lang.+):(?<error>.+)";
Regex codeErrorRegEx = new Regex (CodeErrorRegExString, RegexOptions.Compiled);
Regex exceptionRegEx = new Regex (ExceptionRegExString, RegexOptions.Compiled);
protected Regex codeErrorRegEx = new Regex (CodeErrorRegExString, RegexOptions.Compiled);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should probably be protected static readonly. This isn't something that should be changed (readonly), and I can't think of any reason we'd ever need to change this on a per-instance basis (static).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should also be PascalCased as CodeErrorRegex, as it's not a "publicly visible" member.


return cmd.ToString ();
cmd.AppendSwitchIfNotNull ("-jar ", ProguardJarPath);
cmd.AppendSwitchUnquotedIfNotNull ("-injars ", $"{enclosingChar}'" + string.Join ($"{enclosingChar}{Path.PathSeparator}{enclosingChar}", jars) + $"'{enclosingChar}");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought we were going to try to do an -injar per file. Did that not work?

foreach (var j in jars) {
    cmd.AppendSwitchIfNotNull ("-injars ", $"\"{j}\"");
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will give it a go. I forgot, was focused on getting it working lol

cmd.AppendSwitch ("-dontwarn");
cmd.AppendSwitch ("-forceprocessing");
cmd.AppendSwitchIfNotNull ("-outjars ", tempJar);
cmd.AppendSwitchIfNotNull ("-libraryjars ", $"'{Path.Combine (AndroidSdkBuildToolsPath, "lib", "shrinkedAndroid.jar")}'");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why does the value here need quotes? The CommandLineBuilder.AppendSwitchIfNotNull() documentation states:

This method encapsulates individual file names with quotation marks as necessary.

which suggests that this value will be double quoted. Is that necessary?

Copy link
Contributor Author

@dellis1972 dellis1972 Apr 27, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought the same thing. But when there are spaces in the path its Java that throws a wobbly even if its double quoted. I get an access denied error when we access the shrinkedAndroid.jar from Program Files (x86) even with double quotes, add the single quotes and the error goes away. Same for the include later.

Its totally weird, but I did spend some time testing this out. This works :)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed, totally weird. This would make sense if we were going through some "intermediary," such as a batch file/shell script/"wrapper program" which "forwarded" command-line parameters w/o further quoting, but that shouldn't be the case here; we're invoking java.exe, aren't we?

:-/

cmd.AppendSwitch ("-dontoptimize");
cmd.AppendSwitch ("-dontobfuscate");
cmd.AppendSwitch ("-dontpreverify");
cmd.AppendSwitchIfNotNull ("-include ", $"'{Path.Combine (AndroidSdkBuildToolsPath, "mainDexClasses.rules")}'");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto.


void GenerateProguardCommands (CommandLineBuilder cmd)
{
var enclosingChar = OS.IsWindows ? "\"" : string.Empty;
Copy link
Contributor

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.

… path to the Android SDK contains a space

Fixes https://bugzilla.xamarin.com/show_bug.cgi?id=33052
Fixes https://bugzilla.xamarin.com/show_bug.cgi?id=38693

The google tooling around multidex is pretty broken on
windows. It does not handle paths with spaces and has
over quoting path issues. This is one reason why we are
shipping our own Proguard.

This commit completely removes the user of mainDexClasses.bat
and introduces code which will create the ` multidex.keep` by
making the required calls manually.
@dellis1972
Copy link
Contributor Author

ok I just retested this on windows and I have to back out the foreach on the jar file change. Proguard does NOT like it

Error: Expecting class path separator ';' before '\Microsoft' in argument number 2

Also we do need the single quotes on windows otherwise we get

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

for the shrinkedAndroid.jar and

Error: C:\Program Files (Access is denied)

for the mainDexClasses.rules

@jonpryor jonpryor merged commit 6829b7d into dotnet:master Apr 28, 2017
jonpryor pushed a commit that referenced this pull request Feb 22, 2020
Changes: dotnet/java-interop@b81cfbb...4f47ec8

Fixes: dotnet/java-interop#572

Context: dotnet/project-system#1821
Context: dotnet/java-interop#509

  * dotnet/java-interop@4f47ec8: [generator] Make DIM invoking plumbing private (#581)
  * dotnet/java-interop@2a0f863: [Java.Interop.sln] Let VS update the project type guids. (#579)
  * dotnet/java-interop@9a01c9b: [Java.Interop.Tools.Cecil] remove System.Linq in IsSubclassOf (#577)
  * dotnet/java-interop@cd33da6: [generator] Bind protected nested types (#578)
  * dotnet/java-interop@fa10e98 :[generator] Do bind package-private nested types (#575)
jonpryor pushed a commit that referenced this pull request Feb 24, 2020
Changes: dotnet/java-interop@e92f341...178e849

Fixes: dotnet/java-interop#572

Context: dotnet/project-system#1821
Context: dotnet/java-interop#509

  * dotnet/java-interop@178e849: [generator] Make DIM invoking plumbing private (#581)
  * dotnet/java-interop@b7b10bc: [Java.Interop.sln] Let VS update the project type guids. (#579)
  * dotnet/java-interop@3c590a4: [Java.Interop.Tools.Cecil] remove System.Linq in IsSubclassOf (#577)
  * dotnet/java-interop@d1bbed7: [generator] Bind protected nested types (#578)
  * dotnet/java-interop@5db30a8: [generator] Do bind package-private nested types (#575)
@github-actions github-actions bot locked and limited conversation to collaborators Feb 5, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants