Debug Android application on device without debugger
I am in a desperate situation.
I am developing an Android application using the ADT in Eclipse on Ubuntu 10.04 on a netbook.
Unfortunately the netbook is not powerful enough to run the Device Emulator (when I try there are always issues). Then, I tried to debug on-device, but unfortunately my phone (Pulse) seems to have some problem.
It seems I can't debug. I have already spent hours trying to get that working. And I can't afford to upgrade my netbook/mobile now.
The only thing I can do is developing on Eclipse and run the application on the phone.
Is there any way I can debug while the application is running on my phone? Can I create somewhere a log with errors/warnings and even some custom messages I put in the code?What a situat开发者_Go百科ion.
Any help would be appreciated.
Thanks,
DanOn device debugging should work. Make sure you have android:debuggable="true"
in your application manifest. I previously had debugging issues that fixed themselves after rebooting the device.
Alternately, you can use the Log class to print out log messages. These can be seen by running adb logcat
or in the logcat view of Eclipse.
Edit:
It seems that on some devices you have to run echo 1 > /sys/kernel/logger/log_main/enable
from adb shell
to enable logging.
With an Android-powered device, you can develop and debug your Android applications just as you would on the emulator. Before you can start, there are just a few things to do:
1 Declare your application as "debuggable" in your Android Manifest. android:debuggable="true" to the element
2 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).
3 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).
4 Set up your system to detect your device. If you're developing on Windows, you need to install a USB driver for adb. If you're using an Android Developer Phone (ADP), Nexus One, or Nexus S, see the Google Windows USB Driver. Otherwise, you can find a link to the appropriate OEM driver in the OEM USB Drivers document. If you're developing on Mac OS X, it just works. Skip this step. 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.
You can debug an android application directly through a tool named DDMS included in the SDK. With Eclipse the plugin intgrates everything for you: just create a breakpoint on the line you want to stop to by double-clicking in the margin, then hit the 'debug' button (the little bug at the top of the window). The program will start on the device and the device will display a message 'waiting for debugger to attach'. The message should disappear within a few seconds and will stop at the line you put the breakpoint on.
As for create logs, you can use the android.util.Log class:
import android.util.Log;
...
Log.e("MYAPPLICATION", "my message");
This should show in the "Logcat" view of eclipse.
I don't understand why you wouldn't be able to debug on the device. Just make sure your device is recognized by Ubuntu by following this article.
精彩评论