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

"Install-AndroidSDKPackages" not on windows-2022 #8976

Closed
2 of 10 tasks
chavetski opened this issue Dec 7, 2023 · 1 comment
Closed
2 of 10 tasks

"Install-AndroidSDKPackages" not on windows-2022 #8976

chavetski opened this issue Dec 7, 2023 · 1 comment

Comments

@chavetski
Copy link

chavetski commented Dec 7, 2023

Description

Our product requires NDK r19 (yes, I realize this is super old). For months, we've had the below PWSH in an in-line PWSH task that has worked just fine on windows-2022 template:

$sdkRoot = "C:\Android\android-sdk"
$sdkManager = "$sdkRoot\cmdline-tools\latest\bin\sdkmanager.bat"
Install-AndroidSDKPackages -AndroidSDKManagerPath $sdkManager -AndroidSDKRootPath $sdkRoot -AndroidPackages "ndk;19.2.5345600"
# Set default ndk root
$sdkRoot = "C:\Android\android-sdk"
$sdkManager = "$sdkRoot\cmdline-tools\latest\bin\sdkmanager.bat"
$androidPackages = Get-AndroidPackages -AndroidSDKManagerPath $sdkManager
$ndkDefaultVersion = ($androidPackages | Where-Object { $_ -match "ndk;19" }).Split(';')[1]
$ndkRoot = "$sdkRoot\ndk-bundle"
New-Item -Path $ndkRoot -ItemType SymbolicLink -Value "$sdkRoot\ndk\$ndkDefaultVersion"
setx ANDROID_NDK_HOME $ndkRoot /M
setx ANDROID_NDK_PATH $ndkRoot /M
setx ANDROID_NDK_ROOT $ndkRoot /M
(Get-Content -Encoding UTF8 "${ndkRoot}\ndk-build.cmd").replace('%~dp0\build\ndk-build.cmd','"%~dp0\build\ndk-build.cmd"')|Set-Content -Encoding UTF8 "${ndkRoot}\ndk-build.cmd"
          
$androidNDK = "$sdkRoot\ndk\$ndkDefaultVersion"
$env:ANDROID_NDK = $androidNDK
Write-Host "ANDROID_NDK: $env:ANDROID_NDK"
Write-Host "##vso[task.setvariable variable=androidNDKDir]$androidNDK"
Write-Host "androidNDK: $androidNDK"

With the release of 20231205, we're now getting errors stating "Install-AndroidSDKPackages" cannot be found:

Install-AndroidSDKPackages : The term 'Install-AndroidSDKPackages' is not recognized as a name of a cmdlet, function, script file, or executable program.

image

The script came from answers to these issues:

Any assistance would be MUCH appreciated.

After further investigation, I believe this is related to #8877 - which is fine, we just want some guidance.

Platforms affected

  • Azure DevOps
  • GitHub Actions - Standard Runners
  • GitHub Actions - Larger Runners

Runner images affected

  • Ubuntu 20.04
  • Ubuntu 22.04
  • macOS 11
  • macOS 12
  • macOS 13
  • Windows Server 2019
  • Windows Server 2022

Image version and build link

20231205.1.0

Is it regression?

yes. Did NOT happen on 20231126.1.0

Expected behavior

The script to install NDK r19 as it previously was

Actual behavior

Get below error

Install-AndroidSDKPackages : The term 'Install-AndroidSDKPackages' is not recognized as a name of a cmdlet, function, script file, or executable program.

Repro steps

Create a pipeline.yml to run the following PWSH task on a windows-2022 Microsoft-Hosted agent:

- task: PowerShell@2
  displayName: Install NDK r19
  inputs:
    pwsh: true
    targetType: 'inline'
    script: |
      $sdkRoot = "C:\Android\android-sdk"
      $sdkManager = "$sdkRoot\cmdline-tools\latest\bin\sdkmanager.bat"
      Install-AndroidSDKPackages -AndroidSDKManagerPath $sdkManager -AndroidSDKRootPath $sdkRoot -AndroidPackages "ndk;19.2.5345600"
      # Set default ndk root
      $sdkRoot = "C:\Android\android-sdk"
      $sdkManager = "$sdkRoot\cmdline-tools\latest\bin\sdkmanager.bat"
      $androidPackages = Get-AndroidPackages -AndroidSDKManagerPath $sdkManager
      $ndkDefaultVersion = ($androidPackages | Where-Object { $_ -match "ndk;19" }).Split(';')[1]
      $ndkRoot = "$sdkRoot\ndk-bundle"
      New-Item -Path $ndkRoot -ItemType SymbolicLink -Value "$sdkRoot\ndk\$ndkDefaultVersion"
      setx ANDROID_NDK_HOME $ndkRoot /M
      setx ANDROID_NDK_PATH $ndkRoot /M
      setx ANDROID_NDK_ROOT $ndkRoot /M
      (Get-Content -Encoding UTF8 "${ndkRoot}\ndk-build.cmd").replace('%~dp0\build\ndk-build.cmd','"%~dp0\build\ndk-build.cmd"')|Set-Content -Encoding UTF8 "${ndkRoot}\ndk-build.cmd"
      
      $androidNDK = "$sdkRoot\ndk\$ndkDefaultVersion"
      $env:ANDROID_NDK = $androidNDK
      Write-Host "ANDROID_NDK: $env:ANDROID_NDK"
      Write-Host "##vso[task.setvariable variable=androidNDKDir]$androidNDK"
      Write-Host "androidNDK: $androidNDK"

Edit:

I have fixed the issue by replacing the below line:

Install-AndroidSDKPackages -AndroidSDKManagerPath $sdkManager -AndroidSDKRootPath $sdkRoot -AndroidPackages "ndk;19.2.5345600"

With this:

& $sdkManager --sdk_root=$sdkRoot "ndk;19.2.5345600"

I hope this helps someone else who may be having same issue. Please feel free to close this.

@ilia-shipitsin
Copy link
Contributor

thank you for confirming the fix, I'm closing the issue

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

No branches or pull requests

2 participants