rcadaval
rcadaval

Reputation: 43

Android JNI java.lang.UnsatisfiedLinkError

I'm trying to implement the method rotateBitmapCcw90 found at another question. In order to use this method, I've created a java class, named Utils. This class is as simple as:

package com.test.jnitest;

import android.graphics.Bitmap;

public class Utils {
    static {
        System.loadLibrary("utils");
    }

    public static native Bitmap rotateBitmapCcw90(Bitmap bitmap);
}

rotateBitmapCcw90 is implemented inside com_test_jnitest_Utils.cpp under poject_path/jni. The content of this file is:

#include <jni.h>
#include <android/log.h>
#include <android/bitmap.h>

#include <stdio.h>
#include <stdlib.h>

#define  LOG_TAG    "libutils"
#define  LOGI(...)  __android_log_print(ANDROID_LOG_INFO,LOG_TAG,__VA_ARGS__)
#define  LOGE(...)  __android_log_print(ANDROID_LOG_ERROR,LOG_TAG,__VA_ARGS__)
#define  LOGD(...)  __android_log_print(ANDROID_LOG_DEBUG,LOG_TAG,__VA_ARGS__)

extern "C" {
JNIEXPORT jobject JNICALL Java_com_test_jnitest_Utils_rotateBitmapCcw90(JNIEnv * env, jobject obj, jobject bitmap)
{
    // same code of other question
    ...
}
};

My Android.mk is:

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)

LOCAL_MODULE    := libutils
LOCAL_SRC_FILES := com_test_jnitest_Utils.cpp
LOCAL_LDLIBS := -L$(SYSROOT)/usr/lib -llog
LOCAL_LDLIBS += -ljnigraphics

include $(BUILD_SHARED_LIBRARY)

Everything compiles successfully (ndk-build and Eclipse project), but as soon as I call Utils.rotateBitmapCcw90 passing a Bitmap, I get an java.lang.UnsatisfiedLinkError. The log says:

03-15 14:46:48.243: D/dalvikvm(1936): Trying to load lib /data/data/com.example.jnitest/lib/libutils.so 0x40f77c98
03-15 14:46:48.253: D/dalvikvm(1936): Added shared lib /data/data/com.example.jnitest/lib/libutils.so 0x40f77c98
03-15 14:46:48.253: D/dalvikvm(1936): No JNI_OnLoad found in /data/data/com.example.jnitest/lib/libutils.so 0x40f77c98, skipping init
03-15 14:46:48.333: W/dalvikvm(1936): No implementation found for native Lcom/test/jnitest/Utils;.rotateBitmapCcw90:(Landroid/graphics/Bitmap;)Landroid/graphics/Bitmap;

Quetion is: what am I doing wrong? Is there anything wrong with my cpp file? I have also already tried to generate a header with javah and including it on my cpp, but the same error appears.

Upvotes: 1

Views: 2069

Answers (4)

joey
joey

Reputation: 1

in your .mk file should be like this:

LOCAL_MODULE    := utils

Upvotes: 0

rcadaval
rcadaval

Reputation: 43

I finally got it to work after changing lib name from utils to bitmaputils.

Upvotes: 1

Sohyun Ahn
Sohyun Ahn

Reputation: 250

Your ndk code is in "com_test_jnitest_Utils.cpp", but you add "com_test_jnitest_Utils.c" in "Android.mk". If you change the file name extension, no error in this program.

Upvotes: 0

Dekra
Dekra

Reputation: 572

Trying to do like this:

import android.graphics.Bitmap;

static {
        System.loadLibrary("utils");
    }

public class Utils {


    public static native Bitmap rotateBitmapCcw90(Bitmap bitmap);
}

Upvotes: 0

Related Questions