简体   繁体   English

Android JNI java.lang.UnsatisfiedLinkError

[英]Android JNI java.lang.UnsatisfiedLinkError

I'm trying to implement the method rotateBitmapCcw90 found at another question . 我正在尝试实现在另一个问题上发现的rotateBitmapCcw90方法。 In order to use this method, I've created a java class, named Utils. 为了使用此方法,我创建了一个名为Utils的Java类。 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. rotateBitmapCcw90下poject_path / JNI内部com_test_jnitest_Utils.cpp实现。 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: 我的Android.mk是:

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. 一切都可以成功编译(ndk-build和Eclipse项目),但是一旦我通过位图调用Utils.rotateBitmapCcw90,就会得到一个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? 我的cpp文件有问题吗? I have also already tried to generate a header with javah and including it on my cpp, but the same error appears. 我也已经尝试使用javah生成标头并将其包含在我的cpp中,但是出现相同的错误。

将lib名称从utils更改为bitmaputils后,我终于使它起作用。

Trying to do like this: 尝试这样做:

import android.graphics.Bitmap;

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

public class Utils {


    public static native Bitmap rotateBitmapCcw90(Bitmap bitmap);
}

Your ndk code is in "com_test_jnitest_Utils.cpp", but you add "com_test_jnitest_Utils.c" in "Android.mk". 您的ndk代码在“ com_test_jnitest_Utils.cpp”中,但是您在“ Android.mk”中添加了“ com_test_jnitest_Utils.c”。 If you change the file name extension, no error in this program. 如果更改文件扩展名,则此程序没有错误。

.mk文件中的文件应如下所示:

LOCAL_MODULE    := utils

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM