I want to use native libraries in my Android project and I try compiling them. The error I found is caused from the incompatible file extensions. They are .c .h .m4 .y and others extensions.
here is a part of my Android.mk file
LOCAL_PATH := $(call my-dir)
TARGET_ARCH_ABI := armeabi-v7a
include $(CLEAR_VARS)
LOCAL_LDLIBS := -llog
LOCAL_MODULE := openssl-0.9.7m
FILE_LIST := $(wildcard $(LOCAL_PATH)/$(LOCAL_MODULE))
LOCAL_SRC_FILES := $(FILE_LIST:$(LOCAL_PATH)/%=%)
include $(BUILD_SHARED_LIBRARY)
include $(CLEAR_VARS)
LOCAL_LDLIBS := -llog
LOCAL_MODULE := pbc-0.5.12
FILE_LIST := $(wildcard $(LOCAL_PATH)/$(LOCAL_MODULE))
LOCAL_SRC_FILES := $(FILE_LIST:$(LOCAL_PATH)/%=%)
include $(BUILD_SHARED_LIBRARY)
include $(CLEAR_VARS)
LOCAL_LDLIBS := -llog
LOCAL_MODULE := libbswabe-0.9
FILE_LIST := $(wildcard $(LOCAL_PATH)/$(LOCAL_MODULE))
LOCAL_SRC_FILES := $(FILE_LIST:$(LOCAL_PATH)/%=%)
include $(BUILD_SHARED_LIBRARY)
include $(CLEAR_VARS)
LOCAL_LDLIBS := -llog
LOCAL_MODULE := gmp-5.0.2
FILE_LIST := $(wildcard $(LOCAL_PATH)/$(LOCAL_MODULE))
LOCAL_SRC_FILES := $(FILE_LIST:$(LOCAL_PATH)/%=%)
include $(BUILD_SHARED_LIBRARY)
include $(CLEAR_VARS)
LOCAL_LDLIBS := -llog
LOCAL_MODULE := libpbc
FILE_LIST := $(wildcard $(LOCAL_PATH)/$(LOCAL_MODULE))
LOCAL_SRC_FILES := $(FILE_LIST:$(LOCAL_PATH)/%=%)
include $(BUILD_SHARED_LIBRARY)
include $(CLEAR_VARS)
LOCAL_LDLIBS := -llog
LOCAL_MODULE := m4-1.4.16
FILE_LIST := $(wildcard $(LOCAL_PATH)/$(LOCAL_MODULE))
LOCAL_SRC_FILES := $(FILE_LIST:$(LOCAL_PATH)/%=%)
include $(BUILD_SHARED_LIBRARY)
include $(CLEAR_VARS)
LOCAL_LDLIBS := -llog
LOCAL_MODULE := cpabe-0.11
FILE_LIST := $(wildcard $(LOCAL_PATH)/$(LOCAL_MODULE))
LOCAL_SRC_FILES := $(FILE_LIST:$(LOCAL_PATH)/%=%)
include $(BUILD_SHARED_LIBRARY)
include $(CLEAR_VARS)
# LOCAL_LDLIBS := -llog
LOCAL_MODULE := PHRapp_Login_JNI
FILE_LIST := $(wildcard $(LOCAL_PATH)/$(LOCAL_MODULE))
LOCAL_SRC_FILES := $(FILE_LIST:$(LOCAL_PATH)/%=%)
include $(BUILD_STATIC_LIBRARY)
when i compile in Eclipse, it warned that there are unsupported source file extensions for the module i described in Android.mk.
How should I do for the solution?
Using $wildcard to list all files in lib build directory is not a good practice. When you work with so many open source libraries it's much easier to prepare and use standalone toolchain for NDK instead of improvizing the Android.mk.
Related
I am getting error during ndk build. I have only one android.mk file and only one Application.mk file in my project
Android NDK: Trying to define local module 'protobuf' in /home/parag.j/AndroidArm//jni/Android.mk.
Android NDK: But this module was already defined by /home/parag.j/AndroidArm//jni/Android.mk.
Here is my Android.mk file
LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE=ndktest
LOCAL_SRC_FILES=ndktest.cpp
include $(CLEAR_VARS)
LOCAL_MODULE := c++_shared
LOCAL_SRC_FILES := $(LOCAL_PATH)/inc/build/libc++_shared.so
include $(PREBUILT_SHARED_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := armnn
LOCAL_SRC_FILES := $(LOCAL_PATH)/inc/build/libarmnn.so
include $(PREBUILT_SHARED_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := armnnTfParser
LOCAL_SRC_FILES := $(LOCAL_PATH)/inc/build/libarmnnTfParser.so
include $(PREBUILT_SHARED_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := protobuf
LOCAL_SRC_FILES := $(LOCAL_PATH)/inc/build/libprotobuf.so
include $(PREBUILT_SHARED_LIBRARY)
LOCAL_LDLIBS += -lm -llog -landroid
LOCAL_CFLAGS += -DARM_NEON_64BIT -O3 -mfpu=neon -mcpu=kryo -std=c++14 -pie
LOCAL_SHARED_LIBRARIES := opencv_java3 armnn armnnTfParser protobuf c++_shared
LOCAL_C_INCLUDES := $(LOCAL_PATH)/inc/include\
include $(BUILD_SHARED_LIBRARY)
Here is my Application.mk file
APP_ABI:=arm64-v8a
APP_CFLAGS += -Ofast
APP_OPTIM := release
APP_STL := gnustl_static
APP_CPPFLAGS := -frtti -fexceptions
APP_PLATFORM := android-22
ANDROID_TOOLCHAIN_NAME := clang++
You forgot to (re)set LOCAL_MODULE for the last part of your makefile. I think the last few lines should be:
LOCAL_MODULE=ndktest
LOCAL_SRC_FILES=ndktest.cpp
LOCAL_LDLIBS += -lm -llog -landroid
LOCAL_CFLAGS += -DARM_NEON_64BIT -O3 -mfpu=neon -mcpu=kryo -std=c++14 -pie
LOCAL_SHARED_LIBRARIES := opencv_java3 armnn armnnTfParser protobuf c++_shared
LOCAL_C_INCLUDES := $(LOCAL_PATH)/inc/include
include $(BUILD_SHARED_LIBRARY)
(and get rid of the ndktest lines at the start of the file, of course)
While transforming my project from eclipse to AS.
I got a fatal error which caused by "the lib not found " problem.
My project contains jni codes,compiled by ndk build system and managed by the "Android.mk" file.
After transformed I found that two of the libraries(.so) was not packaged into the apk file while other libraries are packaged correctly.
Here is part of the content of "Android.mk" file,all libraries are packaged but "curl" and "jsqlite".The two files do exist in the right path.Is there any suggestion,thks!!
LOCAL_PATH := $(call my-dir)
MY_LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := skia
LOCAL_SRC_FILES := libs/$(TARGET_ARCH_ABI)/libskia.a
include $(PREBUILT_STATIC_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := iconv
LOCAL_SRC_FILES := libs/$(TARGET_ARCH_ABI)/libiconv.so
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/include
LOCAL_EXPORT_LDLIBS :=
include $(PREBUILT_SHARED_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := jsqlite
LOCAL_SRC_FILES := libs/$(TARGET_ARCH_ABI)/libjsqlite.so
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/include
LOCAL_EXPORT_LDLIBS := -lz
include $(PREBUILT_SHARED_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := curl
LOCAL_SRC_FILES := libs/$(TARGET_ARCH_ABI)/libcurl.so
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/include
LOCAL_EXPORT_LDLIBS :=
include $(PREBUILT_SHARED_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := gdal
LOCAL_SRC_FILES := libs/$(TARGET_ARCH_ABI)/libgdal.so
LOCAL_SHARED_LIBRARIES := jsqlite
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/include
LOCAL_EXPORT_LDLIBS := -lz
include $(PREBUILT_SHARED_LIBRARY)
Application.mk
APP_STL := gnustl_static
APP_ABI := all
Android.mk
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := libz
LOCAL_SRC_FILES := ../prebuild/libz.a
LOCAL_EXPORT_C_INCLUDES := ../prebuild/include/
include $(PREBUILT_STATIC_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := libssl
LOCAL_SRC_FILES := ../prebuild/libssl.a
LOCAL_EXPORT_C_INCLUDES := ../prebuild/include
include $(PREBUILT_STATIC_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := libcrypto
LOCAL_SRC_FILES := ../prebuild/libcrypto.a
LOCAL_EXPORT_C_INCLUDES := ../prebuild/include
include $(PREBUILT_STATIC_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := libjson-c
LOCAL_SRC_FILES := ../prebuild/libjson-c.a
LOCAL_EXPORT_C_INCLUDES := ../prebuild/include
include $(PREBUILT_STATIC_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := libcurl
LOCAL_SRC_FILES := ../prebuild/include/libcurlall/$(TARGET_ARCH_ABI)/libcurl.a
LOCAL_EXPORT_C_INCLUDES := ../prebuild/include
include $(PREBUILT_STATIC_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := curl-ndk
LOCAL_SRC_FILES := ../cpp/curl-http.cpp
LOCAL_STATIC_LIBRARIES := libcurl libssl libcrypto libz libjson-c
LOCAL_LDLIBS := -lz -llog -ljnigraphics
include $(BUILD_SHARED_LIBRARY)
clean project and I'm trying to cross compile NDK then show given below error:
/Volumes/Work/Android/Projects/app/src/main/jni/../prebuild/libz.a: error adding symbols: File in wrong format
clang++: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [/Volumes/Work/Android/Projects/app/src/main/obj/local/arm64-v8a/libcurl-ndk.so] Error 1
Its working on 32 bits fine but 64 bit its show error
Thanks in advance
You're using one prebuilt for all ABIs. You need one prebuilt for each ABI you target. The typical way to write a prebuilt module is like this:
include $(CLEAR_VARS)
LOCAL_MODULE := libz
LOCAL_SRC_FILES := ../prebuild/$(TARGET_ARCH_ABI)/libz.a
LOCAL_EXPORT_C_INCLUDES := ../prebuild/include/
include $(PREBUILT_STATIC_LIBRARY)
Then you can have prebuild/armeabi-v7a/libz.a, prebuild/arm64-v8a/libz.a, etc. Disable ABIs you don't want to build for (or don't have prebuilts for) using APP_ABI in your Application.mk.
Android.mk
LOCAL_PATH:=$(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := libopencv_core
LOCAL_SRC_FILES := $(LOCAL_PATH)/opencv_precompiled/libs/$(APP_ABI)/libopencv_core.a
include $(PREBUILT_STATIC_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := libopencv_calib3d
LOCAL_SRC_FILES := $(LOCAL_PATH)/opencv_precompiled/libs/$(APP_ABI)/libopencv_calib3d.a
include $(PREBUILT_STATIC_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := libopencv_videostab
LOCAL_SRC_FILES := $(LOCAL_PATH)/opencv_precompiled/libs/$(APP_ABI)/libopencv_videostab.a
include $(PREBUILT_STATIC_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := libopencv_videoio
LOCAL_SRC_FILES := $(LOCAL_PATH)/opencv_precompiled/libs/$(APP_ABI)/libopencv_videoio.a
include $(PREBUILT_STATIC_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := libopencv_video
LOCAL_SRC_FILES := $(LOCAL_PATH)/opencv_precompiled/libs/$(APP_ABI)/libopencv_video.a
include $(PREBUILT_STATIC_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := libopencv_shape
LOCAL_SRC_FILES := $(LOCAL_PATH)/opencv_precompiled/libs/$(APP_ABI)/libopencv_shape.a
include $(PREBUILT_STATIC_LIBRARY)
ifeq ($(APP_ABI),armeaby-v7a)
include $(CLEAR_VARS)
LOCAL_MODULE := libopencv_ts
LOCAL_SRC_FILES := $(LOCAL_PATH)/opencv_precompiled/libs/$(APP_ABI)/libopencv_ts.a
include $(PREBUILT_STATIC_LIBRARY)
endif
include $(CLEAR_VARS)
LOCAL_MODULE := libopencv_superres
LOCAL_SRC_FILES := $(LOCAL_PATH)/opencv_precompiled/libs/$(APP_ABI)/libopencv_superres.a
include $(PREBUILT_STATIC_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := libopencv_stitching
LOCAL_SRC_FILES := $(LOCAL_PATH)/opencv_precompiled/libs/$(APP_ABI)/libopencv_stitching.a
include $(PREBUILT_STATIC_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := libopencv_photo
LOCAL_SRC_FILES := $(LOCAL_PATH)/opencv_precompiled/libs/$(APP_ABI)/libopencv_photo.a
include $(PREBUILT_STATIC_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := libopencv_flann
LOCAL_SRC_FILES := $(LOCAL_PATH)/opencv_precompiled/libs/$(APP_ABI)/libopencv_flann.a
include $(PREBUILT_STATIC_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := libopencv_objdetect
LOCAL_SRC_FILES := $(LOCAL_PATH)/opencv_precompiled/libs/$(APP_ABI)/libopencv_objdetect.a
include $(PREBUILT_STATIC_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := libopencv_ml
LOCAL_SRC_FILES := $(LOCAL_PATH)/opencv_precompiled/libs/$(APP_ABI)/libopencv_ml.a
include $(PREBUILT_STATIC_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := libopencv_imgcodecs
LOCAL_SRC_FILES := $(LOCAL_PATH)/opencv_precompiled/libs/$(APP_ABI)/libopencv_imgcodecs.a
include $(PREBUILT_STATIC_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := libopencv_features2d
LOCAL_SRC_FILES := $(LOCAL_PATH)/opencv_precompiled/libs/$(APP_ABI)/libopencv_features2d.a
include $(PREBUILT_STATIC_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := libopencv_highgui
LOCAL_SRC_FILES := $(LOCAL_PATH)/opencv_precompiled/libs/$(APP_ABI)/libopencv_highgui.a
include $(PREBUILT_STATIC_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := libopencv_imgproc
LOCAL_SRC_FILES := $(LOCAL_PATH)/opencv_precompiled/libs/$(APP_ABI)/libopencv_imgproc.a
include $(PREBUILT_STATIC_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := libtbb
LOCAL_SRC_FILES := $(LOCAL_PATH)/opencv_precompiled/3rdparty/libs/$(APP_ABI)/libtbb.a
include $(PREBUILT_STATIC_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := libIlmImf
LOCAL_SRC_FILES := $(LOCAL_PATH)/opencv_precompiled/3rdparty/libs/$(APP_ABI)/libIlmImf.a
include $(PREBUILT_STATIC_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := liblibjasper
LOCAL_SRC_FILES := $(LOCAL_PATH)/opencv_precompiled/3rdparty/libs/$(APP_ABI)/liblibjasper.a
include $(PREBUILT_STATIC_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := liblibjpeg
LOCAL_SRC_FILES := $(LOCAL_PATH)/opencv_precompiled/3rdparty/libs/$(APP_ABI)/liblibjpeg.a
include $(PREBUILT_STATIC_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := liblibpng
LOCAL_SRC_FILES := $(LOCAL_PATH)/opencv_precompiled/3rdparty/libs/$(APP_ABI)/liblibpng.a
include $(PREBUILT_STATIC_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := liblibtiff
LOCAL_SRC_FILES := $(LOCAL_PATH)/opencv_precompiled/3rdparty/libs/$(APP_ABI)/liblibtiff.a
include $(PREBUILT_STATIC_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := liblibwebp
LOCAL_SRC_FILES := $(LOCAL_PATH)/opencv_precompiled/3rdparty/libs/$(APP_ABI)/liblibwebp.a
include $(PREBUILT_STATIC_LIBRARY)
include $(CLEAR_VARS)
LOCAL_C_INCLUDES := $(LOCAL_PATH)/eigen\
$(LOCAL_PATH)/inc\
$(LOCAL_PATH)/opencv_precompiled/include\
LOCAL_MODULE:=blend
LOCAL_SRC_FILES:=$(LOCAL_PATH)/src/poisson_solver.cpp $(LOCAL_PATH)/src/clone.cpp $(LOCAL_PATH)/src/seamless_cloning.cpp
LOCAL_LDLIBS += -lz -llog -landroid -ldl -lm -ljnigraphics
LOCAL_STATIC_LIBRARIES := libopencv_shape libopencv_stitching libopencv_objdetect libopencv_superres libopencv_videostab libopencv_calib3d\
libopencv_features2d libopencv_highgui libopencv_videoio libopencv_imgcodecs libopencv_video libopencv_photo\
libopencv_ml libopencv_imgproc libopencv_flann libopencv_core\
liblibjpeg liblibwebp liblibpng liblibtiff liblibjasper libIlmImf libtbb\
ifeq ($(APP_ABI),armeaby-v7a)
LOCAL_LDLIBS += libopencv_ts
endif
include $(BUILD_SHARED_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := cpu_info-jni
LOCAL_SRC_FILES := $(LOCAL_PATH)/src/utils.cpp
include $(BUILD_SHARED_LIBRARY)
Application.mk
NDK_TOOLCHAIN_VERSION := 4.9
APP_ABI := arm64-v8a
APP_CPPFLAGS += -std=c++11 -fexceptions
APP_STL := gnustl_static
This is the error i get:
/home/pedja/workspace/Projekat/android/src/main/jni/opencv_precompiled/libs/arm64-v8a/libopencv_imgcodecs.a(grfmt_jpeg.cpp.o): In function `cv::my_jpeg_load_dht(jpeg_decompress_struct*, unsigned char*, JHUFF_TBL**, JHUFF_TBL**) [clone .constprop.52]':
grfmt_jpeg.cpp:(.text.unlikely._ZN2cvL16my_jpeg_load_dhtEP22jpeg_decompress_structPhPP9JHUFF_TBLS5_.constprop.52+0x104): undefined reference to `jpeg_alloc_huff_table'
/home/pedja/workspace/Projekat/android/src/main/jni/opencv_precompiled/libs/arm64-v8a/libopencv_imgcodecs.a(grfmt_jpeg.cpp.o): In function `cv::JpegEncoder::write(cv::Mat const&, std::vector<int, std::allocator<int> > const&)':
Full error:
Error
To answer my own question.
For some reason, module name for local static libraries cannot be: "liblibjpeg" for example.
After renaming module liblibjpeg (and other libs that start with lib) to libjpeg it linked successfully.
I'd like to create two .so file within a single .mk file. But the following codes fails because there should not be a space in LOCAL_MODULE. So is there a way out?
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := gpio hello-jni
LOCAL_CFLAGS := -Werror
LOCAL_SRC_FILES := gpio.c hello-jni.c
LOCAL_LDLIBS := -llog
include $(BUILD_SHARED_LIBRARY)
I just got it works using the following codes.
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := gpio
LOCAL_CFLAGS := -Werror
LOCAL_SRC_FILES := gpio.c
LOCAL_LDLIBS := -llog
include $(BUILD_SHARED_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := h ello-jni
LOCAL_CFLAGS := -Werror
LOCAL_SRC_FILES := hello-jni.c
LOCAL_LDLIBS := -llog
include $(BUILD_SHARED_LIBRARY)