Skip to content

A fresh install of Android and VS Code fails #8522

Open

Description

@mattleibow

Android application type

.NET Android (net7.0-android, etc.)

Affected platform version

All

Description

I just did a fresh install of VS Code and tried to build an Android app. I followed the instructions to set up Java and the Android SDK. VSCode can build the app, but dotnet build does not.

It fails because it can't find the sdk because I have not set AndroidSdkDirectory. I never set that for builds when using full VS.

I tried setting the correct ANDROID_SDK_ROOT and ANDROID_HOME envvars, but nothing changes.

The output of dotnet build -t:InstallAndroidDependencies -f:net8.0-android also does not say anything. It would be nice if the SDK could be automatically picked up using the default/accepted envvars and not require a .NET-specific setting.

Steps to Reproduce

  1. Clean VS/Sandbox
  2. Install MAUI Dev Kit
  3. Install Java and Android SDK following the directions
  4. Run dotnet build
  5. Observe the error
  6. Run using F5
  7. Observe no error

Did you find any workaround?

Setting an envvar AndroidSdkDirectory to my SDK. This is not really expected and no mention in the docs. I just know to set it because I know MSBuild also checks envvars.

Relevant log output

No response

Activity

  1. mattleibow commented on Nov 19, 2023

    @mattleibow
    MemberAuthor

    This is also an issue because this breaks VS Code intellisense. The design time builds are failing since android is the first TFM. As a result, a fresh VS Code does not work.

  2. dellis1972 commented on Nov 20, 2023

    @dellis1972
    Contributor

    We should probably move this issue to the andorid-sdk-installer repo as that is where the task in question lives.
    That said we should also update the documentation in this repo for this target to say that the AndroidSdkDirectory is required. Currently it doesn't mention it at all.

  3. added this to the .NET 8 Servicing milestone on Nov 20, 2023
  4. mattleibow commented on Nov 20, 2023

    @mattleibow
    MemberAuthor

    What was the issue for also checking the ANDROID_SDK_ROOT or ANDROID_HOME paths as that is a "standard" envvar?

  5. dellis1972 commented on Nov 20, 2023

    @dellis1972
    Contributor

    @mattleibow it was never implemented as both VS and VSForMac always provided a valid to the msbuild property.

  6. mattleibow commented on Nov 20, 2023

    @mattleibow
    MemberAuthor

    But, if I install VS proper and then dotnet build it works, why? I tested now in a plain pwsh prompt after installing VS, no AndroidSdkDirectory envvar needed.

  7. dellis1972 commented on Nov 20, 2023

    @dellis1972
    Contributor

    But, if I install VS proper and then dotnet build it works, why? I tested now in a plain pwsh prompt after installing VS, no AndroidSdkDirectory envvar needed.

    Because the IDE extension for .net android passes that value for 'AndroidSdkDirectory' to the target when it calls it.
    Its funny I thought this was done by the VSCode Maui extension , I seem to remember someone talking about this issue.

  8. dellis1972 commented on Nov 20, 2023

    @dellis1972
    Contributor

    or maybe the VS installer is setting up a system level envvar.

  9. akoeplinger commented on Nov 20, 2023

    @akoeplinger
    Member
  10. mattleibow commented on Nov 20, 2023

    @mattleibow
    MemberAuthor

    OK, so on my machine, the checked paths are:

    • C:\Users\maleib\AppData\Local\Xamarin\MonoAndroid\android-sdk-windows
    • C:\Program Files (x86)\Android\android-sdk
    • C:\Program Files (x86)\Android\android-sdk-windows
    • C:\Program Files\Android\android-sdk
    • C:\Users\maleib\AppData\Local\Android\android-sdk
    • C:\ProgramData\Android\android-sdk
    • C:\android-sdk-windows

    However, the recommended path is:

    • %LOCALAPPDATA%\Android\Sdk
    • C:\Users\maleib\AppData\Local\Android\Sdk

    They are so close, maybe the docs can rather say:

    • %LOCALAPPDATA%\Android\android-sdk

    And maybe mention that there are some special paths so just in case there is some weird case where different devs use different paths and get different results.

    But, a free win might just be to rename Sdk to android-sdk?

  11. akoeplinger commented on Nov 21, 2023

    @akoeplinger
    Member

    I think %LOCALAPPDATA%\Android\Sdk is the default install location that Android Studio uses. We should probably add that to the lookup path.

  12. akoeplinger commented on Apr 14, 2025

    @akoeplinger
    Member

    is this still an issue?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

Area: App+Library BuildIssues when building Library projects or Application projects.

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions