-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathAndroidBuilder.cs
More file actions
117 lines (91 loc) · 3.94 KB
/
Copy pathAndroidBuilder.cs
File metadata and controls
117 lines (91 loc) · 3.94 KB
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
using Beyond.NET.Core;
namespace Beyond.NET.Builder.Android;
public class AndroidBuilder
{
public record BuildResult(
string? AndroidARM64LibraryPath,
string OutputDirectoryPath
);
public string ProductName { get; }
public string OutputDirectory { get; }
public bool BuildAndroidARM64 { get; }
private ILogger Logger => Services.Shared.LoggerService;
private string OutputProductName => ProductName;
private string OutputLibraryFileName => $"lib{OutputProductName}.so";
public AndroidBuilder(
string productName,
string outputDirectory,
bool buildAndroidARM64
)
{
ProductName = productName;
OutputDirectory = outputDirectory;
BuildAndroidARM64 = buildAndroidARM64;
}
public BuildResult Build(
string? androidARM64BuildPath
)
{
Logger.LogInformation("Building Android libraries");
string? androidARM64LibraryPath = null;
if (androidARM64BuildPath is not null && BuildAndroidARM64)
{
androidARM64LibraryPath = Path.Combine(androidARM64BuildPath, OutputLibraryFileName);
if (!File.Exists(androidARM64LibraryPath))
{
var libraryWithoutLibName = OutputLibraryFileName.Replace("lib", "");
androidARM64LibraryPath = Path.Combine(androidARM64BuildPath, libraryWithoutLibName);
}
if (!File.Exists(androidARM64LibraryPath))
{
throw new FileNotFoundException($"Android library not found at {androidARM64BuildPath}");
}
Logger.LogInformation($"Android library found at: {androidARM64LibraryPath}");
}
// Create output directory structure for Android
string androidOutputPath = Path.Combine(OutputDirectory, "android");
Directory.CreateDirectory(androidOutputPath);
if (androidARM64LibraryPath is not null)
{
string arm64OutputDir = Path.Combine(androidOutputPath, "arm64-v8a");
Directory.CreateDirectory(arm64OutputDir);
string destPath = Path.Combine(arm64OutputDir, OutputLibraryFileName);
File.Copy(androidARM64LibraryPath, destPath, true);
Logger.LogInformation($"Copied library to: {destPath}");
}
if (androidARM64BuildPath is not null && BuildAndroidARM64)
{
string debugSymbolsOutputPath = Path.Combine(androidOutputPath, "android-debug-symbols");
Directory.CreateDirectory(debugSymbolsOutputPath);
Logger.LogInformation($"Copying all files from {androidARM64BuildPath} to {debugSymbolsOutputPath}");
CopyAllFiles(androidARM64BuildPath, debugSymbolsOutputPath);
Logger.LogInformation($"Copied debug symbols to: {debugSymbolsOutputPath}");
}
Logger.LogInformation($"Android build completed. Output directory: {androidOutputPath}");
return new BuildResult(
androidARM64LibraryPath,
androidOutputPath
);
}
private void CopyAllFiles(string sourceDirectory, string destinationDirectory)
{
if (!Directory.Exists(sourceDirectory))
{
throw new DirectoryNotFoundException($"Source directory not found: {sourceDirectory}");
}
Directory.CreateDirectory(destinationDirectory);
foreach (string filePath in Directory.GetFiles(sourceDirectory))
{
string fileName = Path.GetFileName(filePath);
string destFilePath = Path.Combine(destinationDirectory, fileName);
File.Copy(filePath, destFilePath, overwrite: true);
Logger.LogDebug($"Copied: {fileName}");
}
foreach (string dirPath in Directory.GetDirectories(sourceDirectory))
{
string dirName = Path.GetFileName(dirPath);
string destDirPath = Path.Combine(destinationDirectory, dirName);
CopyAllFiles(dirPath, destDirPath);
}
}
}