adb got two same serial numbers when connected to

2020-01-24 21:44发布

I have two smart phones (ZTEV788d, system Android 2.3.6) connected to a computer (Ubuntu 11.10) at the same time, using command: adb devices I got this:

List of devices attached
P753A12D    device
P753A12D    device

The serial numbers are the same!

I wrote an application in the computer side to communicate with these two phones, for example install app and push files.

I used these commands:

adb -s P753A12D install XXX.apk
adb -s P753A12D push XXX /sdcard

Now these two phones have the same serial no (P753A12D), when I run these commands I get this error:

error:more than one device

So, my questions are:

  1. Is that normal that two phones to have the same serial no?
  2. Can I change the serial no? if yes, how?
  3. Is there any way to run these install, push commands successfully even if the serial no are the same?

BTW, the WiFi/3G network will be turned off when I'll run the test.

标签: android adb
8条回答
相关推荐>>
2楼-- · 2020-01-24 21:56

The answer given by @mirokropacek works for Linux (and presumably Mac, too) but doesn't work for Windows, unfortunately. This is due to the way the register_usb_transport function is called in Windows. It turns out the devpath parameter is always NULL in Windows. I needed to handle the same situation so I adapted the solution given above to randomly generate a device ID for each device if the serial parameter is NULL or it is empty (zero length).

I don't need to worry about differentiating devices over long periods of time and many devices so generating a pseudo-random number for the device ID with rand, then using sprintf to create a string representation of that ID seems to be sufficient for my needs but YMMV. It only generates a 4-digit hex number but it works well enough for me (for now at least).

查看更多
贼婆χ
3楼-- · 2020-01-24 21:57

I faced the very same problem. It's because the adb tool uses the serial numbers for identification of devices connected to usb instead of their device paths (which are unique for sure).

If you feel up to getting your hands dirty, download the Android source tree, go to system/core/adb/transport.c, change it to something like that:

void register_usb_transport(usb_handle *usb, const char *serial, const char *devpath, unsigned writeable)
{
    atransport *t = calloc(1, sizeof(atransport));
    D("transport: %p init'ing for usb_handle %p (sn='%s')\n", t, usb,
      serial ? serial : "");
    init_usb_transport(t, usb, (writeable ? CS_OFFLINE : CS_NOPERM));
//    if(serial) {
//        t->serial = strdup(serial);
//    }
    if(devpath) {
        t->devpath = strdup(devpath);
        t->serial = strdup(devpath);
    }

type make adb from the top level path and voila. Devices use usb paths for identification. Now you can install & execute all of the devices from Eclipse with one click.

查看更多
Root(大扎)
4楼-- · 2020-01-24 22:01

Additionally you can use below commands when to handle multiple instance attached (device + emulator)

adb -d shell #(or adb -e shell if you're connecting to an emulator).

-d stands for device and -e stands for emulator

查看更多
Root(大扎)
5楼-- · 2020-01-24 22:03

If you don't want to change the device itself, and/or don't have root access, and the device has network access, you could switch to using TCPIP instead of USB:

  1. Switch adb to using TCPIP: adb tcpip 5555
  2. Have adb connect to the device using the network: adb connect yourhostname

I've run this through SSH tunnels where it would connect to localhost, so all devices show up as 'localhost' which is quite unuseful. Adding hosts to /etc/hosts (that all pointed to localhost) fixed that for me.

查看更多
再贱就再见
6楼-- · 2020-01-24 22:03

Now newer adb supports transport ID besides serial number:

-s SERIAL  use device with given serial (overrides $ANDROID_SERIAL)
-t ID      use device with given transport id

Firstly run

adb devices -l

You would see like below:

List of devicos attached
0123456789ABCDEF device usb:123456789X product:Foo V1 model:Foo_ AB device:Bar AB transport_id:2 
0123456789ABCDEF device usb:987654321X product:Foo V1 model:Foo_ AB device:Bar AB transport_id:1

Now you could specify a device with

adb -t 1 install XXX.apk
查看更多
萌系小妹纸
7楼-- · 2020-01-24 22:05

Today I found an easy solution for this issue.

adb devices -l

You'll get list of devices with their qualifiers

List of devices attached
P753A12D device usb:26200000 transport_id:1
P753A12D device usb:24400000 transport_id:2

Then you can use qualifiers instead of serial numbers like this

adb -s usb:26200000 install xxx.apk

or with transport_id and -t

adb -t 1 install xxx.apk
查看更多
登录 后发表回答