I have a small project I've coded for Android that uses a small about of NDK/JNI code. I'd like to share this code between two projects but I'm having little luck so far. First off, I've tried to refactor off the NDK specific code into a library which I think link to both projects using

'project->java build path->source->link source'

and specifying the native library in there. Sounds good but it's wrong. The project from which I refactored the code still requires the .so library file in


Removing that from the original project whilst still linking the source of the refactored library fails.

Secondly, creating a new project and attempting to use the NDK library I wrote by both including the source of the library and copying over the .so files from 'obj' and 'libs' into the root directory of the new project fails. It seems to pass


At least, it didn't assert.

The code gets as far as my first NDK call and then crashes without being caught by my exception handler.

Any hints would be welcome - such as foolproof ways to get NDK to load a library, typical gotchas and NDK debugging techniques.

Thanks in advance,



When I worked with the NDK a year ago, I build the .so file with the NDK make. Then I copied the .so from the NDK to the /lib folder of my project. It worked without a problem. Do the method names in your NDK-Project match the fully qualified class-/methodnames of the classes where you want to call the JNI functions? If you have a class:

package com.example;
 public class Foo{
  native public void bar();

Then the method in your C file must be something like:

void com_example_Foo_bar();

If that didn't help, could you then post the exception?

| improve this answer | |
  • \$\begingroup\$ Thanks for the answer! The signature is almost certainly correct because it works in the project I copied it from. The exception is too long to post in its entirety so here's the beginning and end. \$\endgroup\$ – Luther Aug 5 '11 at 18:45
  • \$\begingroup\$ Actually, scrub that. Here's the full exception in pastebin: pastebin.com/RgGjPcTn \$\endgroup\$ – Luther Aug 5 '11 at 19:18
  • \$\begingroup\$ I've rediscovered the LogCat android output and it has some info: \$\endgroup\$ – Luther Aug 5 '11 at 21:59
  • \$\begingroup\$ 08-05 22:57:16.410: WARN/dalvikvm(23479): No implementation found for native Ltcode/tmath/BufferUtils;.copyJni ([FLjava/nio/Buffer;II)V 08-05 22:57:16.420: INFO/GLThread(23479): exiting tid=12 \$\endgroup\$ – Luther Aug 5 '11 at 22:00
  • \$\begingroup\$ Which is odd as the .so file is there in the libs/armeabi folder. \$\endgroup\$ – Luther Aug 5 '11 at 22:00

Solved it - the missing signature was a bug in the C++ code that didn't manifest in the other project as that function was never called. Just a miss named function signature, that's all.

| improve this answer | |
  • \$\begingroup\$ Why the -1 ? What's wrong with this? \$\endgroup\$ – Luther Aug 7 '11 at 11:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.