我正在尝试将Jnetpcap移植到Android,以便将其用于解析.pcap文件。 Jnetpcap是libpcap的java包装器,它使用JNI。我已经使用android的源代码树将libpcap编译为静态库。
当编译Jnetpcap作为共享库时,我收到错误,因为我必须链接libpcap.a但我不知道怎么能告诉Android.mk他必须链接到我有的libpcap.a文件
使用“LOCAL_STATIC_LIBRARIES:= libpcap”将无法正常工作,因为在android NDK中默认不提供libpcap。
如果你们中的任何人能帮助我,我会非常感激。
这是我当前的Android.mk文件:
include /home/sergio/workspace/MyApp/jni/libpcap/Android.mk
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := jnetpcap
LOCAL_SRC_FILES :=\
jnetpcap.cpp\
packet_flow.cpp\
packet_jheader.cpp\
jnetpcap_pcap_header.cpp\
nio_jbuffer.cpp\
winpcap_stat_ex.cpp\
winpcap_send_queue.cpp\
winpcap_ext.cpp\
jnetpcap_ids.cpp\
jnetpcap_dumper.cpp\
jnetpcap_utils.cpp\
util_in_cksum.cpp\
jnetpcap_beta.cpp\
nio_jmemory.cpp\
packet_jsmall_scanner.cpp\
packet_protocol.cpp\
nio_jnumber.cpp\
packet_jheader_scanner.cpp\
library.cpp\
packet_jscan.cpp\
jnetpcap_pcap100.cpp\
util_checksum.cpp\
packet_jpacket.cpp\
winpcap_ids.cpp\
jnetpcap_bpf.cpp
LOCAL_C_INCLUDES := /home/sergio/android-ndk-r5b/platforms/android-8/arch-arm/usr/include /home/sergio/workspace/Shark/jni/libpcap
LOCAL_STATIC_LIBRARIES := libpcap
include $(BUILD_SHARED_LIBRARY)
答案 0 :(得分:42)
终于解决了。我的Android.mk代码:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := libpcap
LOCAL_SRC_FILES := libpcap.a
include $(PREBUILT_STATIC_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := jnetpcap
LOCAL_SRC_FILES :=\
jnetpcap.cpp\
packet_flow.cpp\
packet_jheader.cpp\
jnetpcap_pcap_header.cpp\
nio_jbuffer.cpp\
winpcap_stat_ex.cpp\
winpcap_send_queue.cpp\
winpcap_ext.cpp\
jnetpcap_ids.cpp\
jnetpcap_dumper.cpp\
jnetpcap_utils.cpp\
util_in_cksum.cpp\
jnetpcap_beta.cpp\
nio_jmemory.cpp\
packet_jsmall_scanner.cpp\
packet_protocol.cpp\
nio_jnumber.cpp\
packet_jheader_scanner.cpp\
library.cpp\
packet_jscan.cpp\
jnetpcap_pcap100.cpp\
util_checksum.cpp\
packet_jpacket.cpp\
winpcap_ids.cpp\
jnetpcap_bpf.cpp
LOCAL_C_INCLUDES :=\
/home/sergio/android-ndk-r5b/platforms/android-8/arch-arm/usr/include\
/home/sergio/workspace/MyApp/jni/libpcap
LOCAL_STATIC_LIBRARIES := libpcap
include $(BUILD_SHARED_LIBRARY)
答案 1 :(得分:13)
您必须将pcap构建为静态模块。像这样的东西
include $(CLEAR_VARS)
LOCAL_MODULE := pcap
LOCAL_CFLAGS := declare_flags
LOCAL_C_INCLUDES := declare_include
LOCAL_SRC_FILES := src_files
include $(BUILD_STATIC_LIBRARY)
此构建pcap作为本地模块,您可以使用LOCAL_STATIC_LIBRARIES链接
只需添加
LOCAL_STATIC_LIBRARIES := pcap
之前打电话
include $(BUILD_SHARED_LIBRARY)