Skip to content

detect ANDROID_SDK_ROOT #5502

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

Merged
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
4 changes: 4 additions & 0 deletions eng/Version.Details.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
<Uri>https://github.com/microsoft/clrmd</Uri>
<Sha>d724947392626b66e39b525998a8817447d50380</Sha>
</Dependency>
<Dependency Name="Xamarin.Android.Tools.AndroidSdk" Version="1.0.105-preview.225">
<Uri>https://github.com/dotnet/android</Uri>
<Sha>bf304cf475308547a2a1a342bb9f2e6825cc33cd</Sha>
</Dependency>
Comment on lines +12 to +15
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is probably always going to be "preview" branded and marked as a non-shipping/transport package.

We could track with a subscription, but you probably don't need to update this frequently.

I can manage updating it manually when it matters, such as: > darc update-dependencies --id 276447

</ProductDependencies>
<ToolsetDependencies>
<Dependency Name="Microsoft.DotNet.Arcade.Sdk" Version="10.0.0-beta.25351.106">
Expand Down
1 change: 1 addition & 0 deletions eng/Versions.props
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
<cdbsosversion>10.0.26100.1</cdbsosversion>
<NewtonSoftJsonVersion>13.0.1</NewtonSoftJsonVersion>
<MicrosoftSourceBuildIntermediatesourcebuildreferencepackagesPackageVersion>10.0.622304</MicrosoftSourceBuildIntermediatesourcebuildreferencepackagesPackageVersion>
<XamarinAndroidToolsAndroidSdkVersion>1.0.105-preview.225</XamarinAndroidToolsAndroidSdkVersion>
<!-- Roslyn and analyzers -->
<!-- dotnet/roslyn dependencies -->
<!--
Expand Down
27 changes: 24 additions & 3 deletions src/Tools/dotnet-dsrouter/ADBTcpRouterFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using System.Threading.Tasks;
using Microsoft.Diagnostics.NETCore.Client;
using Microsoft.Extensions.Logging;
using Xamarin.Android.Tools;

namespace Microsoft.Diagnostics.Tools.DiagnosticsServerRouter
{
Expand Down Expand Up @@ -65,7 +66,27 @@ public static void AdbRemovePortReverse(int localPort, int remotePort, bool owns

public static bool RunAdbCommandInternal(string command, string expectedOutput, int expectedExitCode, bool rethrow, ILogger logger)
{
string sdkRoot = Environment.GetEnvironmentVariable("ANDROID_SDK_ROOT");
void sdklogger(TraceLevel level, string message)
{
switch (level)
{
case TraceLevel.Error:
logger?.LogError(message);
break;
case TraceLevel.Warning:
logger?.LogWarning(message);
break;
case TraceLevel.Info:
logger?.LogInformation(message);
break;
case TraceLevel.Verbose:
logger?.LogDebug(message);
break;
}
};

// AndroidSdkInfo checks $ANDROID_SDK_ROOT, $ANDROID_HOME, and default locations.
string sdkRoot = new AndroidSdkInfo(logger: sdklogger).AndroidSdkPath;
string adbTool = "adb";

if (!string.IsNullOrEmpty(sdkRoot))
Expand Down Expand Up @@ -166,7 +187,7 @@ public override void Start()
_ownsPortReverse = false;
Logger.LogError("Failed setting up adb port reverse." +
" This might lead to problems communicating with Android application." +
" Make sure env variable ANDROID_SDK_ROOT is set and points to an Android SDK." +
" Make sure env variable $ANDROID_HOME is set and points to an Android SDK." +
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should probably update our docs as well, https://learn.microsoft.com/en-us/dotnet/core/diagnostics/dotnet-dsrouter, it reference ANDROID_SDK_ROOT as well.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one updates the docs to match this PR:

$" Executing with unknown adb status for port {_localPort}.");
base.Start();
return;
Expand Down Expand Up @@ -245,7 +266,7 @@ public override void Start()
_ownsPortForward = false;
Logger.LogError("Failed setting up adb port forward." +
" This might lead to problems communicating with Android application." +
" Make sure env variable ANDROID_SDK_ROOT is set and points to an Android SDK." +
" Make sure env variable $ANDROID_HOME is set and points to an Android SDK." +
$" Executing with unknown adb status for port {_localPort}.");
return;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Tools/dotnet-dsrouter/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ private static Command AndroidRouterCommand()
private static readonly Option<string> ForwardPortOption =
new("--forward-port", "-fp")
{
Description = "Enable port forwarding, values Android|iOS for TcpClient and only Android for TcpServer. Make sure to set ANDROID_SDK_ROOT before using this option on Android."
Description = "Enable port forwarding, values Android|iOS for TcpClient and only Android for TcpServer. For Android, optionally set $ANDROID_HOME to a valid Android SDK path."
};

private static readonly Option<string> BlockedSignalsOption =
Expand Down
1 change: 1 addition & 0 deletions src/Tools/dotnet-dsrouter/dotnet-dsrouter.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
<PackageReference Include="System.CommandLine" Version="$(SystemCommandLineVersion)" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="$(MicrosoftExtensionsLoggingVersion)" />
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="$(MicrosoftExtensionsLoggingConsoleVersion)" />
<PackageReference Include="Xamarin.Android.Tools.AndroidSdk" Version="$(XamarinAndroidToolsAndroidSdkVersion)" />
</ItemGroup>

</Project>