I'm try to create android jni project with structure.
I want create static library test_module and include it to main shared library monitor
jni directory contain
jni
|-> MonitorPreview.cpp
|-> Processor.cpp
|-> Android.mk
|-> test_module
|-> IModule.cpp
|-> TestModule.cpp
|-> Android.mk
where jni/Android.mk
LOCAL_PATH := $(call my-dir)
MY_ROOT := $(LOCAL_PATH)
include $(call all-subdir-makefiles)
include $(CLEAR_VARS)
LOCAL_PATH := $(MY_ROOT)
LOCAL_MODULE := monitor
LOCAL_C_INCLUDES := $(LOCAL_PATH)/test_module
LOCAL_SRC_FILES := MonitorPreview.cpp \
Processor.cpp
LOCAL_STATIC_LIBRARIES := test_module
LOCAL_LDLIBS := -llog -landroid
include $(BUILD_SHARED_LIBRARY)
$(call import-module, test_module)
jni/test_module/Android.mk
LOCAL_PATH := $(call my-dir)
$(info local path = $(LOCAL_PATH))
include $(CLEAR_VARS)
LOCAL_MODULE := test_module
LOCAL_SRC_FILES := IModule.cpp \
TestModule.cpp
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)
include $(PREBUILD_STATIC_LIBRARY)
ndk-build fail with error
/home/pavel/android_dev/android-ndk-r8e/ndk-build all
local path = jni/test_module
SharedLibrary : libmonitor.so
/home/pavel/android_dev/android-ndk-r8e/toolchains/arm-linux-androideabi- 4.6/prebuilt/linux-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux- androideabi/bin/ld: ./obj/local/armeabi-v7a/objs/monitor/Processor.o: in function hrm::Processor::Processor():jni/Processor.cpp:15: error: undefined reference to 'hrm::TestModule::TestModule()'
`collect2: ld returned 1 exit status
make: *** [obj/local/armeabi-v7a/libmonitor.so] Error 1`
Sorry for bad English.
Please help.
I found answer. See diff's
jni/Android.mk
LOCAL_PATH := $(call my-dir)
MY_ROOT := $(LOCAL_PATH)
include $(call all-subdir-makefiles)
include $(CLEAR_VARS)
LOCAL_PATH := $(MY_ROOT)
LOCAL_MODULE := monitor
LOCAL_C_INCLUDES := $(LOCAL_PATH)/test_module
LOCAL_SRC_FILES := MonitorPreview.cpp \
Processor.cpp
LOCAL_LDLIBS := -llog -landroid
include $(BUILD_SHARED_LIBRARY)
$(call import-module test_module)
jni/test_module/Android.mk
LOCAL_PATH := $(call my-dir)
$(info local path = $(LOCAL_PATH))
include $(CLEAR_VARS)
LOCAL_MODULE := test_module
LOCAL_SRC_FILES := IModule.cpp \
TestModule.cpp
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)
include $(BUILD_STATIC_LIBRARY)
Related
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)
I have a shared lib (ex. libcrypto.so), but don't have header files.
Can I use this lib in other module?
I tried to use LOCAL_EXPORT_C_INCLUDES to export header files, but It doesn't work.
This is prebuilt module:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := libcrypto
LOCAL_SRC_FILES := prebuilt/$(TARGET_ARCH_ABI)/libcrypto.so
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/include
include $(PREBUILT_SHARED_LIBRARY)
And, this is module used libcrypto:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_SRC_FILES += test.c # include "openssl/crypto.h"
LOCAL_C_INCLUDES += $(crypto_PATH)/include
LOCAL_SHARED_LIBRARIES += libcrypto
LOCAL_MODULE := libtest
LOCAL_MODULE_TAGS := optional
LOCAL_ARM_MODE := arm
LOCAL_PRELINK_MODULE := false
include $(BUILD_SHARED_LIBRARY)
This is libcrypto module (boringssl):
LOCAL_PATH := $(call my-dir)
# Target shared library
include $(CLEAR_VARS)
LOCAL_MODULE_TAGS := optional
LOCAL_MODULE := libcrypto
LOCAL_EXPORT_C_INCLUDE_DIRS := $(LOCAL_PATH)/src/include
LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk $(LOCAL_PATH)/crypto-sources.mk
LOCAL_SDK_VERSION := 9
LOCAL_CFLAGS += -fvisibility=hidden -DBORINGSSL_SHARED_LIBRARY -DBORINGSSL_IMPLEMENTATION -DOPENSSL_SMALL -Wno-unused-parameter
# sha256-armv4.S does not compile with clang.
LOCAL_CLANG_ASFLAGS_arm += -no-integrated-as
LOCAL_CLANG_ASFLAGS_arm64 += -march=armv8-a+crypto
include $(LOCAL_PATH)/crypto-sources.mk
include $(BUILD_SHARED_LIBRARY)
EDIT: Added boringssl module. I actually used #include "openssl/crypto.h" in test.c
Usually, you find crypto.h under include/openssl. So, in your case, either change the #include statement in test.c
#include "openssl/crypto.h"
Or (less recommended), edit
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/include/openssl
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.
I am using an open source library to implement the facebook share features with cocos2d-x.
However, when I integrated with android, I have a problem that cannot load the .h file in "jni/screw" folder.
screenshot:
the file structure:
here it is my android.mk:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
$(call import-add-path,$(LOCAL_PATH)/../../cocos2d)
$(call import-add-path,$(LOCAL_PATH)/../../cocos2d/external)
$(call import-add-path,$(LOCAL_PATH)/../../cocos2d/cocos)
LOCAL_MODULE := cocos2dcpp_shared
LOCAL_MODULE_FILENAME := libcocos2dcpp
CPP_FILES := $(shell find $(LOCAL_PATH)/../../Classes -name *.cpp)
LOCAL_SRC_FILES := hellocpp/main.cpp
LOCAL_SRC_FILES += $(CPP_FILES:$(LOCAL_PATH)/%=%)
LOCAL_C_INCLUDES := $(LOCAL_PATH)/../../Classes \
# _COCOS_HEADER_ANDROID_BEGIN
# _COCOS_HEADER_ANDROID_END
LOCAL_STATIC_LIBRARIES := cocos2dx_static
LOCAL_WHOLE_STATIC_LIBRARIES += cocos2dx_store_static
LOCAL_WHOLE_STATIC_LIBRARIES += screw_static
# _COCOS_LIB_ANDROID_BEGIN
# _COCOS_LIB_ANDROID_END
include $(BUILD_SHARED_LIBRARY)
$(call import-module,.)
$(call import-module, extensions/cocos2dx-store)
# _COCOS_LIB_IMPORT_ANDROID_BEGIN
# _COCOS_LIB_IMPORT_ANDROID_END
How to solve? Thanks!
reference library screw:
https://github.com/hiepnd/Screw
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)