SharpAdb / AdvancedSharpAdbClient

AdvancedSharpAdbClient is a .NET library that allows .NET, Mono and Unity applications to communicate with Android devices. It's improved version of SharpAdbClient.
https://sharpadb.github.io
Apache License 2.0
199 stars 54 forks source link

The server returned an invalid sync response 0 when trying to pull. #97

Open DanTheMan827 opened 8 months ago

DanTheMan827 commented 8 months ago

Describe the bug

I'm using the adb server included with the Android platform tools.

Android Debug Bridge version 1.0.41
Version 33.0.3-8952118

Host project is .NET 4.8.1, code is as follows

var adb = new AdbClient();
var devices = (await adb.GetDevicesAsync()).ToArray();

if (devices.Length > 0)
{
    var device = devices[0];

    var client = device.CreateDeviceClient();

    var receiver = new ConsoleOutputReceiver();

    await adb.ExecuteRemoteCommandAsync("pm list packages -f -3", device, receiver);

    var pmOutput = receiver.ToString();

    var match = Regex.Match(pmOutput, @"^package:(.*?)=com.beatgames.beatsaber\r?$", RegexOptions.Multiline);

    if (!match.Success)
    {
        MessageBox.Show("Beat Saber not found", "Not Found", MessageBoxButtons.OK, MessageBoxIcon.Error);

        return;
    }

    var beatSaberPath = match.Groups[1].ToString();

    using (var service = new SyncService(adb, device))
    {
        var files = await service.GetDirectoryListingAsync("/sdcard/Android/obb/com.beatgames.beatsaber");
        var dlcTemp = new EasyTempFolder("dlc", Program.TempFolder);
        var apkTemp = new EasyTempFolder("apk", Program.TempFolder);

        Program.Disposables.Add(dlcTemp);
        Program.Disposables.Add(apkTemp);

        var localApkPath = Path.Combine(apkTemp, "beatsaber.apk");

        using (var localFile = File.Create(localApkPath))
        {
            await service.PullAsync(beatSaberPath, localFile, null);
        }
    }
}

From my understanding of the documentation, this should work, but it doesn't. Pulling with adb.exe does however.

Steps to reproduce the bug

Use provided code with Android emulator.

Expected behavior

No response

Screenshots

No response

NuGet package version

3.1.10

.NET Platform

.NET Framework 4.8.x

Platform type

Windows

System version

No response

IDE

Visual Studio 2022

Additional context

No response

wherewhere commented 8 months ago

You can only use SyncService onetime. If it returns 0, you need to ReOpen it.