Skip to content

Commit 0af3abe

Browse files
committed
[msbuild] Prepare for d8 (new dex compiler)
You can get d8 compiler sources from https://r8.googlesource.com/ d8 expects slightly different set of command line arguments. There is no --no-strict nor --dex arguments, and --output= is not accepted. Classes must be explicitly specified (no assumption on "directory == classes"). With all these changes, I could build apk with this command line: DxJarPath=/path/to/d8.jar DxExtraArguments="--debug" msbuild MyProject.csproj /t:SignAndroidPackage With this change, anyone can offer custom NuGet package for d8 compiler with its own custom MSBuild targets that specifies DxJarPath and DxExtraArguments (just like what we could do for facebook proguard).
1 parent 9ead848 commit 0af3abe

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

src/Xamarin.Android.Build.Tasks/Tasks/CompileToDalvik.cs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ public class CompileToDalvik : JavaToolTask
2020

2121
public string DxJarPath { get; set; }
2222

23+
public string DxExtraArguments { get; set; }
24+
2325
public string JavaToolPath { get; set; }
2426

2527
[Required]
@@ -59,6 +61,7 @@ public override bool Execute ()
5961
Log.LogDebugMessage (" ToolExe: {0}", ToolExe);
6062
Log.LogDebugMessage (" ToolPath: {0}", ToolPath);
6163
Log.LogDebugMessage (" UseDx: {0}", UseDx);
64+
Log.LogDebugMessage (" DxExtraArguments: {0}", DxExtraArguments);
6265
Log.LogDebugMessage (" MultiDexEnabled: {0}", MultiDexEnabled);
6366
Log.LogDebugMessage (" MultiDexMainDexListFile: {0}", MultiDexMainDexListFile);
6467
Log.LogDebugTaskItems (" JavaLibrariesToCompile:", JavaLibrariesToCompile);
@@ -97,23 +100,23 @@ protected override string GenerateCommandLineCommands ()
97100
cmd.AppendSwitchIfNotNull("-Xmx", JavaMaximumHeapSize);
98101

99102
cmd.AppendSwitchIfNotNull ("-jar ", Path.Combine (DxJarPath));
100-
cmd.AppendSwitch ("--no-strict");
101103
}
102104

103-
cmd.AppendSwitch ("--dex");
105+
cmd.AppendSwitch (DxExtraArguments);
104106

105107
if (MultiDexEnabled) {
106108
cmd.AppendSwitch ("--multi-dex");
107109
cmd.AppendSwitchIfNotNull ("--main-dex-list=", MultiDexMainDexListFile);
108110
}
109-
cmd.AppendSwitchIfNotNull ("--output=", Path.GetDirectoryName (ClassesOutputDirectory));
111+
cmd.AppendSwitchIfNotNull ("--output ", Path.GetDirectoryName (ClassesOutputDirectory));
110112

111113

112114
// .jar files
113115
if (File.Exists (OptionalObfuscatedJarFile))
114116
cmd.AppendFileNameIfNotNull (OptionalObfuscatedJarFile);
115117
else {
116-
cmd.AppendFileNameIfNotNull (ClassesOutputDirectory);
118+
foreach (var cls in Directory.GetFiles (ClassesOutputDirectory, "*.class", SearchOption.AllDirectories))
119+
cmd.AppendFileNameIfNotNull (cls);
117120
foreach (var jar in JavaLibrariesToCompile)
118121
cmd.AppendFileNameIfNotNull (jar.ItemSpec);
119122
}

src/Xamarin.Android.Build.Tasks/Xamarin.Android.Common.targets

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -789,6 +789,13 @@ because xbuild doesn't support framework reference assemblies.
789789
Condition="'$(DxJarPath)' == ''"
790790
/>
791791
</CreateProperty>
792+
793+
<CreateProperty Value="--dex --no-strict">
794+
<Output TaskParameter="Value" PropertyName="DxExtraArguments"
795+
Condition="'$(DxExtraArguments)' == ''"
796+
/>
797+
</CreateProperty>
798+
792799
<CreateProperty Value="$(AndroidSdkBuildToolsPath)\">
793800
<Output TaskParameter="Value" PropertyName="DxToolPath"
794801
Condition="'$(UseDx)' == 'True' And '$(DxToolPath)' == ''"
@@ -2029,6 +2036,7 @@ because xbuild doesn't support framework reference assemblies.
20292036
<!-- Compile java code to dalvik -->
20302037
<CompileToDalvik
20312038
DxJarPath="$(DxJarPath)"
2039+
DxExtraArguments="$(DxExtraArguments)"
20322040
JavaToolPath="$(JavaToolPath)"
20332041
JavaMaximumHeapSize="$(JavaMaximumHeapSize)"
20342042
JavaOptions="$(JavaOptions)"

0 commit comments

Comments
 (0)