Help a newbie learn Eclipse/Android debugging best practices - android

I am a newbie to Android and the Eclipse development environment and would like some advice on best practices for debugging my apps when they throw a Force Close.
I have researched ADB, however, I can not get this to interact with my phone even though I have explicitly turned debug mode to true on my test handset.
Obviously Android comes with a LOG method which I have seen utilized in many example apps, can someone please explain how to review these logs quickly and how to setup logging appropriately to determine the cause of a Force Close (always occurs when I push the Home button).
Any advice on debugging effectively in Eclipse would be much appreciated!
Sincerely,
Ryan

To debug using your device, you will need to have debug mode turned on (which it sounds like you do), you will then need to have the phone plugged in with the USB connector. From here, you can tell Eclipse to run/debug.
Eclipse should ask which device to use (this is done because there should be multiple devices available for running/debugging since your device is plugged in). At this point, you can select your actual device from the list, and you should be up and running.
If you are using android.util.Log, then your logs will show up in LogCat. If you do not see LogCat by default in your Eclipse environment, you can add it by doing the following:
Go to Window -> Show View -> Other
Select Android -> LogCat
Cick OK.
When running/debugging your device, you should see your Log statments in LogCat.

As I have never been able to get Eclipse to refresh the LogCat when I'm debugging on device, I will add this :
You can also debug from command line like this :
"adb -d logcat"
However, as the windows command line is awfully basic, the line are cut in 2 most of the time.
And my asking about your OS does help because the procedure is not the same to set up device debugging if you are on windows or linux or mac.
For instance, in the case of windows, you need to install a driver (you can find all the doc here) before being able to debug on a device.

Related

How to debug remotely

I have a situation:
1. Samsung 7 has a strange bug in my app.
2. This device is 10000 miles away from me.
What are the opportunities for debugging this device remotely.
When tester on the other side can do everything.
I tried adb tcpip <port>
but device ip can be only local(192.168.....)
The rude way is to get Android Studio there and install team viewer on the phone. It's not working every time.
And when we have 1 hour intersection it's difficult to support.
Is there any other way?
Have your user enable Developer Options on the device. You should already know how to do that.
See whether the device has Take Bug Report and/or Bug Report Shortcut settings. If you enabled Bug Report Shortcut a Take Bug Report option will appear when pressing/holding the power button.
Instruct your user to take a bug report -- either through Developer Options, or from the power menu -- as soon as your app crashes.
As for the APK you send to your user, make sure debugging is enabled, so you get all your log messages. If you obfuscate the APK, be sure you keep your mapping files handy.
If you have some idea of where the bug is happening, an option could be to set up something like http://www.acra.ch/ and send your tester a new apk.
This way when the bug is provoked, given you set up useful log events, you will receive information about the crash or bug. ACRA lets you include the LogCat as well, which is pretty useful.
There are several options:
-Build APK and send it to the phone. Install and check/try again.
-Create Android Virtual Device identical to the model located remotely, install Samsung Android firmware.
There is no clear solution about debugging out of local network.
You could try something like LogmeIn for Android - this way both devices will be in the same network.
Once done, just do usual adb connect ipadress If t refuses to do so first, try enabling ADB over WiFi option

Is it possible to see output from log cat without having the app source code?

I have an app installed on my device.
An app that I developed, but I haven't got the source code anymore.
Is it possible to attach log cat to this app?
yes you can, just enable usb debugging on your android device, and plug the device where you have the application installed on it, by that, you will see all the logs on logcat.
Depends if you've left logs in the code. If you did, the easiest method would be probably going into your Android Studio and checking you Android Monitor tab. You can switch devices / applications there.
If you don't have any logs and your question actually means you want to add some logs in, then I'm afraid you can't reliably do that.

Android: How to find out reason for "Unfortunately [...] has stopped"?

when I run my Android application with an emulator, it works perfectly, and so it does on my phone, but on another phone, trying to run the app, I always get the "Unfortunately [...] has stopped" error. How can I find out the reason for this error (Using the emulator, I could look it up in LogCat, but not on a real phone)??
Thanks in advance!
On a real phone, you can use the tool aLogCat to view logs on the device itself. You can also connect it to your computer via USB and use the adb logcat tool, and the logs will be visible from the computer's shell window.
Adb logcat could also be used over a wireless network with a tool like WiFi ADB, should you prefer wireless methods.
Android Remote Stacktrace is a quite useful library/script that allows you to easily add a way for a phone to send its crash logs your way.
Simplest would in this case probably be to add it to a test version you put on the other phone. Since it's not being actively developed (afaik), you may not want to put it in a normal store release build.

Android Debugging with Eclipse - No Breakpoints

I am trying to debug a simple Android application on either the emultor or a device and I cannot get the debugger to stop on any breakpoints I have set. I have combined the other posts here and throughout the web and tried all the suggestions (Add debuggable:"true" to the manifest, stop and start adb, Clean all, make sure I use the debug button not the run button, etc etc). In the Debug perspective I can see the threads and in DDMS it shows the debug icon next to the device I am debugging on. I do see the blue dots where I set the breakpoint and the Debug perspective lists them and says they are active.
I have put in alerts just before the breakpoints to verify the code is getting executed.
Starting to go crazy here. Any other suggestions? I must be missing something simple but non-obvious.
UPDATE: I appreciate the responses so far. Unfortunately they have not solved my problem. I have followed the instruction on debugging and have debugging turned on in the phone. Also, I do see the "Waiting for debugger" alert on the phone when starting. In general everything says I am debugging (including getting logcat output that I have added). It just will not stop on breakpoints that I have added and are listed in the breakpoints tab in the Debug perspective. Also just to reiterate - this happens when debugging on the device as well as on the emulator. One thing I do notice is that when I launch the debugger I have it set to bring up the Android Device Chooser. In there the "debug" column is blank for my device - but if the emulator is running the debug column does say 'Yes'. Also the console states that is attempting to connect to the debugger. Should there be a console log that states that the debugger successfully connected? I do not see this.
UPDATE 20120914: I have been away from this for some time and had given up previously. Back to try and tackle this. It is still not resolved. Everything above is still current - but one other thing I have noticed. I set a Class Load Breakpoint on the main activity and it does stop there. It just does not stop at any Line Breakpoints. I have just updated to the latest JDK 1.7.0_07, Android SDK 20, ADT Plugin 20.0.3. I have used the logcat to output a message and set a breakpoint on this line. I see the message in logcat so I know the code is being executed. The debug window in the debig perspective also does show the android application with a number of threads beneath it and the Devices window in the DDMS perspective shows the application with the green bug icon next to it.
One more thing - when the debugger is running the line breakpoints bullets do not get a checkmark overlaid on them (the Class Load Breakpoint does!). I am guessing this is the root cause - but I don't know why they are not getting this. (By the way skip breakoints is also not set - breakpoints do not have lines through them).
Any new suggestions would be appreciated. I have burned a lot of time on this. It must be something obvious that I am not seeing.
Now I feel a bit stupid writing this post. But I resolved my issue finally. The problem is you cannot set breakpoints in the Javascript code. The part I left out unintentionally is I am writing an app for Android using PhoneGap. Almost all the code is Javascript. I am so used to developing .NET web apps in Visual Studio I just assumed you could set breakpoints in the javascript code. Breakpoints in the Java code happen to work fine. Anyway, Thanks for any suggestions. Do';t know if there are other .NET developers trying PhoneGap development - but maybe this post will help them.
Android SDK provides most of the tools that you need to debug your applications. This link will introduce you to Android debugging environment and the debugging tools used.
Here's also a hands on tutorial on debugging an android application.
If you want to debug using actual android phone, turn on "USB Debugging" in your device:
Settings > Applications > Development and enable USB debugging
Android 4.0:
Settings > Developer options
AND make use of Log.d and your Logcat.
Eclipse has a debug run configuration. Only if you use the debug run configuration will a debugger be attached with the application during launch.
Does the application launch (on the device/emulator) pause a while "Waiting for Debugger" ? If not, then you are not launching the application using "debug configuration". Its the button to the immediate left of run (drop down) configuration.
Try jsHybugger: http://www.jshybugger.org/ for setting javascript breakpoints in Eclipse for remote(mobile) devices.
It lets you set breakpoints, singlestep, catch exceptions, and interact with the JS/DOM environment. You can use it from Eclipse or from a Chrome or Chrome-compatible debugger on the remote desktop. It can be used with apps that create their own webView.
However, you have to install a few files -- but probably no more complicated to use than weinre. it does extensively modify the JS files (on the fly, transparently to the user) to enable all this debugging -- webKit really should support javascript debugging natively.
Make sure you did not check skip all breakpoints (Run -> Skip all breakpoints).
Ribo already mentions it in his answer, but since this question and answers are about debugging Phonegap applications.
You certainly have to look at weinre (WEb INspector REmote).
http://people.apache.org/~pmuellr/weinre/docs/latest/
Nowadays phonegap even has it's own weinre embraced in phonegap build...
http://debug.phonegap.com/
I Am a big fan of this... (note if you are using weinre on your local machine and trying to debug a phonegap app via wifi... make sure your local device is on the same wifi network!)

"Unable to open log device '/dev/log/main': No such file or directory"

I am new to Android development and bought a cheap Huawei Sonic (U8650 apparently) so I could test my first attempts at making an app on an actual device.
However, whenever I try to use 'adb logcat' or 'adb shell' then 'logcat' on the device I get:
Unable to open log device '/dev/log/main': No such file or directory
I have already enabled Usb debugging in Settings -> Developer.
I just don't know enough about Android to know if this is something I can even fix.
I have found two other questions with similar problems:
/dev/log/main not found
??-?? ??:??:??.???: INFO/<unknown>(<unknown>): Unable to open log device '/dev/log/main': No such file or directory
...but they both turned out to be using some kind of non standard kernel that had logging disabled. Mine is a stock phone out of the box.
It's a very cheap but snappy Android 2.3 phone, so hopefully it wasn't a total waste of money.
Any help would be greatly appreciated.
Dial this: *#*#2846579#*#*
Service menu will appear.
Go to "ProjectMenu" -> "Background Setting" -> "Log Setting"
Open "Log switch" and set it to ON.
Open "Log level setting" and set the log level you wish.
Reboot the phone.
Open: /system/etc/init.d/××× (not the same file on different ROMs, find the right file)
Find the line that says: rm /dev/log/main
Change the line to: # rm /dev/log/main (comments out the line, rm = remove, in case you were wondering)
Save and reboot
I'm sharing my case and solution:
My cellphone had a jellybean version oriented to performance (To be exact a Slim Bean ROM) with a Semaphore kernel (You can recognize it because when the cellphone is starting, the semaphore logo is shown). These kind of ROM have by default disabled the logging so I had to download the Semaphore Manager application (You can download it from here). After that, in the section "Modules" I had to turn on the Logger option as it is shown in the picture
Restart and the logcat should be working now!
I have actually found an answer for this finally!
I was having another aimless look to see if anything had been updated about this anywhere and came across a post on xda-developers about a slightly different Huawei device with the same problem.
http://forum.xda-developers.com/showpost.php?p=17774398&postcount=93
It actually worked. I have complete logcat logging on my Huawei Sonic (U8650) now.
Three cheers for not giving up.
Solution, copied from the xda (in case it is removed etc):
There is a hidden service-menu where you can set loggin up. The
service-menu is started by "dialing" this phone number:
*#*#2846579#*#*
I have a custom rom on my Samsung Captivate, but my approach may work for others as well:
Open up CMD or Terminal and type:
adb shell
logcat-enable
reboot
The rom I have is Continuum v6.1, but this still may work for others.
If you have the terminal emulator on the phone, you also may be able to do:
logcat-enable
and then just reboot the phone. I didn't try that, but it probably would work too. My phone is also rooted - don't know if that makes a difference.
it was enough to restart the Huawei device
adb shell
reboot
I'm having exactly the same problem.
Someone from xda-developers wrote something as follows in msg #33
http://forum.xda-developers.com/showthread.php?t=1169869&page=4
One of the reason it can't be rooted is this phone had removed the
"Logcat" mechanism from android. So, this makes most of rooting ways
malfunction.
Maybe right maybe wrong i don't know.Anyway it gives some idea about the case.

Categories

Resources