Search code examples
androidcmakeandroid-ndksipbaresip

Implementing baresip NDK library causes lack of *.so file


I want to implement baresip lib into my Android project using NDK.

I've found up-to-date "bare bones" demo-project in HERE. As in readme I've created some native libs from another repo and placed in "distribution" folder. Project is compiling, installing, working fine. Comparing to Android native sip implementation this lib is just awesome, use it, forget about permission.USE_SIP, its rubish.

Now I want to import baresip into my project, but without Java/Kotlin files, planning to build own. So my steps:

  1. Added externalNativeBuild entries to build.gradle
  2. Copied cpp and distribution folders to proper places in my structure
  3. Invalidate cache and restart

And got exception:

Build command failed.

Error while executing process C:\Android\sdk\cmake\3.6.4111459\bin\cmake.exe with arguments {--build C:\Android\projects\MyApplication\app.cxx\cmake\debug\armeabi-v7a --target baresip}

[1/2] Building C object CMakeFiles/baresip.dir/baresip.c.o

[2/2] Linking C shared library C:\Android\projects\MyApplication\app\build\intermediates\cmake\debug\obj\armeabi-v7a\libbaresip.so

FAILED: cmd.exe /C "..."

next some duplicated lines like:

src/video.c:331: error: undefined reference to 'atof'

src/main/main.c:944: error: undefined reference to 'signal'

src/main/main.c:775: error: undefined reference to '__FD_ISSET_chk'

src/main/main.c:690: error: undefined reference to '__FD_SET_chk'

C:/Android/projects/MyApplication/app/src/main/cpp/../../../../distribution/openssl/lib/armeabi-v7a/libcrypto.a(armcap.o):armcap.c:function OPENSSL_cpuid_setup: error: undefined reference to 'sigfillset'

and ends with

clang: error: linker command failed with exit code 1 (use -v to see invocation)

ninja: build stopped: subcommand failed.

note app/src/main/cpp/../../../../distribution/ files path, as declared in CMakeLists:

set(distribution_DIR ${CMAKE_SOURCE_DIR}/../../../../distribution)

For me it looks like not-visible files for compiler, but when I add/remove some/any ../ error changes to clearly suggesting wrong path. besides same path and hierarchy is in sample project

I've tried to strip out baresip.c file, but its crashing with just logging OnLoad call...

#include <string.h>
#include <pthread.h>
#include <jni.h>
#include <android/log.h>
#include <stdlib.h>
#include <re.h>
#include <baresip.h>

#define LOGD(...) \
    if (log_level_get() < LEVEL_INFO) ((void)__android_log_print(ANDROID_LOG_DEBUG, "Baresip Lib", __VA_ARGS__))


JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM* vm, void* reserved) {
    LOGD("at JNI_OnLoad\n");
    return JNI_VERSION_1_6;
}

crash still occurs, but when I comment out if (log_level_get() < LEVEL_INFO) call my project is building and install just fine... log_level_get() comes from baresip.h, which is #included, libbaresip.a files (per abi) present, so why is libbaresip.so missing, why it isn't generating? what lines are present in sample project which makes it to build and work?

(yep, I'm pretty weak in native, lost some support from colleagues due to coronavirus...)


Solution

  • turns out it was a bit hidden, but nothing tough... target/compile SDK version should be at least 21 for this lib, I had 19, thats why ndk wasn't compiling properly...