patagona.AdbClient 2.0.0

.NET 6.0 .NET Standard 2.1
dotnet add package patagona.AdbClient --version 2.0.0
NuGet\Install-Package patagona.AdbClient -Version 2.0.0
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="patagona.AdbClient" Version="2.0.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add patagona.AdbClient --version 2.0.0
#r "nuget: patagona.AdbClient, 2.0.0"
#r directive can be used in F# Interactive, C# scripting and .NET Interactive. Copy this into the interactive tool or source code of the script to reference the package.
// Install patagona.AdbClient as a Cake Addin
#addin nuget:?package=patagona.AdbClient&version=2.0.0

// Install patagona.AdbClient as a Cake Tool
#tool nuget:?package=patagona.AdbClient&version=2.0.0

AdbClient.NET

A .NET Client for the Android Debug Bridge (ADB)

Nuget

Features

  • Simple
  • Thread-Safe
  • Implemented Services:
    • GetHostVersion
    • GetDevices
    • TrackDevices
    • Sync
      • Push
      • Pull
      • List
      • Stat
    • Execute

Compared to madb / SharpAdbClient

  • Pros:
    • Simple
    • Thread-Safe
    • Async
    • CancellationToken support
  • Cons:
    • Lots of services not (yet) implemented (pull requests are welcome)

Examples

Get ADB host version

var adbClient = new AdbServicesClient();
int hostVersion = await adbClient.GetHostVersion();

Get Devices

var adbClient = new AdbServicesClient();
IList<(string Serial, string State)> devices = await adbClient.GetDevices();

Track Devices

This tracks all device changes until the CancellationToken is cancelled (in this case, for 60 seconds)

var adbClient = new AdbServicesClient();
var cts = new CancellationTokenSource(60000);
await foreach ((string Serial, string State) deviceStateChange in adbClient.TrackDevices(cts.Token))
{
    [...]
}

List root directory

var adbClient = new AdbServicesClient();
using(var syncClient = await adbClient.GetSyncClient("abcdefghijklmnop"))
{
    IList<StatEntry> entries = syncClient.List("/");
}

Execute command

Simple
var adbClient = new AdbServicesClient();
int exitCode = await adbClient.Execute("abcdefghijklmnop", "touch", new string[] { "/storage/emulated/0/test.txt" }, null, null, null);
With stdout/stderr redirection
var adbClient = new AdbServicesClient();
using var stdout = new MemoryStream();
using var stderr = new MemoryStream();
int exitCode = await adbClient.Execute("abcdefghijklmnop", "ls", new string[] { "-la", "/storage/emulated/0/test.txt" }, null, stdout, stderr);
if (exitCode != 0)
    throw new Exception(Encoding.UTF8.GetString(stderr.ToArray()));
Console.WriteLine(Encoding.UTF8.GetString(stdout.ToArray())); // prints directory listing
With everything redirected
var adbClient = new AdbServicesClient();
using var stdin = new MemoryStream(Encoding.UTF8.GetBytes("Hello World"));
using var stdout = new MemoryStream();
using var stderr = new MemoryStream();
int exitCode = await adbClient.Execute("abcdefghijklmnop", "cat", new string[] {}, stdin, stdout, stderr);
if (exitCode != 0)
    throw new Exception(Encoding.UTF8.GetString(stderr.ToArray()));
Console.WriteLine(Encoding.UTF8.GetString(stdout.ToArray())); // prints "Hello World"
Product Versions
.NET net5.0 net5.0-windows net6.0 net6.0-android net6.0-ios net6.0-maccatalyst net6.0-macos net6.0-tvos net6.0-windows net7.0 net7.0-android net7.0-ios net7.0-maccatalyst net7.0-macos net7.0-tvos net7.0-windows
.NET Core netcoreapp3.0 netcoreapp3.1
.NET Standard netstandard2.1
MonoAndroid monoandroid
MonoMac monomac
MonoTouch monotouch
Tizen tizen60
Xamarin.iOS xamarinios
Xamarin.Mac xamarinmac
Xamarin.TVOS xamarintvos
Xamarin.WatchOS xamarinwatchos
Compatible target framework(s)
Additional computed target framework(s)
Learn more about Target Frameworks and .NET Standard.
  • .NETStandard 2.1

    • No dependencies.
  • net6.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
2.0.0 119 12/7/2022
1.1.0 142 11/17/2022
1.0.0 136 11/17/2022

- fix!: use uint for stat element size
         - fix: more consistent usage of cancellation token
         - feat: add `host:track-devices support`