I have a Cordova app using Vue.js, and lots of logging using the standard Javascript/browser console.log(). Up until now I've only been targeting iOS, and those console.log messages appear in the xCode log viewer.
Now, however, I'm also targeting Android. I've successfully imported the Cordova project into Android Studio and the app is running in debug mode in the Emulator. But, I can't find the console.log output anywhere.
I think the log output should appear here, but there is nothing from my app at all.
I've also tried Logcat, as #Lukasz describes, which also had no effect:
You should try to use chrome inspect as described here:
https://developers.google.com/web/tools/chrome-devtools/remote-debugging/
If you really want to see the console.log statements from inside the Android Studio you can use logcat View -> Tool Windows -> Logcat. Remember to filter it by 'CONSOLE' statement like I did on the image below.
I finally resolved this. I had to enable Developer Options in settings and enable USB Debugging.
If you're not seeing console.log in LogCat, ensure your application is debuggable. This will be true for apps run from Android Studio (I think) but if you're debugging a 3rd party APK like I am, it won't. Maybe this will save someone the 3 hours I wasted on it.
So ensure android:debuggable="true" is there in the application tag of of your AndroidManifest.xml file
Related
I am using Android Studio and wanted to see if I could get "prints" or logs from my app, which would help later in debugging of more involved apps.
My minSDK API is 9 and targetSDK API is 22.
So, I take the simplest HelloAndroid app, and add a Log.i with an appropriate tag in the oncreate method.
I install and run this app on my Samsung phone, which has the developer options set to enable USB debugging.
The app runs fine, and I can see the system logs.w or logs.i from the various managers, but I can't find the print message I had inserted.
I had already added debuggable = true in both manifest and gradle build script as well.
So, why can't I see my own log messages.
Thanks,
Har Yash
In my case, I needed to reinstall the application on my device to see at least the logs. It seems that android studio was not running the actual version of my code...
Maybe these links could help to solve the problem in that case:
how-to-reinstall-apk
how-to-resintall-app
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.
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)
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
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.