adb_client icon indicating copy to clipboard operation
adb_client copied to clipboard

Unable to install APK to usb device

Open zamonary1 opened this issue 8 months ago • 21 comments

I use this library in my project involving a usb connected device, and this library just hangs forever. I am using it as a git repo in cargo.toml. I think that i am doing something wrong.

use adb_client::{ADBDeviceExt, ADBUSBDevice};

fn main() {
    let product_id = 0x0000;
    let vendor_id = 0x0000; // edited out

    let mut device = ADBUSBDevice::new(vendor_id, product_id).unwrap();

    device
        .install(&"/home/zamonary1/Загрузки/SlimeVR-android.apk")
        .unwrap();
}

zamonary1 avatar Apr 28 '25 16:04 zamonary1

It was running for 4.6 minutes and i had to stop it manually Image

zamonary1 avatar Apr 28 '25 16:04 zamonary1

Hello, have you tried running it with RUST_LOG=debug ? Also have you accepted the prompt on the device when running the command ?

cocool97 avatar Apr 28 '25 17:04 cocool97

I was not prompted on my phone because i already accepted the connection to this PC while using google's adb.

I waited for a couple of minutes with set envvar but there is no output whatsoever. Assuming that code works on your setup, that may be the android to blame. My device is nothing phome 2a plus with android 15 and latest update. I could try the example on some of my older devices tomorrow.

zamonary1 avatar Apr 28 '25 19:04 zamonary1

I just checked on it and it gave me something while i was typing. May be the faulty usb tho.

Image

zamonary1 avatar Apr 28 '25 19:04 zamonary1

I was not prompted on my phone because i already accepted the connection to this PC while using google's adb.

I waited for a couple of minutes with set envvar but there is no output whatsoever. Assuming that code works on your setup, that may be the android to blame. My device is nothing phome 2a plus with android 15 and latest update. I could try the example on some of my older devices tomorrow.

Yes, this would help to debug if this is the phone, the library or your computer

cocool97 avatar Apr 29 '25 06:04 cocool97

I just checked on it and it gave me something while i was typing. May be the faulty usb tho.

Image

Are you using a logging crate in your executable ? This is weird that nothing is display at all by the library

cocool97 avatar Apr 29 '25 06:04 cocool97

I tried it on another device running android 10, here is the backtrace with RUST_BACTRACE=full

bktr.txt

zamonary1 avatar Apr 29 '25 11:04 zamonary1

Can you try #111 ? This should fix your issue

cocool97 avatar Apr 30 '25 13:04 cocool97

I don't know why did you close the issue because it is not resolved. The code with android 15 device produces output now, but it errors out still.

bktr2.txt

Please, reopen the issue

zamonary1 avatar May 01 '25 20:05 zamonary1

I can't help you if you don't provide any logs :/ this backtrace does not hold much information..

Please use log crate and a user-facing logging crate like env_logger. Then run your program with RUST_LOG=trace and paste the output

cocool97 avatar May 02 '25 05:05 cocool97

Good news - running code with the latest adb_client release installs the apk on device

Bad news - unwrap() catches some error anyway. Also if you try to run the code again it errors out until you reattach device's cable. I've attached the outputs with RUST_LOG=trace for both runs.

bktr3.zip (first run, installs the app)

bktr4.txt (second run, throws error and does nothing)

zamonary1 avatar May 02 '25 15:05 zamonary1

Thanks for the report and the backtraces, can you try #114 ? Does it fix your issue ?

cocool97 avatar May 07 '25 11:05 cocool97

Unfortunately, the problem is the same. The first run installs the app and throws an error, other runs error out without doing anything. I wasn't even sure that was the new commit but i checked the changes manually. I've tested on android 10 and android 15 devices. I don't count the android 6 device because it refuses to work even with google's adb. I really appreciate your work and understand how hard it is to work on such a big codebase. Thank you anyway, i think that i'll try to poke around your code too and find more clues.

Edit: here's the log

zamonary1 avatar May 07 '25 12:05 zamonary1

Hmmm

Can you provide a minimum reproductible example of this bug ? This would greatly help me debugging it :)

cocool97 avatar May 07 '25 14:05 cocool97

Sure! Pretty much no changes from the original source

use adb_client::{ADBDeviceExt, ADBUSBDevice};
use log::*;

fn main() {
    env_logger::init();

    // lsusb:
    // 0e8d:201c MediaTek Inc. A142P

    let vendor_id = 0x0e8d;
    let product_id = 0x201c; // A142P - android 15

    let mut device = ADBUSBDevice::new(vendor_id, product_id).unwrap();

    device
        .install(&"/path/to/file.apk")
        .unwrap();
}

zamonary1 avatar May 07 '25 15:05 zamonary1

Hello, have you been able to replicate the issue?

zamonary1 avatar May 14 '25 15:05 zamonary1

Apart from the related PR, I cannot reproduce on any of my devices..

cocool97 avatar May 14 '25 16:05 cocool97

That's really unfortunate, i'll try the code on my laptops and come back with feedback

zamonary1 avatar May 14 '25 16:05 zamonary1

Good news - i ran the compiled binary on my second machine running arch, and the code worked perfectly with no errors at the end during furst run, but on the second run i am getting the same ONNX, AUTH error. I am going to compile my other project with the latest version of adb_client and send over to friend for testing under windows.

So turns out, the error was just partially because of my setup. I'll test the code under VM to find what exactly breaks it.

zamonary1 avatar May 14 '25 17:05 zamonary1

Hello, my tester has sent me the logs from the app utilizing adb_client, the app crashes and logs contain the following error: ERROR - error while sending CLSE message: no write endpoint setup Please note that he was on windows OS. I think that the error occurs here.

zamonary1 avatar May 15 '25 14:05 zamonary1

I am also encountering this issue. Logging around the install method indicates its hanging inside of std::io::copy, so the writer is not allowing the flow to continue, probably because it's not properly parsing an ack from the Android device.

In my experience it alternates between two states. One run of the program will hang at the copy, the next one will immediately return the error Failed to connect to USB device: USB Error: Input/Output Error, then the cycle repeats.

agg23 avatar Sep 04 '25 02:09 agg23