Issue
New to Android NDK development, I am trying to get an Android app designed to build under Eclipse for Linux using ndkBuild to build under Android Studio on the Mac.
It is failing assembly with "unrecognized opcode". I assume this is some kind cross-compilation issue for the target processor, but I have no idea how this is configured with ndkBuild. The Linux header files needed to do this compilation were copied from an Ubuntu VM on the same Mac.
Any idea how to resolve this assembly error?
Here's my build.gradle:
defaultConfig {
applicationId "net.kismetwireless.android.pcapcapture"
minSdkVersion 13
targetSdkVersion 15
ndk {
moduleName "libpcap"
}
externalNativeBuild {
ndkBuild {
cFlags "-Wno-return-type"
}
}
}
externalNativeBuild {
ndkBuild {
path "src/main/jni/Android.mk"
}
}
And my Android.mk looks like this:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE:= libpcap
LOCAL_SRC_FILES:= \
libpcap-1.3.0/pcap-linux.c \
libpcap-1.3.0/fad-null.c \
libpcap-1.3.0/pcap.c \
libpcap-1.3.0/inet.c \
libpcap-1.3.0/gencode.c \
libpcap-1.3.0/optimize.c \
libpcap-1.3.0/nametoaddr.c \
libpcap-1.3.0/etherent.c \
libpcap-1.3.0/savefile.c \
libpcap-1.3.0/sf-pcap.c \
libpcap-1.3.0/sf-pcap-ng.c \
libpcap-1.3.0/pcap-common.c \
libpcap-1.3.0/bpf_image.c \
libpcap-1.3.0/bpf_dump.c \
libpcap-1.3.0/scanner.c \
libpcap-1.3.0/grammar.c \
libpcap-1.3.0/bpf_filter.c \
libpcap-1.3.0/version.c \
pcap_jni.c
#include $(BUILD_EXECUTABLE)
LOCAL_CFLAGS := -DSYS_ANDROID=1 -Dyylval=pcap_lval -DHAVE_CONFIG_H -D_U_="__attribute__((unused))" -I$(LOCAL_PATH)/libpcap-1.3.0
LOCAL_LDLIBS := -llog
include $(BUILD_SHARED_LIBRARY)
My error output looks like this when running ./gradlew build
:
/var/folders/k6/80v30vf13kdc8qd2rjtq35640000gn/T/pcap-linux-60f203.s: Assembler messages:
/var/folders/k6/80v30vf13kdc8qd2rjtq35640000gn/T/pcap-linux-60f203.s:357: Error: unrecognized opcode `rorw $8,$23'
...
/var/folders/k6/80v30vf13kdc8qd2rjtq35640000gn/T/pcap-linux-60f203.s:8369: Error: unrecognized opcode `rorw $8,$2'
clang: error: assembler command failed with exit code 1 (use -v to see invocation)
make: *** [/Users/dyoung/workspace/wireless-r/android-pcap-studio/app/build/intermediates/ndkBuild/debug/obj/local/mips64/objs/pcap/libpcap-1.3.0/pcap-linux.o] Error 1
Solution
For Android build, use Android header files. If some header is not available in NDK, you can use android.googlesource.com/platform/external/kernel-headers.
Note that these headers depend on the ABI and API level. If some header is missing or incomplete in NDK for android-14 but can be found for android-21 it does not necessarily mean that the required kernel function is not available, but you should be extra careful.
The latest NDK r14 proposed a new way to use the Android header files, which they call Unified headers. This switch should reduce the hassle and make Android builds easier. But this feature has not been tested enough yet.
Answered By - Alex Cohn
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.