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

Conversation

StephaneDelcroix
Copy link
Contributor

@StephaneDelcroix StephaneDelcroix commented Jun 16, 2025

this is a draft, as it depends on non-official nuget

Detect the current ANDROID_SDK_ROOT and pick the right adb tool

@StephaneDelcroix
Copy link
Contributor Author

/cc @jonathanpeppers

@StephaneDelcroix StephaneDelcroix force-pushed the stdelc/dev/androidsdkinfo branch from a51fcf6 to 2656299 Compare June 16, 2025 13:56
@StephaneDelcroix StephaneDelcroix force-pushed the stdelc/dev/androidsdkinfo branch from 2656299 to c85f725 Compare June 16, 2025 13:59
@jonathanpeppers
Copy link
Member

I verified the new dependency is already trim/aot compatible:

@StephaneDelcroix StephaneDelcroix marked this pull request as ready for review July 17, 2025 07:36
@StephaneDelcroix StephaneDelcroix requested a review from a team as a code owner July 17, 2025 07:36
Comment on lines 88 to 89
//ANDROID_SDK_ROOT is deprecated
string sdkRoot = Environment.GetEnvironmentVariable("ANDROID_HOME") ?? Environment.GetEnvironmentVariable("ANDROID_SDK_ROOT") ?? new AndroidSdkInfo(logger: sdklogger).AndroidSdkPath;
Copy link
Member

Choose a reason for hiding this comment

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

I was thinking about this...

If $ANDROID_SDK_ROOT is deprecated, we can probably remove it and all mention of this env var. And we should add a new command-line switch to set this path? This could be a separate PR.

Copy link
Member

Choose a reason for hiding this comment

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

How much of this logic is encoded directly into AndroidSdkPath? Maybe it already has logic to check the correct env variables supported by the Android SDK?

When we update this, we should update any documentation that reference the deprecated env variable.

+1 on having a separate optional argument passed to dsrouter, should work when using android profiles or using the forward port argument.

Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

ok, then we should probably drop the env checks here altogether and rely on AndroidSdkPath to provide it.

Comment on lines +12 to +15
<Dependency Name="Xamarin.Android.Tools.AndroidSdk" Version="1.0.105-preview.225">
<Uri>https://github.com/dotnet/android</Uri>
<Sha>bf304cf475308547a2a1a342bb9f2e6825cc33cd</Sha>
</Dependency>
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

@@ -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:

jonathanpeppers added a commit to dotnet/docs that referenced this pull request Jul 24, 2025
Context: https://developer.android.com/tools/variables
Context: dotnet/diagnostics#5502

PR #5502 is adding support to "automatically" find the Android SDK as installed by other tools like Visual Studio, Android Studio, etc.

`$ANDROID_SDK_ROOT` is also deprecated, so updating any messages to mention `$ANDROID_HOME` instead.
Copy link
Member

@tommcdon tommcdon left a comment

Choose a reason for hiding this comment

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

LGTM, thanks!

@jonathanpeppers jonathanpeppers merged commit d7d8500 into dotnet:main Jul 24, 2025
19 checks passed
jonathanpeppers added a commit to dotnet/docs that referenced this pull request Jul 25, 2025
Context: https://developer.android.com/tools/variables
Context: dotnet/diagnostics#5502

PR #5502 is adding support to "automatically" find the Android SDK as installed by other tools like Visual Studio, Android Studio, etc.

`$ANDROID_SDK_ROOT` is also deprecated, so updating any messages to mention `$ANDROID_HOME` instead.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

dotnet-trace with --dsrouter should also set adb env for android
5 participants