How can I debug my Android application in a mobile, not in the emulator?
My OS is Linux. When I try to connect with my mobile device for debugging, it is not
responding.
This question is answered in the documentation for debugging against a mobile
device: Using Hardware Devices.
Directly quoted from their documentation:
Declare your application as "debuggable" in your Android Manifest.
In Eclipse, you can do this from the Application tab when viewing the Manifest (on the right side, set Debuggable to true). Otherwise, in the AndroidManifest.xml file, add android:debuggable="true" to the <application> element.
Set up your device to allow installation of non-Market applications.
On the device, go to Settings > Applications and enable Unknown sources (on an Android 4.0 device, the setting is located in Settings > Security).
Turn on "USB Debugging" on your device.
On the device, go to Settings > Applications > Development and enable USB debugging (on an Android 4.0 device, the setting is located in Settings > Developer options).
Set up your system to detect your device.
<snip - Not using Windows or Mac OS X>
If you're developing on Ubuntu Linux, you need to add a udev rules file that contains a USB configuration for each type of device you want to use for development. In the rules file, each device manufacturer is identified by a unique vendor ID, as specified by the ATTR{idVendor} property. For a list of vendor IDs, see USB Vendor IDs, below. To set up device detection on Ubuntu Linux:
Log in as root and create this file: /etc/udev/rules.d/51-android.rules.
Use this format to add each vendor to the file:
SUBSYSTEM=="usb", ATTR{idVendor}=="0bb4", MODE="0666", GROUP="plugdev"
In this example, the vendor ID is for HTC. The MODE assignment specifies read/write permissions, and GROUP defines which Unix group owns the device node.
Note: The rule syntax may vary slightly depending on your environment. Consult the udev documentation for your system as needed. For an overview of rule syntax, see this guide to writing udev rules.
Now execute:
chmod a+r /etc/udev/rules.d/51-android.rules
You can verify that your device is connected by executing adb devices from your SDK platform-tools/ directory. If connected, you'll see the device name listed as a "device."
If using Eclipse, run or debug your application as usual. You will be presented with a Device Chooser dialog that lists the available emulator(s) and connected device(s). Select the device upon which you want to install and run the application.
If using the Android Debug Bridge (ADB), you can issue commands with the -d flag to target your connected device.
Setting up a Device for Development
Set up your device to allow installation of non-Market applications.
On the device, go to Settings > Applications and enable Unknown sources (on an Android 4.0 device, the setting is located in Settings > Security).
Turn on "USB Debugging".
On the device, go to Settings > Applications > Development and enable USB debugging (on an Android 4.0 device, the setting is located in Settings > Developer options).
Set up your system to detect your device.
If you're developing on Ubuntu Linux, you need to add a udev rules file that contains a USB configuration for each type of device you want to use for development. In the rules file, each device manufacturer is identified by a unique vendor ID, as specified by the ATTR{idVendor} property. For a list of vendor IDs, see USB Vendor IDs, below. To set up device detection on Ubuntu Linux:
Log in as root and create the file /etc/udev/rules.d/51-android.rules.
Use this format to add each vendor to the file:
SUBSYSTEM=="usb", ATTR{idVendor}=="0bb4", MODE="0666", GROUP="plugdev"
In this example, the vendor ID is for HTC. The MODE assignment specifies read/write permissions, and GROUP defines which Unix group owns the device node.
Note: The rule syntax may vary slightly depending on your environment. Consult the udev documentation for your system as needed. For an overview of rule syntax, see this guide to writing udev rules.
Now execute:
chmod a+r /etc/udev/rules.d/51-android.rules
On Android 4.2 and newer, Developer options is hidden by default. To make it available, go to Settings > About phone and tap Build number seven times. Return to the previous screen to find Developer options.
Related
UPDATE: Based on this Here is following question: Create specific device tree for AOSP
I followed this: https://source.android.com/source/building.html and set up the environment and downloaded the latest AOSP. Now I wnat to flash it on my specific device, let's say Galaxy S2.
In the "Configuring USB Access: 51-android.rules", how it should look? Because in above official tutorial each entry looks like:
//adb protocol for device X
SUBSYSTEM=="usb", ATTR{idVendor}=="18d1", ATTR{idProduct}=="4e12", MODE="0600", OWNER="user"
//fastboot protocol for device X
SUBSYSTEM=="usb", ATTR{idVendor}=="0bb4", ATTR{idProduct}=="0fff", MODE="0600", OWNER="user"
But in many places I found this:
SUBSYSTEM=="usb", ATTR{idVendor}=="0502", MODE="0666", GROUP="plugdev"
Of course adding user to plugdev group is obvious, but still: In Google`s way there is separate entries for adb & fastboot, and the mode is different...
What would be the ultimate test to see if this step works?
Suppose I modify the correct lines of code & config files for my specific device like stated here: Android device configuration for AOSP. Which means I have a directory with full AOSP files. In the stage of $ lunch aosp_arm-eng what parameters should be for specific hardware device?
Now suppose I have in my output directory built & compiled AOSP files. How should I flash it on my device? It's not very clear from Google`s above tutorial. I prefer to get just a single zip file in order to flash it via CWM recovery etc.
Is there a way to test the result before flashing it on hardware device (To reduce the chances for brick...)?
Thanks,
The adb rules are to enable adb to work over USB. If you can connect to your device over ADB then the adb rules worked. You may have to enable ADB in the device's Developer Settings.
After you have synced AOSP you can build for your device. You can choose your device in the lunch menu. Run the build/setenv.sh script. Then run lunch. It will have a list of specific devices you can choose from. You can add to that list by syncing new device trees into the tree.
By default it will build system.imgs that you flash through fastboot. If you are building AOSP, make otapackage will make a flashable zip.
The build will make an emulator image that you can test by running emulator. That will give you a general idea of if your build works, but will not give you the full story with regards to your specific device. For instance, the emulator build might run but if you forgot to add the correct proprietary files the build might not boot on your specific device. But you are very unlikely to hard brick your device by flashing a system.img.
I have a Haier phone model W716 and I'm using ubuntu to develop my android applications. The issue I have is that I Google USD Driver is not compatible with linux and thus eclipse doesn't detect my device.
How do I proceed to make my device appear?
Enable USB debugging on your device.
Since development is on Ubuntu Linux, you need to add a udev rules file that contains a USB configuration for each type of device you want to use for development. In the rules file, each device manufacturer is identified by a unique vendor ID, as specified by the ATTR{idVendor} property.
For a list of vendor IDs, see USB Vendor IDs, http://developer.android.com/tools/device.html#VendorIds
Now if you really ain't on the VIP list you'll have to write the udev rules yourself in order to access devices connected to USB via adb or fastboot on linux.
Verify your username is included in the plugdev group. Type
groups
From a terminal and look for plugdev in the listed groups. If you do not see plugdev listed, you can add your username to the group with:
sudo gpasswd -a username plugdev
where username should be replaced with your linux username.
After setting the device in USB Debug mode and connecting it to a USB port, throw the command :
lsusb
You should get an output similar to this
...Bus 002 Device 034: ID 0bb4:0c03 High Tech Computer Corp.
The number after ID and preceding the colon is the ATTR{idVendor}
Copy the set of rules listed here, https://gist.github.com/theeyl/a353632e7fdb41ea9e26, to a text file and save it as /etc/udev/rules.d/51-android.rules.You will need sudo/su to write to that directory. So, for instance:
sudo nano /etc/udev/rules.d/51-android.rules
Use this format to add new vendor to the file:
SUBSYSTEM=="usb", ATTR{idVendor}=="0bb4", MODE="0666", GROUP="plugdev"
If you cannot access your device via adb, even after adding your linux user to the plugdev group and restarting the computer, you can try starting the adb service as root. This is dangerous and not recommended but it worked for me:
adb kill-server
sudo $(which adb) start-server
adb devices
Follow same as at this link, its ok for me...
http://www.techotopia.com/index.php/Testing_Android_Applications_on_a_Physical_Android_Device_with_ADB#Linux_adb_Configuration
I got this following devices :
I got my Ubuntu 64 bits PC
I got my Wildfire (not S, but normal Wildfire)
In my phone,
I have turned on:
USB debugging mode
Also in the charging mode
However, ECLIPSE didn't find my device in their DEVICE section. So, I am wondering for the ideas ! :)
Thank you !
Have you done this setting? (Step 4 mentioned at Using Hardware Devices)
If you're developing on Ubuntu Linux, you need to add a udev rules file that contains a USB configuration for each type of device you want to use for development. In the rules file, each device manufacturer is identified by a unique vendor ID, as specified by the ATTR{idVendor} property. For a list of vendor IDs, see USB Vendor IDs, below.
To set up device detection on Ubuntu Linux:
Log in as root and create this file: /etc/udev/rules.d/51-android.rules.
Use this format to add each vendor to the file:
SUBSYSTEM=="usb", ATTR{idVendor}=="0bb4", MODE="0666", GROUP="plugdev"
In this example, the vendor ID is for HTC. The MODE assignment specifies read/write permissions, and GROUP defines which Unix group owns the device node.
Note: The rule syntax may vary slightly depending on your environment. Consult the udev documentation for your system as needed. For an overview of rule syntax, see this guide to writing udev rules.
Now execute:
chmod a+r /etc/udev/rules.d/51-android.rules
Is there a way of disabling a USB port on an Android enabled device using the Android SDK or NDK?
This applies to a USB accessories port (i.e. not for ADB)...
If you have a rooted device, you can try this as it worked for me...find the file indicating devices authorized for your port and clear it as follows
(Note the path will be specific to your system so it may take a bit of searching - I have a platform based on Freescale HW & BSP) You can try this from a shell session but ultimately it can be done from a script or shell commands executed from within an application
$su
#cd /sys/devices/platform/fsl-ehci.0/usb1/
#echo 0 > authorized
If you need to re-enable, just do
#cd /sys/devices/platform/fsl-ehci.0/usb1/
#echo 1 > authorized
Settings changed in this way worked for me to enable & disable both a USB keyboard and a mass storage device (thumb drive). NOTE: What you set this way may not persist through a reboot or power cycle (it did not in my case) so plan accordingly.
I'm trying to figure out how to debug applications directly on my phone (HTC Desire).
I've installed the USB driver that came with the phone and the phone is listed when using "adb devices".
How do I configure eclipse/ADT to launch on the phone instead of launching the emulator/virtual device?
Note: This answer is a heavily modified version of this guide that used to exist at developer.android.com. Portions of it are quoted verbatim from the original text without attribution for the specific parts that are quoted.
With an Android-powered device, you can develop and debug your Android applications just as you would on the emulator.
1. Declare your application as "debuggable" in AndroidManifest.xml.
<application
android:debuggable="true"
... >
...
</application>
2. On your handset, navigate to Settings > Security and check Unknown sources
3. Go to Settings > Developer Options and check USB debugging
Note that if Developer Options is invisible you will need to navigate to Settings > About Phone and tap on Build number several times until you are notified that it has been unlocked.
4. Set up your system to detect your device.
Follow the instructions below for your OS:
Windows Users
Install the Google USB Driver from the ADT SDK Manager
(Support for: ADP1, ADP2, Verizon Droid, Nexus One, Nexus S).
For devices not listed above, install an OEM driver for your device
Mac OS X
Your device should automatically work; Go to the next step
Ubuntu Linux
Add a udev rules file that contains a USB configuration for each type of device you want to use for development. In the rules file, each device manufacturer is identified by a unique vendor ID, as specified by the ATTR{idVendor} property. For a list of vendor IDs, click here. To set up device detection on Ubuntu Linux:
Log in as root and create this file: /etc/udev/rules.d/51-android.rules.
Use this format to add each vendor to the file:
SUBSYSTEM=="usb", ATTR{idVendor}=="0bb4", MODE="0666", GROUP="plugdev"
In this example, the vendor ID is for HTC. The MODE assignment specifies read/write permissions, and GROUP defines which Unix group owns the device node.
Now execute: chmod a+r /etc/udev/rules.d/51-android.rules
Note: The rule syntax may vary slightly depending on your environment. Consult the udev documentation for your system as needed. For an overview of rule syntax, see this guide to writing udev rules.
5. Run the project with your connected device.
With Eclipse/ADT: run or debug your application as usual. You will be presented with a Device Chooser dialog that lists the available emulator(s) and connected device(s).
With ADB: issue commands with the -d flag to target your connected device.
Sometimes you need to reset ADB.
To do that, in Eclipse, go:
Window>>
Show View >>
Android
(Might be found in the "Other" option)>>Devices
in the device Tab, click the down arrow, and choose reset adb.
in devices which has Android 4.3 and above you should follow these steps:
How to enable Developer Options:
Launch Settings menu.
Find the open the ‘About Device’ menu.
Scroll down to ‘Build Number’.
Next, tap on the ‘build number’ section seven times.
After the seventh tap you will be told that you are now a developer.
Go back to Settings menu and the Developer Options menu will now be displayed.
In order to enable the USB Debugging you will simply need to open Developer Options, scroll down and tick the box that says ‘USB Debugging’. That’s it.