How to debug Android App in Exclipse? - android

Ok.
So while this isnt a programming question.
I wanted to know how do people debug apps?
How do you view log cat, and where these exceptions are thrown etc?
And do I need to run the app on the emulator to see all the stuff, or is there a way to view this after running the app on my phone(while not being connected to the computer)
Links to plugins and tips would be really helpful, as im gonna start work on my next game, and while the first one works fine, had a lot of problems while debugging.

Setup: download the Android Developer Tools (ADT) plugin for Eclipse from here http://developer.android.com/tools/index.html
To debug:
Connect your phone to PC via USB
Open Eclipse, set breakpoints
wherever you need
Run -> Debug to relaunch your app in debug mode
Use the Debug perspective, see:
http://developer.android.com/tools/debugging/debugging-projects.html

Related

Debugging whilst developing JavaFX mobile application with gluon mobile plugin

I am new to javaFx and gluon mobile. In android studio there is the option to debug code whilst it is running on the phone and I was wondering if there is a similar feature for working with intelij and the gluon mobile plugin ? Under the gradle tasks there is a Debug task, which when clicked prints "Listening for transport dt_socket at address: 5005" to the console and waits. Unfortunately there is not a lot of documentation/examples regarding this that I could find. Any help is appreciated.
The Debug task is for desktop only.
It is intended to debug easily on your machine before deploying to mobile, but obviously it will allow tracking down only common issues, and that won't guarantee that the app will work on Android. I.e. using Streams will run on desktop and it will fail on Android.
To debug the app running on Android, the best way is using adb from your Android SDK folder, in the platform-tools folder.
Connect your app to the USB and run it. On a terminal go to that folder and run:
adb logcat -v threadtime
and search through all the messages trying to find out those related to the FXActivity.
You can add print outs in your code so you can easily track them in the logs.
There are other tools like the Android monitor (under Android sdk/tools folder), that will let you add some filters so you can easily go through the app messages.
First make sure you have enabled the Debugging Mode on your phone.
Then in Eclipse e.g., you can create a Debug Configuration of type Remote Java Application which will be attached to the corresponding socket:
You can get the port from the devices view:
Now you have to start your app first, and then start the Debug Configuration

How to debug a cordova plugin for Android

Hi I have created a cordova plugin for Android. But it is not functioning properly.
I want to debug it an IDE.
How can I debug the cordova android plugin file when I launch the application in my mobile?
What are the different and easiest ways to do it?
Thanks in advance.
Expanding response of laughingpine, i use this method:
Debug javascript part with chrome + dev tools + genymotion. You can access it from "inspect devices" and you can debug javascript part.
The problem is for debug my own plugins. For this, i build project "cordova build" from console, and import into Android studio the content of platforms\android from project folders.
After repair some errors whit gradle, i can run and debug whit android studio + genymotion, to acces the .java files.
Build your Android app (via cordova build android) and install the app in your device. For instance, I installed Dropbox on computer and device and transferred the files between them with that free service.
Plug the device into the computer with your USB plug.
Set up the device to enable debugging. In device, Settings:
Allow USB Debugging
Select debug app
In console, type to following so we can read all the messages in full:
adb logcat -v long
If you want to output all the messages to a text file on your Mac desktop (it’s different for a PC), type:
adb logcat > ~/Desktop/logcat.txt
Immediately the console should be outputting a lot of lines of text. If it stops at
-waiting for device -
and freezes, then check your screen to see if there is a popup to answer. If there is none, then unplug the USB from the device and try again. In my Settings > Developer Options, I chose “Select debug app,” then chose the app I installed; that might help too.
When the reporting stops, sometimes I hit Return a few times to mark the place with a large gap of space before doing the next step. This tells me how far to back up.
Tap on app icon in device to start it.
Read the output in logcat.
Tap Ctrl+C to stop logcat.
I think the best way to do this would be with logcat. Logcat is also built into Android Studio, so you can use that IDE to help you debug.
If you are running logcat from the command line, you can limit to a certain tag using the following: adb logcat -s "YOURTAG"
If you are running via Android Studio, see this documentation.. You are able to attach the debugger to a running process, so if you didn't do up your application in Android Studio, you can still attach the Android studio debugger to it. This is done by selecting Attach debugger to Android proccess. Again see the documentation for more.
Android Studio also can also filter based on tag name, log type, etc. This is done by expanding the filters menu, and adding a filter (filter by type, tagname, regex are accepted.)
Lastly, actually getting your plugin to spit out valuable information. First import the Log class: import android.util.Log; and setup a TAG private static final String TAG = "MYTAGNAME". Whenever you wish to write to the log (in this example, the debug level), call Log.d(TAG, "Your message to debug");
See the log documentation for more.
Personally I was right at home using logcat from the command line, but Android Studio does offer a slick interface for debugging your plugins.

Android Logcat is empty when debug with device in android studio

When I try to debug using android device in android studio Logcat shows nothing. But when I use emulator LogCat shows all the messages. How should view the Logcat messages when debugging on actual device?
Thank You !
In Android studio 0.8.0 you should enable ADB integration through Tools -> Android, before run your app. Then the log cat will work correctly. Notice that if you make ADB integration disabled while your app is running and again make it enable, then the log cat dosen't show anything unless you rebuild your project.
Restart the phone. And it solves magically
I was using Lenovo A7000plus powered by Android 6.0 M and found out that my Android Studio was unable to record the debug process, but somehow other's phone debug report could be recorded. Plus, I tried use Memu emulator and it recorded normally.
Strangely, that device was recognized by Android Studio and ready to be debugged, but no recorded debug report at all from all application that ran on the device. Of course, USB debug was tuned on.
What I did before, I turned off Developer option on that phone in order to play my favourite mobile game (F/GO) which forbids USB Debugging is turned on in the device.
A few hours later, after trying any method in Internet and not success, accidentally I found simple but strange solution that is Restart the phone. I restarted the phone while it was connecting to PC, and somehow the logcat showed all debug process in Logcat like normal.
It sounds like non-engineering solution at all, but that's really work for my case.
As of 0.4.0 I have noticed that the logcat tab does not work in the debugger window - only in the Android DDMS window (hit Alt+6 to bring up the working logcat while debugging). Awkward I know :)
In Android studio 1.0.2 or later: you should enable ADB integration through Tools -> Android, before run your app
In Android studio 1.* if logcat messages have disappeared for me helps the next trick:
Tools -> Android -> disable )) "enable ADB integration" (if it've been enabled)
Tools -> Android -> enable it again "enable ADB integration"
In 0.8.2 the DDMS window doesn't show up. However restarting the adb logcat windows by pressing Alt+6 (Twice, if it's already opened) fixes the issue. It worked for me.
I understand that this question is over 2 years old, but from my searches a few people are still having a persistent problem with this. One possible solution to this (which worked for me after two hours!) is that your phone settings may have its "Log Switch" set to off, hence it isn't sending your log data to the IDE.
Here is the solution - "Unable to open log device '/dev/log/main': No such file or directory"
Hope it helps!
If anyone's still having trouble with this despite trying all the answers here, just use System.out.println instead of log.* and your debug messages will output.
Updated: I finally got the cause of the problem in my case. If I switch of my device's wifi, the log shows. Otherwise, the log will not show. I tried several times and it the always show full logs when I turn off my wifi.
My device is: Gsmart Classic, OS: Android OS, v5.1 (Lollipop). I met the problem when I updated the gradle build tool from 'com.android.tools.build:gradle:2.0.0-alpha1' to 'com.android.tools.build:gradle:2.0.0-alpha3' in Android Studio 2.0-preview. After trying all the solutions with no luck, I tried un applied all the instant run choices and re-apply it again. Then the logs show up.
Note: if it still doesn't help. You can as well try to switch back-and-forth the back ground process limit. Unfortunately, I couldn't reproduce the error.
In Android Studio 2.x I used to have to restart to get it working but often switching back and forth between the applications works or running
adb kill-server;
adb start-server;
to restart adb fixes many things as well.
The problem seems to have different causes.
For me, the issue was that I had two emulators with the same name (I created it, deleted it, and then created it again with the same name). There were two emulator entries in the logcat dropdown and it was connected to the wrong one. All I had to do was switch to the other one. I prevented the problem permanently by renaming the emulator.
I believe that the problem has various causes for different users. I experienced the same issue with logcat not displaying any information when my application crashed, and we all know how frustrating this can be.
The following are the solutions that worked for me.
Invalidating caches and restarting android studio
In the developer option in your physical device make sure the logger Buffer size is set to 1MB per logger buffer.
Restart your physical device.
Hope this helps.

monodroid 4.6 breakpoint not hit

I'm using Mono for Android version 4.6.00049 with Visual Studio. I am debugging on a USB-attached Google Nexus 7.
I was able to break into the app being debugged. After installing the latest Mono for Android, debugging seems to have become unstable.
At first I wasn't able to debug my application at all: When starting the debugger, the application started on the device but Visual Studio did not enter into debug mode. After some seconds the app shut down on the device.
I followed an advice here on stack overflow to switch off "Use Fast Deployment" in the application project settings' "Mono Android Options" page.
Now Visual Studio enters debug mode and the app is not aborted on the device. Yet no single break point is being hit.
I read a couple of answers here on stack overflow all related to various settings on the "Mono Android Options" project property page. I realized that several settings lead to somme awkward "package tv.ouya.console.api does not exist" error when trying to rebuild the solution.
Please help.
Thx
Christoph

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 situation.
Any help would be appreciated.
Thanks,
Dan
On 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.
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.

Categories

Resources