안녕하세요.. 만약 사악미소님께서 제 글을 또 보신다면!!! 정말 감사합니다 ㅠ_ㅜ
덕분에 잘 올릴 수 있었어요 ㅠ_ㅜ 하지만 또 막히는 것이 있습니다.. 도와 주세요 ㅠ_ㅜ
일단... 제가 하는 것은 ndk를 통해서 libpcap 라이브 러리를 올리는 것이 였는데요..
ndk-build 를 통해서 만들어진 libpcap.so 는 C:\android-ndk\samples\libpcap\libs\armeabi 여기에 있습니다.
이걸 통해 제가 해보려는 ㅈㅏ바 코드는 ----------------------------------------------------------------------------------------------------------
package org.umit.android.libpcaptest;
import android.app.Activity;
import android.os.Bundle;
public class libpcaptest extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
static{
System.loadLibrary("pcaptest");
}
private native void testLog(String logThis);
}
javah를 통해 .h 파일도 생성 하였어요.........
/* DO NOT EDIT THIS FILE - it is machine generated */
#include <jni.h>
/* Header for class org_umit_android_libpcaptest_libpcaptest */
#ifndef _Included_org_umit_android_libpcaptest_libpcaptest
#define _Included_org_umit_android_libpcaptest_libpcaptest
#ifdef __cplusplus
extern "C" {
#endif
/*
* Class: org_umit_android_libpcaptest_libpcaptest
* Method: testLog
* Signature: (Ljava/lang/String;)V
*/
JNIEXPORT void JNICALL Java_org_umit_android_libpcaptest_libpcaptest_testLog
(JNIEnv *, jobject, jstring);
#ifdef __cplusplus
}
#endif
#endif
그것을 통해 libpcap-native.c 라는 .c 코드를 만들었구요...
#include <jni.h>
#include <string.h>
#include <android/log.h>
#include <pcap.h>
#define DEBUG_TAG "Sample_LIBPCAP_DEBUGGING"
JNIEXPORT void JNICALL Java_org_umit_android_libpcaptest_libpcaptest_testLog
(JNIEnv *env, jclass clazz, jstring message)
{
char errbuf[1024];
errbuf[0] = '\0';
char *szLogThis;
char *dev = pcap_lookupdev(errbuf);
if (dev == NULL) {
szLogThis = "Couldn't find default device";
}
else szLogThis = dev;
__android_log_print(ANDROID_LOG_DEBUG, DEBUG_TAG, "Device status: [%s]", szLogThis);
__android_log_print(ANDROID_LOG_DEBUG, DEBUG_TAG, "errbuf [%s]", errbuf);
(*env)->ReleaseStringUTFChars(env, message, szLogThis);
}
그 다음 Anroid.mk 파일 ㅇㅏ래와 같아요...
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := pcaptest
LOCAL_SRC_FILES := libpcap-native.c
LOCAL_C_INCLUDES := $(NDK_ROOT)/samples/libpcap/jni
LOCAL_STATIC_LIBRARIES := libpcap
LOCAL_LDLIBS := -ldl -llog
LOCAL_LDLIBS += -L $(NDK_ROOT)/samples/libpcap/libs/armeabi
include $(BUILD_SHARED_LIBRARY)
include $(NDK_ROOT)/samples/libpcap/jni/Android.mk
그리고 아래와 같이 libpcap.so 와 libpcaptest.so 모두 생성 되는 것을 보았고.. 분명 안에 내용도 0bytes는 아닌데요..ㅠ_ㅜ
아래와 같은 에러가 나와요 ㅠ_ㅜ
05-05 13:03:35.818: E/AndroidRuntime(647): Caused by: java.lang.UnsatisfiedLinkError: Cannot load library: link_image[1936]: 37 could not load needed library 'libpcap.so' for 'libpcaptest.so' (load_library[1091]: Library 'libpcap.so' not found)
흑흑 ㅠ_ㅜ 혹시나 해서
System.loadLibrary("pcaptest"); -> System.loadLibrary("libpcaptest"); 요렇게 바꾸고 다시 해봤는데요..
05-05 13:26:32.718: E/AndroidRuntime(696): Caused by: java.lang.UnsatisfiedLinkError: Couldn't load libpcaptest: findLibrary returned null
요런 에러가 나옵니다. ㅠ_ㅜ
아... 산넘어 산인것 같아요 ㅠ_ㅜ
도와주세요 ㅠ_ㅜ
긴글 읽어 주셔서 감사합니다!!
UnsatisfiedLinkError 는 심볼정보가 안맞을때 나오는 에러입니다.
혹은 존재하지 않은 lib 를 사용할때도 나올수 있는 에러메세지 이므로 이부분 확인해 보세요..
심볼이 안맞는건.. 문법검사는 통과해서 빌드는되엇으나.. 치명적인 에러가 내포했을때 자주 발생됩니다.