I have library.so, I created wrapper in C and the issue is that on Runtime when I load the wrapper, it is trying to find the library on local path.


APP_ABI := arm64-v8a x86_64


# v2 - use the prebuilt .so library

LOCAL_PATH := $(call my-dir)

#enable our C sources to call prebuilt .so library
include $(CLEAR_VARS)
LOCAL_MODULE := RokuDriver-prebuilt
LOCAL_SRC_FILES := $(LOCAL_PATH)/../jniLibs/$(TARGET_ARCH_ABI)/libRokuDriver.so

#build our own C sources
include $(CLEAR_VARS)
LOCAL_MODULE := TestDriver
LOCAL_SRC_FILES := TestDriver.c
LOCAL_SHARED_LIBRARIES := RokuDriver-prebuilt


public class RokuDriver {
    static {
        try {
        catch (Exception e) {

    public native String stringFromJNI();

    public void call() {
        Log.debug("--------------------------------------------------------------" + stringFromJNI());


android {
    namespace 'secret'
    compileSdk 34

    defaultConfig {
        applicationId "secret"
        minSdk 24
        targetSdk 34
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
        vectorDrawables {
            useSupportLibrary true

        ndk {
            abiFilters "arm64-v8a", "x86_64"

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        debug {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_17
        targetCompatibility JavaVersion.VERSION_17
    ndkVersion '26.1.10909125'
    sourceSets {
        main {
            jniLibs.srcDirs = ['libs']
    externalNativeBuild {
        ndkBuild {
            path 'src/main/jni/Android.mk'

TestDriver.c (still missing anything related to RokuDriver as I am unable to even load it.)

#include <jni.h>        // JNI header provided by JDK
#include <stdio.h>      // C Standard IO Header
#include "TestDriver.h"   // Generated

JNIEXPORT jstring Java_secret_jni_RokuDriver_stringFromJNI(JNIEnv *env, jobject thisObj) {
    return (*env)->NewStringUTF(env, "Hello from JNI !  Compiled with ABI.");


#include <jni.h>

#ifndef _Included_secret_jni_RokuDriver
#define _Included_secret_jni_RokuDriver
#ifdef __cplusplus
extern "C" {

JNIEXPORT jstring Java_secret_jni_RokuDriver_stringFromJNI(JNIEnv *, jobject);

#ifdef __cplusplus


java.lang.UnsatisfiedLinkError: dlopen failed: library "C:projectsAndroidappbuildintermediatescxxDebug1eh3n2g7/obj/local/arm64-v8a/libRokuDriver.so" not found                                                                           
at java.lang.Runtime.loadLibrary0(Runtime.java:977)                                                  
at java.lang.System.loadLibrary(System.java:1530)                                           
at secret.jni.RokuDriver.<clinit>(RokuDriver.java:18)                   
at secret.MainActivity.onCreate(MainActivity.java:104)

The file is present at C:projectsAndroidappbuildintermediatescxxDebug1eh3n2g7/obj/local/arm64-v8a/libRokuDriver.so and the apk also has the libRokuDriver.so at /libs/arm64-v8a/libRokuDriver.so
but why is it loading the library at runtime from local path instead of /libs/arm64-v8a/libRokuDriver.so
I am following the official Android guide here and dozens of articles and it is mindblowing that official Android guides do not work a single time.
If I omitt the prebuilt library and only compile TestDriver.c it works and I see in the Logcat the output.