Unable to load -landroid jni - android

I am unable to load -landroid lib in my package, I am using following Android.mk
code
include $(CLEAR_VARS)
LOCAL_MODULE := ShirtsAR
TARGET_PLATFORM := android-5
USE_OPENGL_ES_1_1 := false
ifeq ($(USE_OPENGL_ES_1_1), true)
OPENGLES_LIB := -lGLESv1_CM
OPENGLES_DEF := -DUSE_OPENGL_ES_1_1
else
OPENGLES_LIB := -lGLESv2
OPENGLES_DEF := -DUSE_OPENGL_ES_2_0
endif
ANDROID_LIB := -landroid
LOCAL_SRC_FILES := ShirtsAR.cpp
LOCAL_CFLAGS := -Wno-write-strings $(OPENGLES_DEF)
LOCAL_LDLIBS := -llog $(OPENGLES_LIB) $(ANDROID_LIB)
LOCAL_ARM_MODE := arm
include $(BUILD_SHARED_LIBRARY)
Please guide, I am stuck.. :(
getting following error
/android-ndk-r7/toolchains/arm-linux-androideabi-4.4.3/prebuilt/windows/bin/../lib/gcc/arm-linux-androideabi/4.4.3/../../../../arm-linux-androideabi/bin/ld.exe: cannot find -landroid
collect2: ld returned 1 exit status
make: * [obj/local/armeabi/libShirtsAR.so] Error 1

Native Activity is only supported with API level 9 and higher (see docs/STABLE-APIS.html in your NDK distribution). So if you want to link against libandroid you'll need to change to
TARGET_PLATFORM := android-9

I have to use this APP_PLATFORM variable in the Application.mk file. I was able to build my solution after this.
Example:
APP_PLATFORM := android-22
Today October 2017 TARGET_PLATFORM doesn't work for me.
Cheers.

Related

Android NDK: Module depends on undefined modules: log

I have tried adding APP_ALLOW_MISSING_DEPS := true to application.mk folder.
Still the error persists.
What can be a fix for this?
My Android.mk folder looks like this:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := libMPMWhiskeyCoveNative
LOCAL_MODULE_CLASS := SHARED_LIBRARIES
LOCAL_MODULE_TAGS := optional
LOCAL_SRC_FILES := WhiskeyCoveNative.c
LOCAL_LDLIBS += -llog
LOCAL_SHARED_LIBRARIES := liblog
LOCAL_PROPRIETARY_MODULE := true
include $(BUILD_SHARED_LIBRARY)
Most likely, you have picked up a project that was prepared for an old version of NDK. Please find log in your Android.mk script, it should be reffered to as
LOCAL_LDLIBS += -llog
The line
LOCAL_SHARED_LIBRARIES := liblog
should be removed, it's a leftover from AOSP build.

NDK cannot locate symbol "_Znwj"

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?

Android-NDK: incompatible target while linking ZeroMQ static library into a shared library

I have successfully compiled multiple static libraries with the ndk toolchain and linked them into my own project. I have to use many cpp files and they need protocol buffers and a ZeroMQ, as a library, to compile successfully. Linking against protocol buffers works great, however, when I link against the ZeroMQ I get the following error:
C:/Users/x/ndk/toolchains/arm-linux-androideabi-4.9/prebuilt/windows- x86_64/bin/../lib/gcc/arm-linux-androideabi/4.9/../../../../arm-linux- androideabi/bin/ld.exe: error: ./zmq/lib/libzmq.a(libzmq
_la-zmq.o): incompatible target
collect2.exe: error: ld returned 1 exit status
make.exe: *** [C:/Users/x/Workspace/y/app/src/main//obj/local/armeabi- v7a/libZ.so] Error 1
I have replaced personal information with x, y, z for a clear reason.
I'm using Windows 8.1 with Android Studio 1.1 RC1 and NDK10d. I compiled the libraries on a Ubuntu and a Debian system (tried different ones). Both use the same arm toolchain.
To compile ZeroMQ I followed the steps from the official page. I tried zeromq3-x and zeromq4-x. I tried the mentioned ndk8 and the new ndk10d.
My Application.mk:
APP_STL := gnustl_static #tried: c++_static/shared stlport_static/shared
APP_PLATFORM := android-21
APP_USE_CPP0X := true #tried to omit
APP_CXXFLAGS := -std=gnu++11
APP_CPPFLAGS := -frtti -fexceptions --std=c++11
APP_ABI := armeabi-v7a #tried different like armeabi, all, x86 - obviously only arm should work
NDK_TOOLCHAIN_VERSION := 4.9
Android.mk without important files to compile because it will crash on the first need of zmq:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := ../jni/protobuf
LOCAL_SRC_FILES := ../jni/protobuf/libprotobuf.a
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/include
LOCAL_EXPORT_C_INCLUDES := C:\Users\x\Android\Proto\.lib arm 5 2.6\protobuf-2.6.0\build\include
LOCAL_EXPORT_C_INCLUDES := C:\Users\x\Android\Proto\.lib arm 5 2.6\protobuf- 2.6.0\build\include\google
LOCAL_EXPORT_C_INCLUDES := C:\Users\x\Android\Proto\.lib arm 5 2.6\protobuf- 2.6.0\build\include\google\proto
LOCAL_C_INCLUDES := C:\Users\x\Android\Proto\.lib arm 5 2.6\protobuf- 2.6.0\build\include
LOCAL_C_INCLUDES := C:\Users\x\Android\Proto\.lib arm 5 2.6\protobuf-2.6.0\build\include\google
LOCAL_C_INCLUDES := C:\Users\x\Android\Proto\.lib arm 5 2.6\protobuf-2.6.0\build\include\google\protobuf
include $(PREBUILT_STATIC_LIBRARY)
LOCAL_MODULE := zmq
LOCAL_SRC_FILES := zmq/lib/libzmq.a
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/include
LOCAL_EXPORT_C_INCLUDES := C:\Users\x\Android\ZMQ\ARM-FINAL\include
LOCAL_EXPORT_C_INCLUDES := zmq/include
LOCAL_C_INCLUDES := C:\Users\x\Android\ZMQ\ARM-FINAL\include
LOCAL_C_INCLUDES := zmq/include
include $(PREBUILT_STATIC_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := Z
LOCAL_CFLAGS := -I/zmq -std=c++11
LOCAL_CPPFLAGS := -I/zmq -std=c++11
LOCAL_CPP_FEATURES += exceptions
LOCAL_LDLIBS := -lGLESv1_CM -ldl -llog
LOCAL_CPP_EXTENSION := .cxx .cpp .cc .h
LOCAL_DISABLE_FORMAT_STRING_CHECKS := true
LOCAL_SRC_FILES := \
../jni/protogen/applications.pb.cc \ # this will work
common/bytearray.cpp \ # this will fail
LOCAL_ALLOW_UNDEFINED_SYMBOLS := true
LOCAL_C_INCLUDES += C:\Users\x\Android-MasterUI\app\src\main\jni
LOCAL_C_INCLUDES += ../jni/protogen
LOCAL_C_INCLUDES += common
LOCAL_C_INCLUDES += C:\Users\x\Android\ZMQ\ARM-FINAL\include
LOCAL_C_INCLUDES += C:\Users\x\Workspace\\app\src\main\jni\protobuf
LOCAL_C_INCLUDES += C:\Users\x\Workspace\Android- MasterUI\app\src\main\jni\protobuf\include
LOCAL_C_INCLUDES += C:\Users\x\Android- MasterUI\app\src\main\jni\protobuf\include\google
LOCAL_C_INCLUDES += C:\Users\x\Android\Proto\.lib arm 5 2.6\protobuf-2.6.0\build\include
LOCAL_C_INCLUDES += C:\Users\x\Android\Proto\.lib arm 5 2.6\protobuf- 2.6.0\build\include\google
LOCAL_C_INCLUDES += C:\Users\x\Android\Proto\.lib arm 5 2.6\protobuf-2.6.0\build\include\google\protobuf
LOCAL_STATIC_LIBRARIES := zmq protobuf
include $(BUILD_SHARED_LIBRARY)
The objdump from the static library looks like this
libzmq_la-address.o: file format elf64-x86-64
architecture: i386:x86-64, flags 0x00000011:
HAS_RELOC, HAS_SYMS
start address 0x0000000000000000
I will omit the further ones because they are all the same. There was a better way to dump all the pieces of information with more details about the architecture, but I can not find it anymore.
If you know a better way you may tell me and I will add more information.
Any idea is welcome and appreciated...

ndk-build gstreamer android tutorial: cannot find -lrt

I am following the tutorial at
http://docs.gstreamer.com/display/GstSDK/Installing+for+Android+development
I would like to use ndk-build to build the example.
When I use "ndk-build", there is an error message.
Here are the output messages:
GStreamer : [GEN] => gst-build/gstreamer_android.c
GStreamer : [COMPILE] => gst-build/gstreamer_android.c
GStreamer : [LINK] => gst-build/libgstreamer_android.so
/home/quanta/tools/android-ndk-r9d/toolchains/arm-linux-androideabi-
4.6/prebuilt/linux-x86/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld.gold: error: cannot find -lrt
collect2: ld returned 1 exit status
make: *** [buildsharedlibrary] Error 1
I use ndk-r9d in ubuntu linux 64bit 12.04
Many thanks for any suggestion.
Add Android.mk
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := tutorial-1
LOCAL_SRC_FILES := tutorial-1.c
LOCAL_SHARED_LIBRARIES := gstreamer_android
LOCAL_LDLIBS := -llog
include $(BUILD_SHARED_LIBRARY)
ifndef GSTREAMER_SDK_ROOT
ifndef GSTREAMER_SDK_ROOT_ANDROID
$(error GSTREAMER_SDK_ROOT_ANDROID is not defined!)
endif
GSTREAMER_SDK_ROOT := $(GSTREAMER_SDK_ROOT_ANDROID)
endif
GSTREAMER_NDK_BUILD_PATH := $(GSTREAMER_SDK_ROOT)/share/gst-android/ndk- build/
GSTREAMER_PLUGINS := coreelements
include $(GSTREAMER_NDK_BUILD_PATH)/gstreamer.mk
LOCAL_LDLIBS := -llog
to
LOCAL_LDLIBS := -llog -landroid
Android doesn't have a librt. It's all in libc.
Presumably include $(GSTREAMER_NDK_BUILD_PATH)/gstreamer.mk is adding -lrt to ldlibs.

Android NDK linking, "undefined reference" When linking with a Static Lib

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...

Categories

Resources