jamesmontemagno / vsts-mobile-tasks

VSTS Tasks for Mobile!
MIT License
79 stars 22 forks source link

[Feature Request] Add support for conditionally changing the android app icon name #44

Open AdamDiament opened 1 year ago

AdamDiament commented 1 year ago

This would be a cool addition and could slot in nicely as an optional parameter to the app bundle id task

There are workarounds out there involving maintaining two separate manifest files and switching them in based on build config, but maintaining multiple build configurations plus an additional file is not ideal.

AdamDiament commented 1 year ago

In the meantime, I am just running a custom powershell script in azure, based heavily on the one that changes the app name in the library

Param(
  [string]$sourcePath,
  [string]$iconName
)

# requies parameters
if(!$sourcePath)
{
    write-host " [!] Missing required input: sourcePath"
    exit 1
} 

write-host "Source path is: $sourcePath"

if(!(Test-Path $sourcePath))
{
    Write-Host " [!] File doesn't exist at specified Android Manifest path: $sourcePath"
    exit 1
}

if(!$iconName)
{
    Write-Host " [!] No iconName specified!"
    exit 1
}

# ---------------------
# --- Configs:
Write-Host " (i) Provided Android Manifest path: $sourcePath"

Write-Host " (i) New Icon Name: $iconName"    

 # Load the manifest file
 [xml] $xam = Get-Content -Path $sourcePath

 # Get the version from Android Manifest
 $NAME = Select-Xml -xml $xam  -Xpath "/manifest/application/@android:icon" -namespace @{android="http://schemas.android.com/apk/res/android"}

 $old_name = $NAME.Node.Value;

 Write-Host " (i) Original Icon Name: $old_name"  

# ---------------------
# --- Main:

Write-Host "Original Manifest:"
Get-Content $sourcePath | Write-Host

$NAME.Node.Value = "@mipmap/$iconName"

$xam.Save($sourcePath)

Write-Host "Final Manifest:"
Get-Content $sourcePath | Write-Host