1. Are you ready for the Galaxy S20? Here is everything we know so far!

How to include two prebuilt interdependent shared libraries into Android application using cmake

Discussion in 'Android Development' started by Uday Makam, Nov 19, 2019.

  1. Uday Makam

    Uday Makam Lurker
    Thread Starter

    I want to include two shared libraries liba.so and libb.so into my android application. Where function of libb.so is called from function in liba.so.

    I have a Java class which calls native JNI Function as,

    package com.test.myapplication;

    public class MainActivity extends AppCompatActivity {

    static{
    System.loadLibrary(a);
    System.loadLibrary(b);
    }
    public native void testSample();

    @override
    protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    testSample();
    }
    }
    My JNI file is

    #include"a.h"

    extern "C" void JNICALL Java_com_test_myapplication_MainActivity_testSample( JNIEnv* env, jobject thiz) {
    a_foo();
    }
    a.cpp file which is part of my library liba.so is

    #include"b.h"
    void a_foo()
    {
    /* ..... code .....*/
    b_foo();
    /* ..... code .....*/
    }
    My b.cpp which is part of libb.so is

    void b_foo()
    {
    /* ..... code .....*/
    }
    I want to include liba.so and libb.so as librares and not as source into my application. Both the libraries are built using android-ndk independently.

    Line System.loadLibrary(a); gives a runtime exception
    java.lang.UnsatisfiedLinkError: dlopen failed: cannot locate symbol "b_foo" referenced by "/data/app/com.test.myapplication-yyA38UEBmsXvaqOY-hm_HQ==/lib/arm64/liba.so" when loading
     


    #1 Uday Makam, Nov 19, 2019
    Last edited: Nov 20, 2019
Loading...

Share This Page

Loading...