madb icon indicating copy to clipboard operation
madb copied to clipboard

Device rejected command: unkown host service

Open Galacticai opened this issue 5 years ago • 2 comments

Hello I have encountered a weird issue with adb using this repo

Start code

    '( GA_tools = C:\Users\(username)\AppData\Roaming\GeekAssistant\tools )
Public Sub madbCreateBridge(Optional forceNewBridge As Boolean = False)
    Dim madb = Adb.AndroidDebugBridge.CreateBridge($"{GA_tools}\adb.exe", forceNewBridge)
    madb.Start()
End Sub
Public Function madb_GetListOfDevice() As List(Of Adb.Device)
    madbCreateBridge() 'Failsafe  
'' vvv Exception thrown while running this: vvv
    Return Adb.AdbHelper.Instance.GetDevices(Adb.AndroidDebugBridge.SocketAddress)
End Function

Call stack

Managed.Adb.dll!Managed.Adb.AdbHelper.ExecuteRawSocketCommand(System.Net.IPEndPoint address, Managed.Adb.Device device, byte[] command) Line 1117 C#

Managed.Adb.dll!Managed.Adb.AdbHelper.ExecuteRawSocketCommand(System.Net.IPEndPoint address, byte[] command) Line 1079 C#

Managed.Adb.dll!Managed.Adb.AdbHelper.ExecuteRawSocketCommand(System.Net.IPEndPoint address, string command) Line 1069 C#

Managed.Adb.dll!Managed.Adb.AdbHelper.GetDevices(System.Net.IPEndPoint address) Line 667 C#

Geek Assistant (Android AIO).exe!GeekAssistant.madb_Functions.madb_GetListOfDevice() Line 38 Basic

...

Exception thrown at AdbHelper.cs Line 1117

1116 |    if ( !resp.IOSuccess || !resp.Okay ) {
1117 |	    throw new AdbException ( "Device rejected command: {0}".With ( resp.Message ) );
1118 |    }

Debug information:

resp.IOSuccess = true resp.Message = "unkown host service" resp.Okay = false (IPEndPoint) address = {127.0.0.1:5037} (Device) device = null (byte[]) command = byte[19]

Version information:

  • Visual Studio: v16.9.2
  • Managed.Adb: v2.0.131.13916
  • Newtonsoft.Json: v8.0.3
  • morelinq: v1.4.0

Meanwhile outside of madb (using the same adb.exe used above in madb):

PS C:\Users\(username)\AppData\Roaming\GeekAssistant\tools> adb devices
List of devices attached
09...(Serial Number)        device

Galacticai avatar Apr 09 '21 10:04 Galacticai

Update:

Cannot reproduce in Managed.Adb v2.0.82.7204

Galacticai avatar Apr 13 '21 10:04 Galacticai

Old report, but... I had this same issue. It has to do with the latest version od adb.exe. Not sure which version it breaks in, but the latest version does NOT want the \n at the end of the command string. I altered the code in AdbHelper.cs to remove the \n.

public byte[] FormAdbRequest ( String req ) {
	String resultStr = String.Format ( "{0}{1}", req.Length.ToString ( "X4" ), req );
	byte[] result;
	try {
		result = resultStr.GetBytes ( AdbHelper.DEFAULT_ENCODING );
	} catch ( EncoderFallbackException efe ) {
		Log.e ( TAG, efe );
		return null;
	}
	System.Diagnostics.Debug.Assert ( result.Length == req.Length + 4, String.Format ( "result: {1}{0}\nreq: {3}{2}", result.Length, result.GetString ( AdbHelper.DEFAULT_ENCODING ), req.Length, req ) );
	return result;
}

That seems to have done the trick

NebulaSleuth avatar Jun 15 '22 21:06 NebulaSleuth

Old report, but... I had this same issue. It has to do with the latest version od adb.exe. Not sure which version it breaks in, but the latest version does NOT want the \n at the end of the command string. I altered the code in AdbHelper.cs to remove the \n.

public byte[] FormAdbRequest ( String req ) {
	String resultStr = String.Format ( "{0}{1}", req.Length.ToString ( "X4" ), req );
	byte[] result;
	try {
		result = resultStr.GetBytes ( AdbHelper.DEFAULT_ENCODING );
	} catch ( EncoderFallbackException efe ) {
		Log.e ( TAG, efe );
		return null;
	}
	System.Diagnostics.Debug.Assert ( result.Length == req.Length + 4, String.Format ( "result: {1}{0}\nreq: {3}{2}", result.Length, result.GetString ( AdbHelper.DEFAULT_ENCODING ), req.Length, req ) );
	return result;
}

That seems to have done the trick

解决了我的问题 感谢

lingy-Mg avatar Mar 16 '24 10:03 lingy-Mg