0
Android Studio 0.3.1

Hello,

I have the following library written in C but don't have the source code for it only the libapp_module.so

libapp_module.so: ELF 32-bit LSB shared object, ARM, version 1 (SYSV), dynamically linked (uses shared libs), not stripped

I have the header file for this library:

#ifdef __cplusplus
extern "C" {
#endif

#ifdef _WIN32
#define LIB_API(type) __declspec(dllexport) type
#else 
#define LIB_API(type) type
#endif

LIB_API(int) module_init();

#ifdef __cplusplus
}
#endif

The problem is the exception when I try and call the function from my Android App:

D/dalvikvm﹕ Added shared lib /data/app-lib/com.sunsystems.snaptest-1/libapp_module.so 0x416f3d88
D/dalvikvm﹕ No JNI_OnLoad found in /data/app-lib/com.sunsystems.snaptest-1/libapp_module.so 0x416f3d88, skipping init
W/dalvikvm﹕ No implementation found for native Lcom/sunsystems/snaptest/App_Module;.module_init:()I
UnsatisfiedLinkError: Native method not found: com.sunsystems.snaptest.App_Module.module_init:()I

This is what I am doing

I have created a Android App and I want to call that module_init() from my App so I have created a class called App_Module.java

public class App_Module {
    /* Load native C libraries */
    static {
        System.loadLibrary("app_module");
    }

    public native static int module_init();
}

And I used JNI like this in my root of the project:

javah -jni -classpath build/classes/debug -d jni/ com.sunsystems.snaptest.App_Module

Which generated the following header interface:

/* DO NOT EDIT THIS FILE - it is machine generated */
#include <jni.h>
/* Header for class com_sunsystems_snaptest_App_Module */

#ifndef _Included_com_sunsystems_snaptest_App_Module
#define _Included_com_sunsystems_snaptest_App_Module
#ifdef __cplusplus
extern "C" {
#endif
/*
 * Class:     com_sunsystems_snaptest_App_Module
 * Method:    module_init
 * Signature: ()I
 */
JNIEXPORT jint JNICALL Java_com_sunsystems_snaptest_App_Module_module_1init
  (JNIEnv *, jclass);

#ifdef __cplusplus
}
#endif
#endif

Then in my Android App I load the library in the above App_Module class and call it like this:

App_Module.module_init()

So I guess it cannot find symbol inside the libapp_module.so library.

Many thanks for any suggestions,

1
  • @joni : I followed you and @Joni. But I receive the error java.lang.UnsatisfiedLinkError: module_init. Can u help me solve problem? Commented Mar 21, 2014 at 9:42

1 Answer 1

1

You have to implement the native method and make it call the function in your library. For example:

#include "header_file_for_your_library.h"

#include "com_sunsystems_snaptest_App_Module.h"

JNIEXPORT jint JNICALL Java_com_sunsystems_snaptest_App_Module_module_1init(JNIEnv *env, jclass klass) {
    return module_init();
}

Just about any tutorial on JNI or Android NDK will have further details.

Sign up to request clarification or add additional context in comments.

1 Comment

I followed you and @Joni. But I receive the error java.lang.UnsatisfiedLinkError: module_init. Can u help me solve problem?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.