Skip to content
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

feat: Add android support for linux #205

Merged
merged 1 commit into from
Nov 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 15 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -156,14 +156,14 @@ jobs:

- manifest: 'manifests/uno.ui.manifest.json'
manifest_name: Stable Upgrade
previous_tool_version: 1.4.2
previous_tool_version: 1.17.0
previous_tool_params: ''
os: macos-11
dotnet_version: 7.0.403

- manifest: 'manifests/uno.ui-preview.manifest.json'
manifest_name: Preview Upgrade
previous_tool_version: 1.4.2
previous_tool_version: 1.17.0
previous_tool_params: '--pre'
os: macos-11
dotnet_version: 7.0.403
Expand Down Expand Up @@ -196,14 +196,14 @@ jobs:

- manifest: 'manifests/uno.ui.manifest.json'
manifest_name: Stable Upgrade
previous_tool_version: 1.4.2
previous_tool_version: 1.17.0
previous_tool_params: ''
os: macos-12
dotnet_version: 7.0.403

- manifest: 'manifests/uno.ui-preview.manifest.json'
manifest_name: Preview Upgrade
previous_tool_version: 1.4.2
previous_tool_version: 1.17.0
previous_tool_params: '--pre'
os: macos-12
dotnet_version: 7.0.403
Expand All @@ -215,6 +215,12 @@ jobs:
# os: macos-12
# dotnet_version: 8.0.100

# Disabled for android emulator setup issues
# - manifest: 'manifests/uno.ui.manifest.json'
# manifest_name: Stable
# os: macos-13
# dotnet_version: 7.0.403

runs-on: ${{ matrix.os }}

steps:
Expand Down Expand Up @@ -337,6 +343,11 @@ jobs:
useConfigFile: true
configFilePath: gitversion.yml

- uses: actions/setup-java@v3
with:
distribution: 'microsoft' # See 'Supported distributions' for available options
java-version: '11'

- name: Install GTK+3
shell: pwsh
run: |
Expand Down
2 changes: 1 addition & 1 deletion UnoCheck/CheckCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ public override async Task<int> ExecuteAsync(CommandContext context, CheckSettin

private async Task<bool> NeedsToolUpdateAsync(CheckSettings settings)
{
if (settings.Manifest is not null && !settings.CI)
if ( (settings.Manifest is not null && !settings.CI) || Debugger.IsAttached)
{
return false;
}
Expand Down
11 changes: 10 additions & 1 deletion UnoCheck/Checkups/AndroidEmulatorCheckup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public IEnumerable<AndroidEmulator> RequiredEmulators
=> Manifest?.Check?.Android?.Emulators;

public override bool IsPlatformSupported(Platform platform)
=> platform == Platform.OSX || platform == Platform.Windows;
=> platform == Platform.OSX || platform == Platform.Windows || platform == Platform.Linux;

public override string Id => "androidemulator";

Expand Down Expand Up @@ -57,6 +57,11 @@ public override Task<DiagnosticResult> Examine(SharedState history)
history.GetEnvironmentVariable("ANDROID_SDK_ROOT") ?? history.GetEnvironmentVariable("ANDROID_HOME"));
avds.AddRange(avdManager.ListAvds());
}
else
{
return Task.FromResult(
new DiagnosticResult(Status.Error, this, $"Unable to find Java {java}"));
}

// Fallback to manually reading the avd files
if (!avds.Any())
Expand Down Expand Up @@ -87,6 +92,10 @@ public override Task<DiagnosticResult> Examine(SharedState history)

preferredDevice = devices.FirstOrDefault(d => d.Name.Contains("pixel", StringComparison.OrdinalIgnoreCase));
}
else
{
ReportStatus($"Unable to find AVD manager", Status.Ok);
}
}
catch (Exception ex)
{
Expand Down
2 changes: 1 addition & 1 deletion UnoCheck/Checkups/AndroidSdkCheckup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public IEnumerable<Manifest.AndroidPackage> RequiredPackages
List<string> temporaryFiles = new List<string>();

public override bool IsPlatformSupported(Platform platform)
=> platform == Platform.OSX || platform == Platform.Windows;
=> platform == Platform.OSX || platform == Platform.Windows || platform == Platform.Linux;

public override bool ShouldExamine(SharedState history)
=> RequiredPackages?.Any() ?? false;
Expand Down
5 changes: 1 addition & 4 deletions UnoCheck/Checkups/DotNetSdkCheckupContributor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,7 @@ public override IEnumerable<Checkup> Contribute(Manifest.Manifest manifest, Shar

if (sdk.Workloads?.Any() ?? false)
{
if (NuGetVersion.Parse(sdkVersion) >= Manifest.DotNetSdk.Version6Preview7)
yield return new DotNetWorkloadsCheckup(sharedState, sdkVersion, workloads, pkgSrcs);
else
yield return new DotNetWorkloadsCheckupLegacy(sharedState, sdkVersion, workloads, pkgSrcs);
yield return new DotNetWorkloadsCheckup(sharedState, sdkVersion, workloads, pkgSrcs);
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions UnoCheck/Checkups/DotNetWorkloadsCheckup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public DotNetWorkloadsCheckup(SharedState sharedState, string sdkVersion, Manife

SdkRoot = dotnet.DotNetSdkLocation.FullName;
SdkVersion = sdkVersion;
RequiredWorkloads = requiredWorkloads;
RequiredWorkloads = requiredWorkloads.Where(w => w.SupportedPlatforms?.Contains(Util.Platform) ?? false).ToArray();
NuGetPackageSources = nugetPackageSources;
}

Expand Down Expand Up @@ -68,7 +68,7 @@ public override async Task<DiagnosticResult> Examine(SharedState history)

var missingWorkloads = new List<Manifest.DotNetWorkload>();

foreach (var rp in RequiredWorkloads.Where(w => w.SupportedPlatforms?.Contains(Util.Platform) ?? false))
foreach (var rp in RequiredWorkloads)
{
var versionParts = rp.Version.Split("/", StringSplitOptions.None);
var workloadVersion = versionParts.First();
Expand Down
89 changes: 0 additions & 89 deletions UnoCheck/Checkups/DotNetWorkloadsCheckupLegacy.cs

This file was deleted.

50 changes: 42 additions & 8 deletions UnoCheck/Checkups/OpenJdkCheckup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Security.Policy;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using Xamarin.Android.Tools;
Expand Down Expand Up @@ -43,7 +44,7 @@ public bool RequireExact
static string PlatformJavaCExtension => Util.IsWindows ? ".exe" : string.Empty;

public override bool IsPlatformSupported(Platform platform)
=> platform == Platform.OSX || platform == Platform.Windows;
=> platform == Platform.OSX || platform == Platform.Windows || platform == Platform.Linux;

public override bool ShouldExamine(SharedState history)
=> Manifest?.Check?.OpenJdk != null;
Expand Down Expand Up @@ -87,7 +88,8 @@ public override Task<DiagnosticResult> Examine(SharedState history)
{
Environment.SetEnvironmentVariable("JAVA_HOME", jdk.Directory.FullName, EnvironmentVariableTarget.Machine);
ReportStatus($"Set Environment Variable: JAVA_HOME={jdk.Directory.FullName}", Status.Ok);
} catch { }
}
catch { }
}
}
else
Expand All @@ -97,10 +99,18 @@ public override Task<DiagnosticResult> Examine(SharedState history)
if (ok)
return Task.FromResult(DiagnosticResult.Ok(this));

var url = Manifest?.Check?.OpenJdk?.Url;
return Task.FromResult(new DiagnosticResult(Status.Error, this,
new Suggestion("Install OpenJDK11",
new BootsSolution(url, "Download and Install Microsoft OpenJDK 11"))));
if (Util.IsLinux)
{
return Task.FromResult(new DiagnosticResult(Status.Error, this,
new Suggestion("Install OpenJDK11", "OpenJDK 11 is missing, follow the installation instructions here: https://learn.microsoft.com/en-us/java/openjdk/install#install-on-ubuntu")));
}
else
{
var url = Manifest?.Check?.OpenJdk?.Url;
return Task.FromResult(new DiagnosticResult(Status.Error, this,
new Suggestion("Install OpenJDK11",
new BootsSolution(url, "Download and Install Microsoft OpenJDK 11"))));
}
}

IEnumerable<OpenJdkInfo> FindJdks()
Expand Down Expand Up @@ -130,7 +140,8 @@ IEnumerable<OpenJdkInfo> FindJdks()

SearchDirectoryForJdks(paths,
Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles), "Microsoft", "Jdk"), true);
} else if (Util.IsMac)
}
else if (Util.IsMac)
{
var ms11Dir = Path.Combine("/Library", "Java", "JavaVirtualMachines", "microsoft-11.jdk", "Contents", "Home");
SearchDirectoryForJdks(paths, ms11Dir, true);
Expand Down Expand Up @@ -163,14 +174,37 @@ IEnumerable<OpenJdkInfo> FindJdks()
SearchDirectoryForJdks(paths, Environment.GetEnvironmentVariable("JAVA_HOME") ?? string.Empty, true);
SearchDirectoryForJdks(paths, Environment.GetEnvironmentVariable("JDK_HOME") ?? string.Empty, true);

var environmentPaths = Environment.GetEnvironmentVariable("PATH")?.Split(';') ?? Array.Empty<string>();
var environmentPaths = Environment.GetEnvironmentVariable("PATH")?.Split(Path.PathSeparator) ?? Array.Empty<string>();

foreach (var envPath in environmentPaths)
{
if (envPath.Contains("java", StringComparison.OrdinalIgnoreCase) || envPath.Contains("jdk", StringComparison.OrdinalIgnoreCase))
SearchDirectoryForJdks(paths, envPath, true);
}

if (Util.IsLinux)
{
var r = ShellProcessRunner.Run("whereis", "-b javac");

if (
r.Success
&& r.StandardOutput.Count > 0
&& r.StandardOutput[0].Split(" ").Skip(1).FirstOrDefault() is { } javacBinPath)
{
var readlinkResult = ShellProcessRunner.Run("readlink", "-f " + javacBinPath);

if (
readlinkResult.Success
&& r.StandardOutput.Count > 0)
{
if (TryGetJavaJdkInfo(readlinkResult.StandardOutput[0], out var jdkInfo))
{
paths.Add(jdkInfo);
}
}
}
}

return paths
.GroupBy(i => i.JavaC.FullName)
.Select(g => g.First());
Expand Down
4 changes: 2 additions & 2 deletions UnoCheck/DotNet/DotNetWorkloadManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,10 @@ public async Task Install(Manifest.DotNetWorkload[] workloads)

string WriteRollbackFile(Manifest.DotNetWorkload[] workloads)
{
var workloadRolback = GetInstalledWorkloadManifestIdsAndVersions();
var workloadRollback = GetInstalledWorkloadManifestIdsAndVersions();

foreach (var workload in workloads)
workloadRolback[workload.WorkloadManifestId] = workload.Version;
workloadRollback[workload.WorkloadManifestId] = workload.Version;

var json = new StringBuilder();
json.AppendLine("{");
Expand Down
7 changes: 6 additions & 1 deletion UnoCheck/Manifest/Urls.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ public partial class Urls
[JsonProperty("linux", NullValueHandling = NullValueHandling.Ignore)]
public Uri Linux { get; set; }

[JsonProperty("linuxArm64", NullValueHandling = NullValueHandling.Ignore)]
public Uri LinuxArm64 { get; set; }

public Uri Get(string version, Platform? platform = default)
{
var uri = For(platform ?? Util.Platform)?.ToString();
Expand All @@ -49,7 +52,9 @@ Uri For(Platform platform)
: (Util.Is64
? Win64 ?? Win
: Win),
Platform.Linux => Linux,
Platform.Linux => Util.IsArm64
? (LinuxArm64 ?? Linux)
: Linux,
_ => Win
};
}
Expand Down
7 changes: 5 additions & 2 deletions manifests/uno.ui.manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,13 @@
"openjdk": {
"version": "11.0",
"urls": {
// Sources https://learn.microsoft.com/en-us/java/openjdk/download#openjdk-11
"win64": "https://aka.ms/download-jdk/microsoft-jdk-$(OPENJDK_VERSION)-windows-x64.msi",
"winArm64": "https://aka.ms/download-jdk/microsoft-jdk-$(OPENJDK_VERSION)-windows-aarch64.msi",
"osx": "https://aka.ms/download-jdk/microsoft-jdk-$(OPENJDK_VERSION)-macos-x64.pkg",
"osxArm64": "https://aka.ms/download-jdk/microsoft-jdk-$(OPENJDK_VERSION)-macos-aarch64.pkg"
"osxArm64": "https://aka.ms/download-jdk/microsoft-jdk-$(OPENJDK_VERSION)-macos-aarch64.pkg",
"linux": "https://aka.ms/download-jdk/microsoft-jdk-$(OPENJDK_VERSION)-linux-x64.tar.gz",
"linuxArm64": "https://aka.ms/download-jdk/microsoft-jdk-$(OPENJDK_VERSION)-linux-aarch64.tar.gz"
}
},
"xcode": {
Expand Down Expand Up @@ -105,7 +108,7 @@
"workloadManifestId": "microsoft.net.sdk.android",
"packageId": "Microsoft.NET.Sdk.Android.Manifest-8.0.100",
"version": "$(ANDROID_SDK_VERSION)",
"supportedPlatforms": [ "Windows", "OSX" ]
"supportedPlatforms": [ "Windows", "OSX", "Linux" ]
},
{
"workloadId": "ios",
Expand Down
Loading