Skip to content

Commit

Permalink
Support d8 instead of dx in ApkBuilder (#68084)
Browse files Browse the repository at this point in the history
dx has officially been removed from Android SDK since build-tools version 31.0.0.

Fixes #65087
  • Loading branch information
akoeplinger committed Apr 17, 2022
1 parent fe478d7 commit d81ac24
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/tasks/AndroidAppBuilder/ApkBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ public ApkBuilder(TaskLoggingHelper logger)

// tools:
string dx = Path.Combine(buildToolsFolder, "dx");
string d8 = Path.Combine(buildToolsFolder, "d8");
string aapt = Path.Combine(buildToolsFolder, "aapt");
string zipalign = Path.Combine(buildToolsFolder, "zipalign");
string apksigner = Path.Combine(buildToolsFolder, "apksigner");
Expand Down Expand Up @@ -394,7 +395,20 @@ public ApkBuilder(TaskLoggingHelper logger)
string javaCompilerArgs = $"-d obj -classpath src -bootclasspath {androidJar} -source 1.8 -target 1.8 ";
Utils.RunProcess(logger, javac, javaCompilerArgs + javaActivityPath, workingDir: OutputDir);
Utils.RunProcess(logger, javac, javaCompilerArgs + monoRunnerPath, workingDir: OutputDir);
Utils.RunProcess(logger, dx, "--dex --output=classes.dex obj", workingDir: OutputDir);

if (File.Exists(d8))
{
string[] classFiles = Directory.GetFiles(Path.Combine(OutputDir, "obj"), "*.class", SearchOption.AllDirectories);

if (!classFiles.Any())
throw new InvalidOperationException("Didn't find any .class files");

Utils.RunProcess(logger, d8, $"--no-desugaring {string.Join(" ", classFiles)}", workingDir: OutputDir);
}
else
{
Utils.RunProcess(logger, dx, "--dex --output=classes.dex obj", workingDir: OutputDir);
}

// 3. Generate APK

Expand Down

0 comments on commit d81ac24

Please sign in to comment.