-
Notifications
You must be signed in to change notification settings - Fork 4.7k
/
DexBuilder.cs
56 lines (47 loc) · 1.66 KB
/
DexBuilder.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using System;
using System.IO;
using System.Linq;
using Microsoft.Build.Utilities;
internal sealed class DexBuilder
{
private readonly string _workingDir;
private readonly AndroidSdkHelper _androidSdk;
private readonly TaskLoggingHelper _logger;
public DexBuilder(
TaskLoggingHelper logger,
AndroidSdkHelper buildTools,
string workingDir)
{
_androidSdk = buildTools;
_workingDir = workingDir;
_logger = logger;
}
public void Build(string inputDir, string outputFileName)
{
if (_androidSdk.HasD8)
{
BuildUsingD8(inputDir, outputFileName);
}
else
{
BuildUsingDx(inputDir, outputFileName);
}
}
private void BuildUsingD8(string inputDir, string outputFilePath)
{
string[] classFiles = Directory.GetFiles(inputDir, "*.class", SearchOption.AllDirectories);
if (classFiles.Length == 0)
throw new InvalidOperationException("Didn't find any .class files");
Utils.RunProcess(_logger, _androidSdk.D8Path, $"--no-desugaring {string.Join(" ", classFiles)}", workingDir: _workingDir);
File.Move(
sourceFileName: Path.Combine(_workingDir, "classes.dex"),
destFileName: outputFilePath,
overwrite: true);
}
private void BuildUsingDx(string inputDir, string outputFileName)
{
Utils.RunProcess(_logger, _androidSdk.DxPath, $"--dex --output={outputFileName} {inputDir}", workingDir: _workingDir);
}
}