Iam new to android ndk , i have created basic app with android ndk and i have already created all mk files ( android.mk and application.mk ) how to solve the abi error
enter code here LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
#opencv
OPENCVROOT:= C:\OpenCV-OpenCV 3.2-android-sdk
OPENCV_CAMERA_MODULES:=on
OPENCV_INSTALL_MODULES:=on
OPENCV_LIB_TYPE:=SHARED
include ${OPENCVROOT}/sdk/native/jni/OpenCV.mk
LOCAL_SRC_FILES := com_example_working_new.cpp
LOCAL_LDLIBS += -llog
LOCAL_MODULE := MyLibs
include $(BUILD_SHARED_LIBRARY)
my Application.mk file
enter code here APP_STL := gnustl_static
APP_CPPFLAGS := -frtti -fexceptions
APP_ABI := armeabi-v7a
APP_PLATFORM := android-16
the simple way is to make all APP_Abi for different platforms and emulators edit this in your application.mk file.
enter code here
APP_ABI :=all
Related
Here is my Android.mk
LOCAL_PATH := $(call my-dir)
LOCAL_STATIC_LIBRARIES = -lboost_system ...
include $(CLEAR_VARS)
LOCAL_MODULE := AVL
LOCAL_MODULE_FILENAME:= libAVL
LOCAL_SRC_FILES := AVL.cpp
LOCAL_CFLAGS += -I$(LOCAL_PATH)/boost/include/boost-1_55
LOCAL_CPPFLAGS += -fexceptions
LOCAL_CPPFLAGS += -frtti
include $(BUILD_SHARED_LIBRARY)
include $(BUILD_STATIC_LIBRARY)
Application.mk
APP_ABI := all
APP_STL := stlport_static
Error:
Android NDK: jni/Android.mk:AVL: LOCAL_MODULE_FILENAME must not contain a file extension
/home/manevbg/Documents/android-sdks/android-ndk-r10/build/core/build-static-library.mk:29: *** Android NDK: Aborting . Stop.
Any idea how to build shared library?
PP: Using eclipse.
Remove the LOCAL_MODULE_FILENAME:= libAVL. The build system will correctly prefix the library with 'lib' for you.
I've compiled a 3rd party library on Linux using a standalone toolchain, and I'm now trying to load that library in my app.
Problem is I'm getting java.lang.UnsatisfiedLinkError: dlopen failed: cannot locate symbol "_Znwj" referenced by "libmxnet_predict.so"
I've tried adding CFLAGS and LDFLAGS, both APP & LOCAL, but to no avail.
Before you ask, I'm developing with ADT because I have to.
This is my Application.mk:
APP_STL := gnustl_shared
APP_CFLAGS += -std=c++11
APP_CPPFLAGS := -frtti -fexceptions
APP_ABI := armeabi-v7a
APP_PLATFORM := android-19
My (simplified) Android.mk:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
OPENCV_LIB_TYPE:=SHARED
OPENCV_CAMERA_MODULES:=off
OPENCV_INSTALL_MODULES:=on
NDK_TOOLCHAIN_VERSION=4.9
include $(CLEAR_VARS)
include $(PREBUILT_SHARED_LIBRARIES)
include C:/OpenCV-2.4.8-android-sdk/sdk/native/jni/OpenCV.mk
LOCAL_MODULE := FreshubML
LOCAL_C_INCLUDES += $(LOCAL_PATH)
LOCAL_SRC_FILES := Mldevlib.cpp \
Tablet.cpp \
Interface.cpp \
LOCAL_LDLIBS += -llog -ldl -landroid -lm -ljnigraphics -lstdc++
C:\KitchenVision\Workspaces\MLDevWorkspace\MLDev\assets\share
include $(BUILD_SHARED_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := libmxnet_predict
LOCAL_SRC_FILES := lib/armeabi-v7a/libmxnet_predict.so
include $(PREBUILT_SHARED_LIBRARY)
Searching the standalone toolchain I saw that the symbol was referenced in libgnust_shared.so which I added to my project via APP_STL and in libstdc++.so but still, same error.
How do I get this to work?
I have a Application.mk and a Android.mk file.
Application.mk looks like
NDK_TOOLCHAIN_VERSION := 4.8
APP_PLATFORM := android-9
APP_STL := c++_shared
APP_ABI := armeabi-v7a
and my Android.mk looks like
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := foo1
LOCAL_SRC_FILES := foo1.cpp
# ... some other stuff ...
include $(BUILD_SHARED_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := foo2
LOCAL_SRC_FILES := foo2.cpp
# ... some other stuff ...
include $(BUILD_SHARED_LIBRARY)
Now I want that library libfoo1 use c++_shared for APP_STL and libfoo2 use c++_static for APP_STL. (I know, normally that should not be made relation between app_stl values with static and shared build android). Is there a easy way without building a extra project and import the library to the other project?
Yes, it is possible. Do the following changes:
# Application.mk
APP_STL := none
This way you disable internal logic of choosing STL implementation of NDK build system. Now, specify manually which C++ stdlib implementation you want link with:
# Android.mk
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := foo1
LOCAL_SRC_FILES := foo1.cpp
LOCAL_SHARED_LIBRARIES := c++_shared
# ... some other stuff ...
include $(BUILD_SHARED_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := foo2
LOCAL_SRC_FILES := foo2.cpp
LOCAL_STATIC_LIBRARIES := c++_static
# ... some other stuff ...
include $(BUILD_SHARED_LIBRARY)
$(call import-module,cxx-stl/llvm-libc++)
I am working with Android+NDK+OpenCV.
I keep getting the following build error
Android NDK: Check that ../../OpenCV-2.4.10-android-sdk/sdk/native/jni/../libs/arm64-v8a/libopencv_java.so exists or that its path is correct
../../android-ndk-r10d/build/core/prebuilt-library.mk:45: *** Android NDK: Aborting . Stop.
My Application.mk file is:
APP_PLATFORM := android-8
APP_ABI := armeabi armeabi-v7a arm64-v8a x86 x86_64 mips mips64
APP_OPTIM := debug
NDK_DEBUG := 1
NDK_TOOLCHAIN_VERSION := 4.6
APP_STL := gnustl_shared
APP_CPPFLAGS := -fexceptions -frtti
And my Android.mk file is:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
OPENCV_INSTALL_MODULES := on
include ../../OpenCV-2.4.10-android-sdk/sdk/native/jni/OpenCV.mk
LOCAL_MODULE := document_scanner
LOCAL_SRC_FILES := jni_part.cpp
LOCAL_C_INCLUDES :=../../OpenCV-2.4.10-android-sdk/sdk/native/jni/include
LOCAL_LDLIBS += -llog
include $(BUILD_SHARED_LIBRARY)
Try to move include ../../OpenCV-2.4.10-android-sdk/sdk/native/jni/OpenCV.mk below include $(CLEAR_VARS)
Environment
android-ndk-r10c
VisualGDB
Windows x64
Use-case 1
ADB Cmdline executable ( no Java / APK ) is consist of several C++ files
Executable is compiled having "APP_STL := gnustl_static" at Application.mk
Executable is successfully compiled and running
Use-case 2
The ADB tool of Use-case 1 is split into two separate projects
A static library encapsulating general purpose functionality
The ADB Tool minus the functionality moved out to the static lib
Executable & static Lib are compiled having "APP_STL := gnustl_static" at Application.mk
ADB Exe is compiled having LOCAL_LDLIBS := -L$(PATH_TO_STATIC_LIB) -lstaticlib
Compilation fail with "undefined reference to `std::terminate()'" Linker error
Problem at hand
When compiling all CPP files as one project all goes fine, no linker error.
When spiting the logic into a thin executable and a staticlib (that the executable is linked against ) I get an "undefined reference to `std::terminate()'" Linker error.
It seems to me as if "gnustl_static" is not linked with the executable although "APP_STL := gnustl_static" is specified...
What am I missing here? Is there any way to force 'gnustl_static' to link ?
The make files for reference:
Makefile where all files are part of the same executable (WORKING)
Application.mk
APP_STL := gnustl_static
APP_ABI := all
APP_CFLAGS := -std=gnu++11
APP_CPPFLAGS := -std=gnu++11
NDK_TOOLCHAIN_VERSION := 4.9
Android.mk
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := ScreenCapSvc
LOCAL_SRC_FILES := ScreenCapSvc.cpp SnapshotController.cpp SimpleTCPStream.cpp SocketsServer.cpp uuids.cpp
LOCAL_C_INCLUDES :=
LOCAL_STATIC_LIBRARIES :=
LOCAL_SHARED_LIBRARIES :=
LOCAL_LDLIBS := -llog
LOCAL_CFLAGS :=
LOCAL_CPPFLAGS :=
LOCAL_LDFLAGS :=
COMMON_SRC_FILES := $(LOCAL_SRC_FILES)
include $(BUILD_EXECUTABLE)
Makefiles where files are split into a static lib and executable that links against the lib
(NOT WORKING)
Executable Application.mk
APP_STL := gnustl_static
APP_ABI := all
APP_CFLAGS := -std=gnu++11
APP_CPPFLAGS := -std=gnu++11
NDK_TOOLCHAIN_VERSION := 4.9
Executable Android.mk
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := ScreenCapSvc
LOCAL_SRC_FILES := ScreenCapSvc.cpp SnapshotController.cpp
LOCAL_C_INCLUDES :=
LOCAL_STATIC_LIBRARIES :=
LOCAL_SHARED_LIBRARIES :=
LOCAL_LDLIBS := -llog -L$(PATH_TO_STATIC_LIB) -lCollections_statis
LOCAL_CFLAGS :=
LOCAL_CPPFLAGS :=
LOCAL_LDFLAGS :=
COMMON_SRC_FILES := $(LOCAL_SRC_FILES)
include $(BUILD_EXECUTABLE)
Static Lib Application.mk
APP_STL := gnustl_static
APP_ABI := all
APP_CFLAGS := -std=gnu++11
APP_CPPFLAGS := -std=gnu++11
NDK_TOOLCHAIN_VERSION := 4.9
APP_MODULES := Collections-static Collections-shared
Static Lib Android.mk
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := Collections-shared
LOCAL_SRC_FILES := SimpleTCPStream.cpp SocketsServer.cpp uuids.cpp
LOCAL_C_INCLUDES :=
LOCAL_STATIC_LIBRARIES :=
LOCAL_SHARED_LIBRARIES :=
LOCAL_LDLIBS := -llog
LOCAL_CFLAGS :=
LOCAL_CPPFLAGS :=
LOCAL_LDFLAGS :=
COMMON_SRC_FILES := $(LOCAL_SRC_FILES)
include $(BUILD_SHARED_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := Collections-static
LOCAL_SRC_FILES := $(COMMON_SRC_FILES)
include $(BUILD_STATIC_LIBRARY)
This isn't a bug in the NDK build system, but it is an issue with how you are using it.
If you run ndk-build V=1, you see the actual commands that it tries to execute, and you'd see that it already tries to link in gnustl_static, but it links it in before linking in your own static library. The linker only tries libraries in the order they are specified on the linker command line, which means that it won't try to use the earlier specified gnustl_static library to resolve undefined references from a later library.
The correct solution here is to not use LOCAL_LDLIBS for forcing linking to a static library, but use the NDK provided infrastructure for linking to static libraries. That is, change your executable Android.mk like this:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := ScreenCapSvc
LOCAL_SRC_FILES := ScreenCapSvc.cpp SnapshotController.cpp
LOCAL_STATIC_LIBRARIES := Collections_static
LOCAL_LDLIBS := -llog
include $(BUILD_EXECUTABLE)
include $(CLEAR_VARS)
LOCAL_MODULE := Collections_static
LOCAL_SRC_FILES := $(PATH_TO_STATIC_LIB)/libCollections_static.a
include $(PREBUILT_STATIC_LIBRARY)
This way, you include the static library into the build of the executable in the same way regardless if the static library is built as part of the same build, or is a prebuilt library.
This syntax also allows you to add LOCAL_EXPORT_C_INCLUDES in the section for the static library, to add the right include path when building the executable, without having to manually add it to section for the executable.
It appears that indeed although "APP_STL := gnustl_static" is strictly specified at Application.mk of the Executable it is not really linked, to force gnustl_static to link I have added the following to LOCAL_LDLIBS of Android.mk
LOCAL_LDLIBS += -L$(NDK_ROOT)/sources/cxx-stl/gnu-libstdc++/4.9/libs/$(TARGET_ARCH_ABI) -lgnustl_static
Seems to me like a bug in the NDK build system...