ndk-gdb cannot find gdb.setup but it is there under x86 - android

Cocos2d-x 3.7.1 + ndk r10e project on Mac trying to debug in Eclipse. Days pass and the errors keep coming...
I can build and run using cocos compile and cocos run with -p android -m debug --ndk-mode NDK_DEBUG=1 from the terminal in proj.android.
My app runs Ok (eventually) on my x86 emulator no problem.
Typing 'ndk-gdb' in the terminal from ./proj.android and I get the error
ERROR: Could not find gdb.setup under ./libs/
BUT the file gdb.setup (and gdbserver & libcocos2dcpp.so) can be seen in ./proj.android/libs/x86 !?
My AndroidManifest.xml includes android:debuggable="true"
My jni/Application.mk includes APP_ABI := x86 (only)
If anyone can tell me how I can diagnose or fix this problem then I guess I owe them a beer (in Yorkshire btw)
UPDATE: I have tried running up GDB using the --verbose flag. The output shows
Using gdb setup init: ./libs/armeabi/gdb.setup
Using app out directory: ./obj/local/armeabi
Guess I need to change to settings/init file somewhere??

I ran into the same problem. It seems something changed in recent version of Android Build tools.
The trick is:
ERROR: Could not find gdb.setup under ./libs/
It expects gdb.setup is in the directory libs but NOT libs/armeabi
so the simple workground is to copy gdb.setup and gdbserver from "libs/cpu" to "libs" and it works like a magic!

This is a bug caused by adb from android sdk.Issue 191085: ndk-gdb issue - Could not find gdb.setup under ./libs/ (even though it's there)
Currently previewl channel's adb whose version is 1.0.35 still has the same problem.
Without revert adb to 1.0.31.A simple workaround would be modify ndk-gdb a little: change the line if [ $? = 0 ]; then which is below adb_var_shell BCFILES run-as $PACKAGE_NAME /system/bin/sh -c "ls lib/*.bc" to if [ $? = 1 ]; then

Related

Openh264 compiling using PJSIP

I am trying to build pjsip project with openh264 lib. Everything works fine except openh264 is not being detected by pjsip ./configure-android
this is my config_site.h
/* Activate Android specific settings in the 'config_site_sample.h' */
#define PJ_CONFIG_ANDROID 1
#include <pj/config_site_sample.h>
#define PJMEDIA_HAS_VIDEO 1
#define PJMEDIA_HAS_OPENH264_CODEC 1
I am getting following log
Using OpenH264 prefix... /home/user_name/PJSIPTOOLS/openh264-1.0.0/openlib/
checking OpenH264 usability... no
As it is not detected by ./configure-android my app is crashing at runtime saying lib not found for openh264.
I am on ubuntu 14.04 32 bit.
Any suggestions.
I just encountered a similar issue. In the following, I refer to the directory, I downloaded and extracted OpenH264 to, as path-to-openh264. I created a subdirectory android within that folder and modified OpenH264's Makefile by setting PREFIX=android. Afterwards running the following commands to build OpenH264 solved the issue for me:
make OS=android NDKROOT=<path-to-ndk> TARGET=android-14 APP_ABI=armeabi ARCH=arm
make OS=android NDKROOT=<path-to-ndk> TARGET=android-14 APP_ABI=armeabi ARCH=arm clean
make install OS=android NDKROOT=<path-to-ndk> TARGET=android-14 APP_ABI=armeabi ARCH=arm
The resulting libopenh264.so file should end up in the directory path-to-openh264/android/lib/. In order to configure pjsip I used the following command:
APP_PLATFORM=android-14 ./configure-android --with-openh264=<path-to-openh264>/android
The following StackOverflow thread lead me to the right direction:
building openh264 for android platform in x86
The reason for this issue was, that I ran the make install command without the command line parameters at first. This caused the native library file to be created for the wrong ABI (the default one, which is armeabi-v7a). When building pjsip for the armeabi ABI, it didn't recognize the library, because it was built for a different ABI. At least this is what I suppose.
Actually i faced that problem too.
Solution:
step 1:go to your openh264 directory and create a folder named "android"
step 2: open makefile and set prefix
PREFIX=/your_path/openh264-1.0.0/android
step3:then build openh264 using this command
make OS=android NDKROOT=/your_path/android-ndk-r10d TARGET=android-17 APP_ABI=armeabi
step4: now build pjsip using this command
TARGET_ABI=armeabi APP_PLATFORM=android-12 ./configure-android --use-ndk-cflags --with-openh264=/your_path/openh264-1.0.0/android
hope this time you will see
Using OpenH264 prefix...
/home/user_name/PJSIPTOOLS/openh264-1.0.0/openlib/
checking OpenH264 usability... ok
http://trac.pjsip.org/repos/ticket/1758
modify the "prefix" in Makefile
run "make install ARCH=armeabi"
run "./configure-android --with_openh264=/path/to/prefix/folder"

How do I build Libgdx.so from source for Android with gdb tracing enabled?

I have setup a debug ROM on an Android device, and enabled the DDMS Native Heap in search for a libgdx memory leak.
I now have a trace, but no source code attached to follow the lead.
I downloaded libgdx source code.
How do I build it enabling gdb tracing so I can follow the code referenced by the trace ?
Update:
I built the debug .so libgdx from source
To do this, I modified the file:
libgdx/gdx/jni/build-android32.xml
Adding to the compile-natives target
I also added APP_OPTIM := debug to the Application.mk in the same folder
And added '-g' to the Android.mk file in the same folder:
LOCAL_CFLAGS := -g $(LOCAL_C_INCLUDES:%=-I%) -O2 -Wall -D__ANDROID__
This, indeed, produces a dbg libgdx.so dynamic library place in
libgdx/gdx/libs/armeabi
Although I am getting closer, I still cannot get the name of the function that is loading memory.
I am using arm-linux-androideabi-addr2line and the Hex address of the function, but it prints
??
Download the Android Source and build it.
Point DDMS to the libs with debug symbols. On the command line:
export ANDROID_SYMBOLS=$ANDROID_SOURCE/out/target/product/flo/symbols/system/lib
Note that $ANDROID_SOURCE refers to the location where you built the Android source.
start DDMS from that shell
$ddms
Now you should see the native traces on ddms.
I also built libgdx from source and added $LIBGDX_SOURCE/libgdx/gdx/obj/local/armeabi/libgdx.so
to $ANDROID_SOURCE/out/target/product/flo/symbols/system/lib to see the method names for libgdx.so.
Preliminaries
You need to set the device to debug memory
adb root
adb shell setprop libc.debug.malloc 1
adb shell stop
adb shell start
The device must be rooted or with a dbg ROM.

Building OpenSSL for Android (ARMv7) on Win32

How can I build OpenSSL for Android ARM v7 (using Android NDK) on Win32?
Until the OpenSSL's wiki and setenv-android.sh are updated accordingly, I'll publish the recipe here. The required fixes to the process are:
Update setenv-android.sh to support Windows.
Update PATH to use Android NDK's (mingw) GNU make (rather than Cygwin's).
Invoke make with a Windows-style path to Cygwin's perl.
This recipe will be a strange hybrid of Cygwin and mingw (since Android NDK gcc toolchains for win32 are mingw). I'm assuming a Windows x86_64 build of the Android NDK unpacked into c:\android-ndk-r9d, and that you wish to use a gcc 4.8 toolchain.
Install Android NDK (duh!).
Install Cygwin -- make sure to include perl
Start Cygwin shell as an administrator to make sure native symlinks will work.
Within the console, run the following script to set the variables:
export \
CYGWIN=winsymlinks:native \
ANDROID_API=android-14 \
ANDROID_DEV=c:/android-ndk-r9d/platforms/android-14/arch-arm/usr \
PATH=/cygdrive/c/android-ndk-r9d/prebuilt/windows-x86_64/bin:/cygdrive/c/android-ndk-r9d/toolchains/arm-linux-androideabi-4.8/prebuilt/windows-x86_64/bin:$PATH \
MACHINE=armv7 \
SYSTEM=android \
ARCH=arm \
CROSS_COMPILE=arm-linux-androideabi-
Now, unpack openssl:
tar xzfv openssl-1.0.1i.tar.gz (or whatever your tarball is)
cd openssl-1.0.1i (or whatever your version is)
Make sure you have actual native Win32 (!) symlinks in include/openssl:
cmd /c "dir include\openssl"
You should see something like:
13-Aug-14 05:59 PM <SYMLINK> aes.h [..\..\crypto\aes\aes.h]
13-Aug-14 05:59 PM <SYMLINK> asn1.h [..\..\crypto\asn1\asn1.h]
(etc.)
Now it's time to configure:
./config shared -no-ssl2 -no-ssl3 -no-comp -no-hw -no-engine --openssldir=/foo/bar
Ignore the failure to build (due to failure to find perl). We'll rectify this right away. Do this:
make PERL=$(cygpath -w $(which perl))
Now wait for a few minutes until it builds, and presto, you have your libcrypto.so etc.
Just a couple of comments on my experience with this:
Executing this statement:
PERL=$(cygpath -w $(which perl))
in the cygwin shell allows the shell to interpret the backslashes as escape characters and the build process chokes. To solve this I did the following:
$ echo $(cygpath -w $(which perl))
which produced the windows formatted path to the perl executable:
C:\cygwin64\bin\perl
Then I added this line to the export shown above:
PERL=c:/cygwin64/bin/perl \
There are other ways of doing this, but it worked and headed off the problem with the ./config statement documented above (not finding perl).
Second issue was the -no- statements. After running the configure, the script reports that you'll have to run make depend. I wanted to exclude MD5 (i.e. -no-md5) and when I did the make depend, it errored out with a report that MD5 was disabled. Uhhh, yes, that was kind of the idea, but I just won't use MD5 hashes. I did use the -no-ssl2 and didn't get any complaints after the make depend.
Third issue and this is a mystery. The build broke on compiling crypto because it could not find a symbol that is supposed to be defined in /crypto/objects/obj_xref.h. When I looked at the file, it was empty. Something in the perl script I suppose, but no time to debug right now, since I'm at proof of concept phase. I placed a copy from a patch that I picked up at https://github.com/devpack/openssl-android
After that, my build ran to completion. I've done no testing with this and it is not a trustworthy solution, but it did compile and produce the static libraries that I need for proof of concept for my client.
Just as an update, my shared library built with these libraries loaded fine on my target.

android ndk-build error on ubuntu 12.10 32 bit

i have downloaded the latest android ndk r8b on my ubuntu 12.10 beta 2 .
i have included the ndk directory in the PATH variable (when i write ndk-b in terminal and hit tab it auto-completes it) .
but when i try :
cd android-ndk/samples/san-angeles/jni
ndk-build
i get this error:
make: /home/mixpro/Android/android-ndk/toolchains/arm-linux-androideabi-4.6/prebuilt/linux-x86/bin/arm-linux-androideabi-gcc: Command not found
make: /home/mixpro/Android/android-ndk/toolchains/arm-linux-androideabi-4.6/prebuilt/linux-x86/bin/arm-linux-androideabi-gcc: Command not found
Compile thumb : sanangeles <= importgl.c
make: /home/mixpro/Android/android-ndk/toolchains/arm-linux-androideabi-4.6/prebuilt/linux-x86/bin/arm-linux-androideabi-gcc: Command not found
make: *** [/home/mixpro/Android/android-ndk/samples/san-angeles/obj/local/armeabi/objs/sanangeles/importgl.o] Error 127
when checking the /android-ndk/toolchains/arm-linux-androideabi-4.6/prebuilt/linux-x86/bin directory using ls i get:
arm-linux-androideabi-addr2line arm-linux-androideabi-g++
arm-linux-androideabi-gdbtui arm-linux-androideabi-size
arm-linux-androideabi-c++filt arm-linux-androideabi-gcc-4.6.x-google
arm-linux-androideabi-gprof arm-linux-androideabi-strings
arm-linux-androideabi-cpp arm-linux-androideabi-gcov
arm-linux-androideabi-readelf arm-linux-androideabi-elfedit
arm-linux-androideabi-gdb arm-linux-androideabi-run
meaning there is no arm-linux-androideabi-gcc in the directory
I am afraid that somehow you got arm-linux-androideabi-addr2line arm-linux-androideabi-gcc deleted. On linux, it is just a symlink to arm-linux-androideabi-gcc-4.6.x-google, so it's very easy to restore it. But maybe, to be on the safe side, it's worthwhile to reinstall NDK.
you should create symbolic link like this : ln -s /usr/bin/arm-linux-gnueabi-gcc-4.7 "/home/sofien/Bureau/android-ndk-r8c/toolchains/arm-linux-androideabi-4.6/prebuilt/linux-x86/bin/arm-linux-androideabi-gcc"

Debugging Android NDK native apps

I'm trying to debug and step through an Android application that segfaults. I've tried ndk-gdb, but with little luck. I've also referred to Android NDK Debugging without being able to debug my app.
When I try ndk-gdb --start, and I get:
$ ndk-gdb --start --verbose
Android NDK installation path: /opt/android-ndk-r7
Using default adb command: /opt/android-sdk-linux/platform-tools/adb
ADB version found: Android Debug Bridge version 1.0.29
Using final ADB command: '/opt/android-sdk-linux/platform-tools/adb'
Using auto-detected project path: .
Found package name: com.example.native_plasma
ABIs targetted by application: armeabi armeabi-v7a
Device API Level: 10
Device CPU ABIs: armeabi-v7a armeabi
Compatible device ABI: armeabi-v7a
Found debuggable flag: true
Found device gdbserver: /data/data/com.example.native_plasma/lib/gdbserver
Using gdb setup init: ./libs/armeabi-v7a/gdb.setup
Using toolchain prefix: /opt/android-ndk-r7/toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86/bin/arm-linux-androideabi-
Using app out directory: ./obj/local/armeabi-v7a
Found data directory: '/data/data/com.example.native_plasma'
Found first launchable activity: android.app.NativeActivity
Launching activity: com.example.native_plasma/android.app.NativeActivity
## COMMAND: /opt/android-sdk-linux/platform-tools/adb shell am start -n com.example.native_plasma/android.app.NativeActivity
Starting: Intent { cmp=com.example.native_plasma/android.app.NativeActivity }
## COMMAND: /opt/android-sdk-linux/platform-tools/adb shell sleep 2
Found running PID: 0
ERROR: Could not extract PID of application on device/emulator.
Weird, this probably means one of these:
- The installed package does not match your current manifest.
- The application process was terminated.
Try using the --verbose option and look at its output for details.
This indicates that the application segfaulted more less, but I don't know how to set a breakpoint here since gdb never actually gives a prompt.
I also tried this command:
$ ../../toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86/bin/arm-linux-androideabi-addr2line -f -e libs/armeabi/libnative-plasma.so
bedb2330
??
??:0
I have debug symbols I believe.
ndk-build -B V=1 APP_OPTIM=debug
Android.mk in jni/ has LOCAL_CFLAGS := -g
ant debug
I've also ndk-build NDK_DEBUG=1 but I still get where it looks like I don't have debug symbols.
Here's an image of the stack trace. It doesn't get any more informative:
Well NDK_DEBUG=1 and debuggable flag in manifest set to true are required. When you build the app,in your project/libs/armeabi, there should be a gdb.setup file. There is symbol search path there, check whether it is valid. And did you try this:
ndk-gdb --start --verbose --force
And looks like you are getting a null pointer exception.
In latest versions of NDK and Eclipse plug-in you can right click on package and choose Debug as -> Android Native Application
Make sure that you load your native library in either a launchable activity or in your Application class. Otherwise it wouldn't work and you'll get the following error No symbol table is loaded. Use the "file" command..
For example in Application class:
import android.app.Application;
public class MyApp extends Application {
static {
System.loadLibrary("Name");
}
public static native int doSomething();
}
Name is the name of your library (.so file) without the lib part.
I resolved putting --nowait option to the shell command:
ndk-gdb --start --verbose --nowait

Categories

Resources