Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to debug Android native code on a real device

I've got some trouble with the media backend (mostly Stagefrightplayer) in Android, and I'd like to understand why it throws the errors it does. The errors are usually device spesific, so debugging on an emulator wouldn't be sufficient.

Example:

I/AwesomePlayer(  147): mConnectingDataSource->connect() returned -1004
V/MediaPlayerService(  147): [332] notify (0x272830, 100, 1, -1004)
E/MediaPlayer(24881): error (1, -1004)
E/MediaPlayer(24881): Error (1,-1004)
W/PlayerListener(24881): Received error: what = 1, extra = -1004

Example 2:

E/MediaPlayer(  941): error (1, -2147483648)

I've also gotten the player to bork completely and spit out a traces.txt.

Is there a way to debug what's happening, just like I debug Java code? Thanks.

like image 572
neu242 Avatar asked Sep 10 '10 12:09

neu242


People also ask

Can I run debug apk on device?

Android Studio 3.0 and higher allow you to profile and debug APKs without having to build them from an Android Studio project. However, you need to make sure you're using an APK with debugging enabled. To start debugging an APK, click Profile or debug APK from the Android Studio Welcome screen.

Can I use my physical Android device to debug my app without activate the Developer mode?

A device must enable Developer mode in order to deploy and test an Android app. Developer mode is enabled by following these steps: Go to the Settings screen. Select About phone.


3 Answers

Quite a few things you can do.

If you believe the error is in the framework itself, then get the source and dig http://source.android.com/

Otherwise, the best debugger for Android is DDMS, it can work with the emulator, but also with the real device. http://developer.android.com/guide/developing/tools/ddms.html

dumpstate through adb (http://developer.android.com/guide/developing/tools/adb.html) will also give you a full snapshot of what is happening on the device, but it will difficult for you to get the exact point when the error happens.

Although that will still not give you source level debugging as GDB would (or I am not sure what you mean by your usual way of debugging Java code).

If you really mean kernel as kernel, then you are not really in Android anymore but more in Linux world but I don't think you need to go that far.

If you have trouble with a specific Android application (that's out of the open source and is not your own), I am afraid you are out of luck.

For the MediaPlayer part, the file for Eclair is located in https://android.googlesource.com/platform/frameworks/base/+/eclair-release/media/java/android/media/MediaPlayer.java, but cannot find the specific error message you put there.

like image 110
Matthieu Avatar answered Sep 28 '22 12:09

Matthieu


Not that this directly answers your question, but this information might be useful to you.

So based upon your -1004 error code, you had an I/O Error trying to stream. As far as the -2147483648 error code, can't help you much. You would have to look at all of the log output from the media player to see why you are getting that code since it isn't defined. I've seen it from having the decoder choke on the video encoding.

Borrowed from: /frameworks/base/include/media/stagefright/MediaErrors.h

MEDIA_ERROR_BASE = -1000,

ERROR_ALREADY_CONNECTED = MEDIA_ERROR_BASE,
ERROR_NOT_CONNECTED     = MEDIA_ERROR_BASE - 1,
ERROR_UNKNOWN_HOST      = MEDIA_ERROR_BASE - 2,
ERROR_CANNOT_CONNECT    = MEDIA_ERROR_BASE - 3,
ERROR_IO                = MEDIA_ERROR_BASE - 4,
ERROR_CONNECTION_LOST   = MEDIA_ERROR_BASE - 5,
ERROR_MALFORMED         = MEDIA_ERROR_BASE - 7,
ERROR_OUT_OF_RANGE      = MEDIA_ERROR_BASE - 8,
ERROR_BUFFER_TOO_SMALL  = MEDIA_ERROR_BASE - 9,
ERROR_UNSUPPORTED       = MEDIA_ERROR_BASE - 10,
ERROR_END_OF_STREAM     = MEDIA_ERROR_BASE - 11,
like image 35
stewbv Avatar answered Sep 28 '22 11:09

stewbv


Remote debugging (gdbserver on target + gdb on host) can be used to step-through C/C++ userland code running on real hardware. It offers all 'usual' options like breakpoints, backtrace, view/set variables, tracepoints.

For details, look at 'gdbclient' shell function of Android build system, pre-build eabi gdb and maybe DDD or another frontend. Eclipse should be ok.

like image 22
vf_ Avatar answered Sep 28 '22 12:09

vf_