Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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

MyOriginalProject\libs\armeabi\MyNativeLibrary.so

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

System.loadLibrary("MyNativeLibrary")

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,

Tim.

share|improve this question

2 Answers 2

up vote 1 down vote accepted

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?

share|improve this answer
    
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. –  Luther Aug 5 '11 at 18:45
    
Actually, scrub that. Here's the full exception in pastebin: pastebin.com/RgGjPcTn –  Luther Aug 5 '11 at 19:18
    
I've rediscovered the LogCat android output and it has some info: –  Luther Aug 5 '11 at 21:59
    
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 –  Luther Aug 5 '11 at 22:00
    
Which is odd as the .so file is there in the libs/armeabi folder. –  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.

share|improve this answer
    
Why the -1 ? What's wrong with this? –  Luther Aug 7 '11 at 11:57

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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