• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

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

Uday Makam

Lurker
Feb 18, 2015
2
0
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
 
Last edited:

BEST TECH IN 2023

We've been tracking upcoming products and ranking the best tech since 2007. Thanks for trusting our opinion: we get rewarded through affiliate links that earn us a commission and we invite you to learn more about us.

Smartphones