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:

schimanski

Well-Known Member
Licensed User
Longtime User
Hello!

I have a cheap Chinese Android tablet, which doesn't connect with the IDE over wifi. I doen't know the reason fort that until yet.
Is there a way to connect the tablet by wire? It doesn't have a mini or micro-USB port, only two USB 2.0 ports for external usb-equipment. I have tried it with a datalink-cable, but I only have the driver for the windows-desktop-PC.

What about the LAN-Port? Is there a way to connect the device with the IDE over a LAN-wire? I also asked this question, because I doen't have wifi on every places I can develope....

Thanks for an answer....
 

agraham

Expert
Licensed User
Longtime User
I have added a bit more on WiFi at the end of my original post.

If you have enabled Settings -> Applications -> Development -> USB debugging and Windows doesn't ask for a driver when you connect it to the PC by USB then your device, like many cheap tablets, does not implement the USB Android ADB interfaces. There is nothing you can do about this.

If by LAN-port you mean an wired Ethernet port then I don't know, but as WiFi looks like a normal network to applications then if it doesn't work over WiFi it probably wouldn't over a wired connection. However it does sound like a rather unusual device if it doesn't have a USB connection intended for connection to a PC, and a wired LAN connection also seems most unusual.
 

AllanC

New Member
Licensed User
Longtime User
ADB With Droid Fascinate

Read and tried all the great tips and instructions for this, but just can't seem to get it to work. When trying wifi and I run adb connect command it comes back says unable to connect
When I try usb it seems to looking for a driver.
Have USB debug on when trying both wifi and usb.
I assume ther is nothing to be set in basic4.
I can move apk's to sd card and then upload to phone.

Would anyone know if this is a droid and or fascinate issue?
Great post hoping it's something I'm doing wrong and droid phones don't lack this capability.
Tks for any help
 

agraham

Expert
Licensed User
Longtime User

AllanC

New Member
Licensed User
Longtime User
Successfully Connected Droid Fascinate To IDE

Got this to work for my environment - Win7 64 - Droid Fascinate
I basically followed the above link - Newbie guide for rooting Droid Fascinate ....
I know everybody's set up is always a little different but thought I'd share what I did in case it might help or at least provide some things to try for someone else.

Step 1. Only thing I did different here was provide the full path for the adb. I know there are different verisons of sdk out there but using ;c:\program files (x86)\android\android-sdk-windows\platform-tools\ did the trick for me.

Step 2. This where I spent a lot of time getting frustrated. I guess I don't understand what Softpedia is all about - seems a scam to get you to buy some software but again maybe I just didn't know how to navigate the site. Did some more googleing and finally found totally free driver download here:
Samsung Fascinate USB driver download | all samsung phones
Downloaded msi, ran it, connected phone via usb, started Basic4android, went to Designer - Tools - Connect and I was in business.
Thanks again for all the help.

:sign0060:
 

nfordbscndrd

Well-Known Member
Licensed User
Longtime User
My Archos 70, in the USB debugging mode, shows up on my computer, but I can't figure out how to compile to it. When I compile & run, it says "No device found" and wants to launch AVD Manager.

What am I missing?
 

nfordbscndrd

Well-Known Member
Licensed User
Longtime User
My Archos 70, in the USB debugging mode, shows up on my computer, but I can't figure out how to compile to it. When I compile & run, it says "No device found" and wants to launch AVD Manager.

What am I missing?

Turns out what I was missing was restarting A4b.

Now I've got new problems.

1. The A70 has 800x480 res on a 7" screen. I created an 800x480 layout variant with 240dpi (1.5) and an emulator with an 800x480 skin and 240 hw.lcd.density. When displayed on a 7" emulator, it fits fine, but on the actual A70, it takes up little more than a quarter of the screen.

2. I have a 15MB data file in the Files folder, but when the app is compiled onto the A70, it says that it can't find the file when it gets to the line:

File.Copy(File.DirAssets,"Words.db",File.DirDefaultExternal,"Words.db")
 

nfordbscndrd

Well-Known Member
Licensed User
Longtime User
1. Use Msgbox(GetDeviceLayoutValues, "") and make sure that the scale of your real device is indeed 1.5 (240).
2. Try to copy the file directly to the sd card. 15mb is pretty large for an apk file.

1. The Msgbox says that the device is 160 dpi, so I redid the layout.

2. I see lots of apk files larger than 15k. Appslib_2-1.apk is 512.4k.

The Archos 70-250G doesn't have SD, just the 250GB hard drive. Does it matter where on the hard drive that I copy the data file to? Also, is there some way to distribute a 15MB data file without it being part of the apk and without having to download it from my web site?

3. Here's what is probably a dumb question, but where do I get the apk to distribute? It doesn't create one that I can find when I compile.

Thanks for your help.
 

nfordbscndrd

Well-Known Member
Licensed User
Longtime User
2. Is it 15mb or 15kb? 15kb very small.
It doesn't matter where you copy it (assuming that there is no special access restrictions).
If you upload the apk to the market then you will need to host it somewhere online and download it when needed.
3. It is located under <project folder>\Objects.

2. oops -- I was mixing up my kb's and mb's. My data file is 15MB. It's so strange that I have 250GB of internal storage in the A70 and I can't install a 15MB apk.

3. Wow! I have installed my first app. Of course it's just a dozen lines of code done as a test and it took me about 20 or 30 hours, and I still have to figure out how to get it to download the data file from my web site, but there it is!
 

nfordbscndrd

Well-Known Member
Licensed User
Longtime User
3. Using Http with Response.GetAsynchronously it should be pretty simple to download the file.

Just to show that nothing can be too simple -- The "simple" tutorial seems to be about pulling data off a web site into memory as opposed to downloading a file into a device.

The "complicated" example seems to get a web page into memory, read image links from it, then download the image files, but all I need to do is download a single file, and I can't work out from the tutorial nor from the HelpViewer info on GetAsynchronously how to just download a file. It says:

GetAsynchronously (EventName As String, Output As java.io_OutputStream, CloseOutput As Boolean, TaskId As Int) As Boolean

This command does not pass the URL. I see where you are passing a URL in
request.InitializeGet(MainUrl)
HttpClient1.Execute(request, MainRequestId)​
but then I don't see where you are passing the information to select and download an image file.

I've studied this here and by Googling for a couple of hours. That's a lot of time for a "simple" piece of code. Here's what I've got. Can you tell me what to change to get it to work?

Sub Process_Globals
Dim URL As String
URL = "http://www.aeyec.com/aic.jpg"
Dim HttpClient1 As HttpClient
End Sub

Sub Activity_Create(FirstTime As Boolean)
Dim request As HttpRequest
Response.GetAsynchronously(URL, File.OpenOutput _
(File.DirInternalCache, "aic.jpg", False), True, TaskID
End Sub
 

James Moxham

Member
Licensed User
Longtime User
This thread is absolutely brilliant. I was originally downloading to the emulator, but I found the comments about downloading via WiFi, and it is about 5x faster, plus I don't need to keep removing the sd card all the time, nor install each time. And I don't need to wait for the USB cable to arrive.

So, thanks ++ from a very happy user. :sign0060:

BTW the hardware is a $110 Chinese Apad which, according to an advertisement on TV, is known in Australia as a "Panda Pad".

Just one minor thing - as per post #8 and #9 in this thread, the "adp.exe" file is indeed in the C:\Program Files\Android\android-sdk-windows\platform-tools folder, not the C:\Program Files\Android\android-sdk-windows\tools folder. Is there any chance post #1 could be edited to fix this?
 
Top