Use C library in Android over NDK

What I want to do:

I found the C library that calculates the audio stream pitch and wants to use it in Android.

I thought, instead of porting it, I could also use it using the NDK, right?

How it works? Of course I have to install NDK, and then? Can I call the functions of this C library, as usual, in Android?

The library in C that I want to import is:

#include "second_c_file.h" #include <math.h> #include <stdlib.h> #include <string.h> #ifndef max #define max(x, y) ((x) > (y)) ? (x) : (y) #endif #ifndef min #define min(x, y) ((x) < (y)) ? (x) : (y) #endif int _power2p(int value) { ... } typedef struct _minmax { int index; struct _minmax *next; } minmax; double _test_calculate(double * var1, int var2, int var3) { ... } 

The file "second_c_file.h" is another file that I need to import, obviously.

Thanks for your help!

+6
source share
2 answers

A good tutorial on getting started with NDK can be found here . And yes, you should be able to compile it and call it from the NDK without any changes (assuming that the code does not reference other libraries).

+6
source

Take a look at the NDK launch examples: http://developer.android.com/sdk/ndk/overview.html#samples

Then in your NDK see the two-libs example. You probably want to just statically link your third-party tone detection library to your own C code.

You will need to look at Android.mk and modify it to statically create your third-party library, and then indicate that your main project is using this library.

It should be pretty simple. NDK (did not use it at the time) is a little bear. So make sure your build environment (especially if you use Windows + Cygwin) works. Make sure hello-jni builds, and two libs libraries are built by default. Change the second and you should be there.

+7
source

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


All Articles