Linking to prebuilt libraries using NDK using gradle

I have an Android project that includes NDK code. From this code, I need to call functions from other libraries built using the NDK that I have in the jniLibs folder:

jniLibs/armeabi/libtess.so jniLibs/armeabi-v7a/libtess.so ... 

if I try to load these libraries from java like System.loadLibrary ("tess"), it works fine. However, when I try to link my NDK library with it by adding this to build.gradle:

 ndk { moduleName "myJNILib" stl "stlport_shared" ldLibs "log", "tess" } 

he cannot find him.

And, of course, if I do not contact him, he cannot compile myJNILib, since he cannot find the characters. Is there a way to make this work with gradle? Or do I really need to build my library outside of gradle if I want to link with other ready-made libraries?

+6
source share
1 answer

What I think you want to do mainly relies on the natural NDK building ... other ... I'm not sure what that good word is.

In any case, you will want to follow this tutorial. It worked pretty neat for my stuff. You will also most likely want to read this introduction to Android.mk files . This is very useful for debugging and ensuring proper communication.

You may have two problems:

  • Undefined character errors, which can be an absolute pain. Most likely, you will want to eliminate this dependency. I spent several hours on this problem and finally came to the conclusion that the file simply should not be there. Somehow.
  • You may also find that you cannot find the file extension you are working on (Ergo, he may say that foo1.so cannot find the library foo2.so. #, even though you linked foo2.so. Maybe , you will have to compile the .a library if this happens, but it may not be the best solution.).

Ok, hope this helps!

0
source

Source: https://habr.com/ru/post/970285/


All Articles