Re: What's the right way to debug native libraries which are used from Java-only applications?

2,093 views
Skip to first unread message

Ilya Konstantinov

unread,
Dec 3, 2012, 7:06:31 AM12/3/12
to andro...@googlegroups.com
On Tuesday, November 27, 2012 5:47:32 PM UTC+2, Timo wrote:
Hi all,
I need to debug a native library (this project contains only one .java file, where all native methods are listed) which is called from a common Java-based Android application.
If I execute ndk-gdb in the directory of the java application project it complains about the unknown file "./jni/Android.mk":

Unless I misunderstood you, you're trying to debug a prebuilt native library, all while you haven't "added" native support to your Android project. To avoid unnecessary hassles, I recommend you simply:

1) From within Eclipse, do "Android Tools | Add Native Support".

2) Follow the directions in android-ndk\docs\PREBUILTS.html to add your native library as a prebuilt one to jni/Android.mk.

Now you can simply run ndk-gdb (or even remote native debugging from within Eclipse).

Ilya Konstantinov

unread,
Jan 26, 2013, 9:34:42 PM1/26/13
to andro...@googlegroups.com
On Friday, December 14, 2012 7:07:06 PM UTC+2, Timo wrote:
The project setup it's like this:
- Native library which contains also JNI wrapper code (no activity there)

Is the native library in C or C++ source code form, or just an .so file?
 
- Java application project which uses the JNI wrapper code (it contains the activity)

So there is IMHO no use for native support at the Java application project.

Look, the development system will work smoother for you once you stop resisting
and add "native support" :-) The only projects that don't require adding "native
support" are projects that don't use any JNI libraries.

Adding "native support" means:

1) If you're building the native library yourself (i.e. you have its C or C++
source code), then Eclipse will build your native library as part
of the project build.

For example, if you decide to add more native functions, then you could
edit the C files and rebuild right from Eclipse.

But even if you're not building it yourself, though, then still...

2) When you run or debug your project on a device (or an emulator),
Eclipse will pack your native library into the .apk file and copy it to the device.

3) You could use the native debugger from within Eclipse.

As someone else has mentioned, edit your Eclipse project configuration
and add NDK_DEBUG=1 to your NDK builder's command line.

IIRC ndk-build also does things like copying your library to the correct
directories, *even when it's a prebuilt library*.

- - -

To know what native libraries your project uses (either built by you,
or prebuilt), the Android build / deploy / debug system will use
the jni/Android.mk file.

If it's a prebuilt native library (i.e. one you don't have the source code for,
or have no intention of rebuilding), please read docs/PREBUILT.html
for instructions on how to add it to jni/Android.mk.

After you add native support to your Eclipse project, it'll start using
jni/Android.mk for the above-mentioned purposes.

Starting ndk-gdb in the native library folder leads to the situation that I am forced to edit the ndk-gdb script and set the PACKAGE_NAME hardcoded to the package of the main app - I already explained that in the first posting.
Build setup itself is fine.

I'm not quite sure how it works for you right now. Did you somehow manually
forge the .so file into the .apk?
Reply all
Reply to author
Forward
0 new messages