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

Related

The game crashes after the build for android

I have a problem with the game crashing after the build. If I run the game in Unity, then everything works. And when I build it on android, when I start the first training scenes work fine, but when I reach the main stage, the game crashes. There is a error in Unity:
Google.JarResolver.ResolutionException: Cannot find candidate artifact for com.google.android.gms:play-services-games:8.4+
Maybe that's the problem. If that's not the problem, how do you know what it is?
So this looks like plugin resolve problem. But more information wouldnt be bad and you should learn how to see your device logs on Android. Here is how:
You should check the logs of your mobile device in the moment of the crash. You can do it by using "adb logcat".
First you should download SDK Platform Tools.
Then, enable USB debugging on your phone.
Connect your phone to your PC and give the permission it needs. It will ask you when you first connect it.
Open command line on your computer, go to your SDK Platform Tools folder, copy the directory and paste it after writing "cd " to your command line
Now you can use adb to figure out your Android crashes. To filter the ADB you can use
adb logcat -s Unity ActivityManager PackageManager dalvikvm DEBUG
This way you will only see Unity related logs from your device.

Display Cordova "console.log" entries in Android Studio

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

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 debug native Android platform code?

I'm interested in learning about the Android runtime (ART) and I'd like to be able to put a debugger on it so I can step through the code. I have an AOSP build that I've been running on an emulator.
What's the best way to attach and run source? Should I just use gdbserver on the emulator? Are there any IDEs that people use for native debugging?
Looks like you figured this out, but just for completeness, here's a link to some official documentation which basically covers what you said: http://source.android.com/devices/tech/debug/index.html
If you want to debug native code, you're going to need the source, which of course means getting the AOSP. After you've setup the AOSP, do the following:
In your AOSP directory, run "choosecombo". Select "debug" and pick an "eng" build of your choice.
Build the AOSP
Start the emulator (ie: on Linux, "emulator &")
adb shell into the emulator and run "setprop debug.db.uid 32767". This prevents debuggerd from attaching to a process that it thinks has halted and causing problems. See system/core/debuggerd/debuggerd.cpp in the AOSP for more info.
In the same shell that you built the AOSP, run "gdbclient [process name]". This will attach and load the debugging information for the process you are interested in. You can also attach to a pid, but you will end up having to load the symbol information yourself.
Enjoy debugging native Android platform code

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.

Categories

Resources