Android Tutorial Connecting your device to the IDE

Introduction

A program called adb.exe - Android Debug Bridge - is the key component that is used to communicate between programs on your desktop and the emulator or device. adb can be invoked without user intervention by programs such as Basic4Android and Eclipse but also has a command line interface that can be used by advanced users. adb.exe is provided with the Android SDK and is located, together with other development tools, on early versions of the Android SDK in the <android-sdk-windows>\tools and on more recent versions in the <android-sdk-windows>\platform-tools folder. Unless adb can connect properly to the emulator or device Basic4Android will not be able to load and run applications, however in this event they could still be compiled then copied to the SD card on the device by USB and installed from there. This tutorial tries to explain how to get your device connected to adb so that you can use it with the Basic4Android IDE.


Device SD cards and USB

Although this capability is entirely independent of adb it is worth including here for completeness in describing how devices use USB connections. Android devices have a USB port that when plugged into a desktop lets the SD card on the device look like a USB memory stick. The first time that a device is connected to a desktop by USB Windows should automatically detect this and install the necessary driver without you having to do anything. The SD card will then appear as a disc drive in Windows Explorer and Device Manager while the device is connected. While the SD card is visible to the desktop as a drive the device will not be able to access it as it is unmounted from the device. Some, but not all, devices allow you to mount and unmount the SD card from the device when it is plugged into the desktop USB. Other devices do not offer this option but automatically unmount it on connection to USB and remount it on disconnection. You will have to see how your own device behaves in this regard


The emulator and adb

There should be absolutely no problem using the emulator with Basic4Android. adb will connect automatically and should work well, although I have found that if the emulator is running Android 1.6 the adb connection will frequently drop and cause problems. Therefore I recommend using Android 2.1 or later in the emulator to avoid any possible problems. Also there should be no problem interacting with the emulator with adb in command line mode if that is required. Because the emulator should just work the remainder of this article deals with connecting devices by means of adb.


Devices and adb

In my experience so far devices differ in their USB capability and in their interaction with adb and Windows so the following can only be a guide. Your experience may vary.

adb can connect a device to the desktop by two different means, Wi-Fi and USB. In both cases for adb to recognise the device Settings -> Applications -> Development -> USB debugging must be checked. This runs the adb daemon on the device which communicates with adb on the desktop.


adb and WiFi

To connect to a device wirelessly you need to connect the device to the network by Wi-Fi and obtain the device IP address. This can be found under Settings -> Wireless & Networks -> Wi-Fi Settings. Press the connected network under the WiFi Networks section and a message box will display the connection details.

Before running Basic4Android open a Command Window in the <android-sdk-windows>\tools folder and type the command

adb connect 192.168.0.10

replacing the IP address with the correct one for the device.

if you get an error try specifying the port

adb connect 192.168.0.10:5555

I have encountered only partial functionality with adb over Wi-Fi. I have a tablet that works fine with adb and so with Basic4Android - which is just as well as the tablet lacks the USB connectivity needed for adb. I also have a phone that mostly works with adb in command line mode but adb hangs and doesn't return to the command prompt after performing an install or uninstall although the actual operation on the device is successful. This behaviour means that neither Basic4Android nor Eclipse can be used with the phone over wireless but thankfully they work perfectly over USB.


adb and USB

Many Android devices, but not all like some cheap Chinese Android tablets, have two more USB interfaces "Android ADB Interface" and "Android Composite ADB Interface". These belong to a device that, on successful USB driver installation, appears as "Android Phone" in Device Manager and is used by adb to connect to the phone over USB. If your phone lacks these it may still be possible to connect adb to it by means of wireless as described above.

These Android interfaces, unlike SD card access, need custom USB drivers that are located in the <android-sdk-windows>\usb_driver. In this folder there is a android_winusb.inf file that contains the USB IDs needed to install the drivers for different phones. When a phone is connected and Windows asks for the drivers for this device point it to this folder. If the drivers then fail to install it is likely that the android_winusb.inf does not contain the IDs for the phone. In android_winusb.inf there are two sections the one named [Google.NTx86] contains the details for 32 bit systems, another named [Google.NTamd64] contains the details for 64 bit systems. The two sections are in fact identical. For my phone to be recognised the following details needed to be inserted in each of the two sections mentioned.

;Orange San Francisco
%SingleAdbInterface% = USB_Install, USB\VID_19D2&PID_1354&MI_00
%CompositeAdbInterface% = USB_Install, USB\VID_19D2&PID_1354&MI_02

These necessary details were obtained courtesy of a certain well known Internet search engine. However, rather belatedly, Google now at last has a list of links to manufacturer sites that provide USB drivers for their devices on this page Google USB Driver . The actual link is OEM USB Drivers.

Note that for some devices, like my phone, Windows may try to install the drivers without USB Debugging being enabled on the phone. This is likely to fail even when you point Windows at the drivers that installed successfully with USB Debugging enabled. As this will happen every time the phone is plugged in to USB the solution is to keep USB Debugging enabled. This has no downside as, for this phone at least, the USB access to the SD card is entirely independent of whether USB Debugging is enabled or not.

More on adb and WiFi

Some devices seem to not have the adb daemon enabled for wireless. There is an application called adbWireless that can overcome this for many, but not all, devices. It is available on the Android Market, the latest version is 1.4.1, but it needs root access to the phone to work.

Another application called UniversalAndroot may help here - it worked on my ZTE Blade/Orange SanFrancisco to let me run adbWireless on it. It can be downloaded from universalandroot by clicking one of the links at the bottom of the page by the 2D barcodes.
 
Last edited:

agraham

Expert
Licensed User
Longtime User
Is there any chance post #1 could be edited to fix this?
Done. I note that you seem to have the Android SDK installed under "Program Files". While this is OK on Windows XP I would recommend that you put it elsewhere on Vista and Windows 7 because of the extra protection these OSs give to the contents of Program Files which can on some occasions cause problems.
 

asawyer13

Member
Licensed User
Longtime User
I am new to B4A so if this is explained somewhere else, just let me know.

I have a Droid X. I have B4A 1.10. I have the emulator installed and I can run the Guess My Number app in the emulator. I have the Android Composite ADB Interface showing in the Device Manager on my Win 7 64 bit system.

My Droid has the USB symbol on it.

I am trying to figure out how to run this on my Droid. Can I go into Designer, and connect and it will connect to my Droid since the AVD manager isn't running? Do I somehow compile and copy the apk to my Droid? and then run it from there?

I'm sure it's just something simple that I don't understand.

Alan
 

asawyer13

Member
Licensed User
Longtime User
Okay, I didn't have my Droid set to the correct usb mode.
So now I can see my SD card, and when I go to Tools -> Connect in Designer, my application runs on my Droid when I do an F5.. Cool.

Now if I want to actually deploy it on my Droid, is there a set of instructions on the best way to do that?

This is so cool.

Alan
 

agraham

Expert
Licensed User
Longtime User
Now if I want to actually deploy it on my Droid
You already have. It is installed as a normal application and can be removed like a normal application if you no longer want it. As long as you don't want to upload it to the Android Market you don't need to do anything else.


By the way Tools -> Connect in Designer has no effect on running your application by F5. Connect runs the Designer on the phone. F5 runs your application on the phone.
 

asawyer13

Member
Licensed User
Longtime User
@agraham,
Duh, I didn't notice my app was sitting there in the list of apps on my Droid.
Thanks,
Alan
 

James Moxham

Member
Licensed User
Longtime User
Coming back to this after not programming for a few months and I have forgotten how to get this working. So, for dummies:

1) Turn on the android device. Hit the "menu" button which is near the top right and is four bars one above the other. Click on Settings. Click on Wireless Controls. Click on Wifi Settings. There will be several lines of text. The first is Wifi - connected to "mynetwork". Don't click that. The next is Network Connection. Forget that one too. Then there is "Wifi Networks" under that is "mynetwork" and hopefully it says "connected". Click that, and it should come up with your IP address. Note this. (mine is 192.168.2.2)

2) In windows, Start/Run and type CMD. Browse using the "cd" command to C:\Program Files\Android\android-sdk-windows\platform-tools
Then in the dos window, run this command "adb connect 192.168.2.2" where the ip address is the number noted above.

Now run Basic4Android with this program:
B4X:
'Activity module
Sub Process_Globals
   'These global variables will be declared once when the application starts.
   'These variables can be accessed from all modules.

End Sub

Sub Globals
   'These global variables will be redeclared each time the activity is created.
   'These variables can only be accessed from this module.

End Sub

Sub Activity_Create(FirstTime As Boolean)
    Log("Hello world!")
    Msgbox("Hello world", "First program")
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

I wonder if this could be added somewhere in the Basic4Android program - maybe all this could come up in the error message when you hit the compile button and it fails to connect.

(This is usually because the adb program needs to be told the IP address again).
 

harinder

Active Member
Licensed User
Longtime User
adb.exe

Hello there..I have installed the emulator correctly.But, on connecting the designer to emulator,im asked to restart adb server and then it says can't find adb.exe.Please help.The javac.exe and android.jar file paths are cofigured correctly.Thanks..
 

RandomCoder

Well-Known Member
Licensed User
Longtime User
I know this is an old thread now, but I just wanted to add my own experience connecting an LG Optimus GT540 to the IDE, as it may help someone having similar problems connecting to the IDE.

I followed Andrews instructions meticulously but everything I tried resulted in being unable to connect to the LG even though other devices work perfect. Eventually I found that you could use the command line 'adb devices' to list all devices seen by the PC, and this showed no device connected. That led me to believe that the phone was at fault. Yes I'd checked the box for USB debugging etc but still no joy :BangHead:

The fix for my problem was to remove the SD card, then connect to the PC. As soon as I did, Windows sprang into life and installed a new driver that recognised the phone as an LG and allowed USB debugging. I can now plug the SD card in and still connect to the IDE. So if anyone else is having similar problems it might just be worth trying to remove the SD card to see if it helps.

Regards,
RandomCoder.
 

zouriteman

Member
Licensed User
Longtime User
Unable To Connect

You say that ADB can run with this command line :

ADB connect 192.168.1.xxx ( xxx is my good ethernet adress)

I have the good adress , but the port (5555) seem to not valid , because ADB refuse to run.

message :
"Unable to connect to 192.168.1.xxx:5555"

have you some idea ?
 

siaobukol

Member
hello, can you teach me a step by step procedure on how to connect my BASIC4ANDROID application on my computer desktop using WIFI?
 

enonod

Well-Known Member
Licensed User
Longtime User
Hope I am not out of place here...
I notice on my Viewsonic Viepad 7 that when connecting via usb instead of wi-fi then a usb symbol appears on the notification bar at the top of screen and on the PC I get a CD drive but it is not showing the SD Card.

To actually see the SD I must pull down the notification bar which then has an entry 'USB connected' which instructs to tap (select) to copy files to/from computer.
On tapping, a button appears on Android screen saying 'turn on usb storage'. On clicking, the SD card appears as a second (not CD) drive. The button remains on screen saying 'turn off usb storage' which of course reverses the process and removes the SD card drive from the PC but leaves the CD drive of some 8Mb and shows adb.exe among others.

This may be useful for anyone unable to find their SD card on the PC
 

latcc

Banned
Introduction

adb and USB
For my phone to be recognised the following details needed to be inserted in each of the two sections mentioned.

;Orange San Francisco
%SingleAdbInterface% = USB_Install, USB\VID_19D2&PID_1354&MI_00
%CompositeAdbInterface% = USB_Install, USB\VID_19D2&PID_1354&MI_02
Hi Andrew

I also have a SanFran phone and I have been trying to follow the link you gave to get the USB drivers. I have downloaded this...

ZTE Android USB Driver for Microsoft PC_5.2066.1.8(Updated on Mar.31 2011)

Is this the correct driver for our phone? I only ask as there isn't an Orange San Francisco driver on the page you pointed to. But I know this phone is also called a ZTE Blade.

If not do you have a link to the usb driver for the SanFran?
 
Top