Posts

A binary with debug symbols with the Android NDK

First go into the Android.mk file in your jni folder and add this line: LOCAL_CFLAGS  += -g This is going to enable the debug compile option. You might have a separate option for logging more data. Next go into Application.mk and uncomment this line: APP_OPTIM := debug (or add it if it isnt there) This should be sufficient. Now when you run the ndk-build (You can run ndk-build V=1 to enable the verbose option), you should get the debuggable binaries. For some reason the binary I get in the libs/armeabi folder is not the debuggable one, this one has its debug options stripped out. To get the debug one grab it from obj/local/armeabi.

Sun JDK on Ubuntu

Thought it would be simple, but apparently not. These are the instructions I followed first and the installer seemed to get stuck at 99% for some reason: sudo add-apt-repository "deb http://archive.canonical.com/ lucid partner" sudo apt-get update sudo apt-get install sun-java6-jdk To get it to work, replaced the last 2 lines by: sudo apt-get install sun-java6-jre sun-java6-plugin sudo update-alternatives --config java

Comparing directrories using diff

diff -qr --exclude=".svn" --exclude=".git" --exclude="STATIC_LIBRARIES" dir1 dir2 q is for brief, which means output only if the files differ r is for recursive since we are comparing directories. we exclude certain directories using the exclude option

Dynamically allocating 2d arrays in C++

http://www.codeproject.com/KB/cpp/arrayDinamic.aspx

Debugging an android crash

Image
So lets say one of your android app crashes and you get something like this in your logcat: Here #00 tells us the address in the program counter. But this information is pretty useless. To translate into actual file and line numbers we can use a tool called addr2line. For NDK4 it is located at android-ndk-r4b/build/prebuilt/linux-x86/arm-eabi-4.4.0/bin. For NDK5 it is at a different location. So we go to this location and run the tool: addr2line -f -e mydroid/gingerbread_2.3.3_GINGERBREAD/modified/out/target/product/crespo/symbols/system/lib/libmedia.so 0004853a This gives us the file and line numbers we are looking for. We use the code in the symbols directory because that has the unstripped version of the libraries.

kernel logs android

If you want to extract kernel logs from the android shell and are getting 'Permission Denied' errors, you can use this approach: Go into the adb shell and run: cat /proc/last_kmsg >/sdcard/last_kmsg. Now come out of the shell and run: adb pull /sdcard/last_kmsg This will extract the logs to the folder containing the adb exe!

Grep

Let's say you want to search for the text 'amigo' within a directory. You can use: grep -r 'amigo' /home/guest/mydir. If you start getting errors like 'No such file or directory' and you want to ignore them, the option -s can be used. So it'll become grep -r  -s 'amigo' /home/guest/mydir. Here -r is for recursive search within a directory and -s for skipping error messages. And if we want to exclude searching certain type of files, like SVN and xml files, we can use: grep -r -s -n --exclude=*.{svn*,xml} 'PATTERN' . Another useful feature is if we want to exclude certain directories from the search altogether. For this we can use  --exclude-dir=Tests .