How to debug a cordova plugin for Android - 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.

Related

How to debug the android app in emulator/device on react native 0.62.0?

I have updated my react native app to version 0.62.0 from 0.59.0 some time ago. I am able to debug the app on ios simulator and device but not able to get the in app developer menu on android by pressing the command+m key for emulator and device (on shaking the device). While updating I skipped the code for Flipper which is a new debugging tool that comes by default with RN 0.62.0.
I am also not able to see the change in app when I run the app from Android Studio.
Is it not possible to use the shake gesture feature or debug the app without Flipper on Android ?
You can use this command from terminal, I set it up to a hotkey so I can do it quickly cause its annoying to have to shake your device anyway..
First time you need to do this to get device list and it will return a list of devices, choose the number for your device, something like "2663404d12057ece"
adb devices
To open developer menu on device use command:
adb -s YOUR_DEVICE_NUMBER shell input keyevent 82
I found the solution, MainApplication.java file contained this import statement import com.facebook.react.BuildConfig; which is not needed. The BuildConfig.java should be pulled from android/app/build/generated/source/buildConfig/debug/[your]/[package]/[name]/BuildConfig.java instead, which is imported automatically when the project is build/synced in Android Studio.
After I remove the import statement I was able to see the developer menu and reload the app.

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 can I see my debug logs on Unity Android?

I'm still new to Android development and I'm currently having difficulties trying to figure out how to debug my Unity game when I deploy it to my Android device. I need to see what is happening while the user is playing my game to make sure my code logic is flowing as expected.
I'm coming from an iOS background and in iOS, I simply have to build my Unity project and open and run it in Xcode. Xcode automatically shows a debug window where I can see my Debug.Log messages I have set in my C# scripts in Unity.
How do I do debug on the Android platform? I have tried following liortal's answer here but I can't seem to get it to work even with the following settings suggested.
I'm using Unity5 and I already have Developer options and USB debugging enabled on my Android device by the way.
Any help is greatly appreciated.
Thanks.
Use logcat. You'll find it at sdk\tools or sdk\platform-tools.
Then you can use it like this:
adb logcat # (start logging)
adb logcat -c # (clears the log)
adb logcat > dump.txt # (dump log info)

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.

"DeviceMonitor]Sending jdwp tracking request failed!" in Eclipse / Android

I'm a noob learning Eclipse and Android. Whenever I close the emulator I get "DeviceMonitor]Sending jdwp tracking request failed!" in the Console tab. Infact that seems to be the ONLY thing I get in the console tab - I don't get all the emulator loading messages and other things I used to see.
Everything else seems to work, I can build, run in the emulator, debug in the emulator (via Run>Debug after setting a Debug configuration . . . I can't get "Debug As" to work, see: "Debug As..." in Eclipse for Android - don't know if that's relevant to this problem).
What does this message mean, and how do I correct it? Thanks in advance!
The message you receive is in the normal console of Eclipse and isn't really important, because it just reports you that the connection to the emulator was lost. That ok as you described you closed it.
The normal android log is only visible via the adb tool (via console) or with the view in Eclipse called LogCat. You can add that to your working screen if you go to Window -> View -> Other -> Android -> LogCat
I recommend to look at the other views of the android tools, too. Like Device or Explorer.
What might happen with the LogCat output is that it went blank. Than you need to clear the LogCat (there is a button for that on the top of the view) and if this doesn't help try to click on the emulator in the device list. If nothing of that helped: close eclipse and the emulator and start them again.
I fixed by changing the usb cable which was connected to PC and device.
Before that restarting dev machine, eclipse, even the device dint help.
Close eclipse, stop adb process. From command line, "adb kill-server".
Launch your eclipse project.
I don't know if this will help for sure, but I had a similar problem and I solved it by changing my workspace to a different folder where I placed copies of the projects and changed the names of the folders just one caracter so that It would not tell me they are already in use. Then I worked I just had to import the projects again and I refactored their names to match the code (just the project names).
This error is mostly result of incorrect permissions set for "ddms"/ "android" scrips residing in "your sdk location"/tools.
If you are getting only
Sending tracking request failed!
error then change the permissions assigned to tools/android.
To do that open the directory "your sdk location"/tools/ using file browser. You should see a file named android, right click-> properties -> permissions tab -> select allow executing and program. [chmod].
If your error is
Sending jdwp tracking request failed!
then you need to apply same procedure described above for "your sdk location/tools/ddms"

Categories

Resources