sample-projects icon indicating copy to clipboard operation
sample-projects copied to clipboard

Is it possible to generate binding for already compiled shared library for Android?

Open mSerdcevas opened this issue 4 years ago • 3 comments

Hello, I couldn't find example how to generate binding for already compiled library. I tried using gradle-javacpp-android as example but I couldn't figure out how can I link my shared library. I have 4 libraries for 4 architectures:

lib
|-arm64-v8a
    |-libtest_library.so
|-armeabi-v7a
    |-libtest_library.so
|-x86
    |-libtest_library.so
|-x86_64
    |-libtest_library.so

test.h

#ifndef UNTITLED1_TEST_H
#define UNTITLED1_TEST_H

class Test {
    int m_val;
public:
    Test();

    int get_val();
};

#endif //UNTITLED1_TEST_H

mSerdcevas avatar Apr 30 '21 12:04 mSerdcevas

Sure, what is the issue exactly?

saudet avatar Apr 30 '21 12:04 saudet

This is my forked example I added libs to src/main/jniLibs added my test.h to src/main/cpp and edited NativeLibraryConfig

package com.example.myapplication;

import org.bytedeco.javacpp.*;
import org.bytedeco.javacpp.annotation.*;
import org.bytedeco.javacpp.tools.*;

@Properties(
    value = @Platform(include = {"NativeLibrary.h", "test.h"}),
    target = "com.example.myapplication.NativeLibrary"
)
public class NativeLibraryConfig implements InfoMapper {
    static {
        // Let Android take care of loading JNI libraries for us
        System.setProperty("org.bytedeco.javacpp.loadLibraries", "false");
    }

    public void map(InfoMap infoMap) {
    }
}

Where should I specify linkage to my test_library? Without linking to my library I get error:

app/src/main/cpp/jniNativeLibrary.cpp:760: error: undefined reference to 'Test::Test()'

mSerdcevas avatar Apr 30 '21 12:04 mSerdcevas

You'll need to add that to the CMakeLists.txt file. This isn't related to JavaCPP, but with the CMake build system that comes with Android Studio.

saudet avatar Apr 30 '21 12:04 saudet