Linking gnustl into Android ndk project with stlport_static - android

In my Android.mk and Application.mk , I am using a static library which is build using stlpot_static, but I want to use gnustl instead of stlport to build my project because I need support of c++11 in my project.
Earlier I was using APP_STL := stlport_shared Application.mk in my and my project was running successfully.
But now I want to make it APP_STL := gnustl_shared, the project compiles successfully but it crashes during run time giving me a error java.lang.UnsatisfiedLinkError: dlopen failed: cannot locate symbol "_ZNSt13_Filebuf_base12_M_page_sizeE", when I checked for this error,I found this dependency in my static library which was build using stlport_static.
How can I use gnustl with my project without disturbing my static library which has its dependency on stlport_static.

You can't mix and match STLs in a single binary: https://android.googlesource.com/platform/ndk/+/master/docs/user/common_problems.md#Using-Mismatched-Prebuilt-Libraries

Related

SDL build system - When I link against `gnustl_shared` I get "Error: Cannot load library: ..." at runtime

I'm trying to compile a C++ application for android. I use project for android NDK that comes with SDL library.
When I use APP_STL := gnustl_static it compiles and runs fine, but I need gnustl_shared because my project uses multiple .so files. APP_STL := gnustl_shared gives me following runtime error at emulator:
I followed an advice from similar SO post and added
static {System.loadLibrary("gnustl_shared");}
to the end of SDLActivity.java : class SDLMain, but it had no visible effect.
If it matters, libgnustl_shared.so in all libs/*/ directories.
What do I need to do to fix gnustl_shared?
YEAH, solved.
protected String[] getLibraries() {
return new String[] {
"gnustl_shared", // I've added this line
"SDL2",
"main"
};
}

Android NDK and .so.X extensions

I'm trying to use the Grantlee library in an Android NDK app.
I can compile Grantlee just fine, and I get libGrantlee_Templates.so, libGrantlee_Templates.so.5, and libGrantlee_Templates.so.5.0.0.
Of these three, I can only install the first one in my Android.mk:
include $(CLEAR_VARS)
LOCAL_MODULE := libgrantlee
LOCAL_SRC_FILES := $(GRANTLEE_PATH)/lib/libGrantlee_Templates.so
include $(PREBUILT_SHARED_LIBRARY)
Because if I try to install either of the other two, then I get:
Android NDK: ERROR:Android.mk:grantlee: LOCAL_SRC_FILES should point to a file ending with ".so"
Android NDK: The following file is unsupported: libGrantlee_Templates.so.5
But then, like a cruel joke, the .so.5 that I can't install is exactly the file that it looks for at runtime:
E/AndroidRuntime(14439): java.lang.UnsatisfiedLinkError: dlopen failed: could not load library "libGrantlee_Templates.so.5"; caused by library "libGrantlee_Templates.so.5" not found
How do I solve this?
When you build a native shared library with NDK standalone toolchain, you must change its make files to get rid of .version suffixes. See for example how this is done for ffmpeg.
I had the same problem when using an external library in my project.
You can also add -avoid-version to the libtool command. This trick saved my day...
If the library is built with an autotools/libtool based build system, update the bundled libtool to libtool 2.4.3 or newer. Those versions know how to deal with these details about android shared libraries, so if you build it with --host=arm-linux-androideabi or similar, it won't add any version numbers to the libraries.
To upgrade the libtool version within a source package, run e.g. autogen.sh or a similar script within the source package, or autoreconf -fi, assuming that you've got a new enough version of libtool installed in the surrounding system.

i can't get opencv to work in android

I'm using eclipse to write android programs and i can successfully run them on adt but recently i had to write a program that uses opencv but i can't get opencv to work with android i got ndk and add it to system variables and also downloaded opencv4android sdk from this link: http://docs.opencv.org/doc/tutorials/introduction/android_binary_package/O4A_SDK.html and i imported all the examples now i get numerous error for any of the examples and when i click project->clean->clean all it comes up with following error :
C:\Documentation_Android\android-ndk-r9d-windows-x86_64\android-ndk-r9d\ndk-build.cmd
Android NDK: WARNING:jni/Android.mk:mixed_sample: non-system libraries
in linker flags: -lopencv_java Android NDK: This is likely to
result in incorrect builds. Try using LOCAL_STATIC_LIBRARIES
Android NDK: or LOCAL_SHARED_LIBRARIES instead to list the library
dependencies of the Android NDK: current module
[armeabi-v7a] Install : libmixed_sample.so =>
libs/armeabi-v7a/libmixed_sample.so
I also tried Fix Project Properties but nothing happened and i tried to change jni/Application.mk and change armeabi-v7a to armeabi and that didn't helped too what should i do now ? is there anything I missing here ?
have you added LOCAL_LDLIBS in android.mk file?
LOCAL_LDLIBS := $(LOCAL_PATH)/jniLibs/libmixed_sample.so //path of .so file
OK i found the answer ! How stupid I am ! i just have to go to opencv library project properties in android tab select project build target as android 4.2.2 and everything worked well

android using external shared library

I am facing issues in using an external shared library in my Android application. I created an Android.mk file as given below:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := MyApp
LOCAL_SRC_FILES := myexternallib.so
include $(PREBUILT_SHARED_LIBRARY)
Using ndk-build I am able to generate a local native library and I use this native library in my System.loadLibrary method.
When I run the application I get an error java.lang.UnsatisfiedLinkError: Cannot load library: reloc_library[1486]: 2659 unknown reloc type 19 # ( 4220)
On further search I found a link which recommends to build the shared library using the android toolchain. So I used one of the toolchain arm-eabi-gcc, which is available in the prebuilt/linux_x86/toolchain/arm-eabi-4.4.3/bin directory of the android source code, to build my source files. I get an error arm-eabi-gcc: error trying to exec 'cc1': execvp: No such file or directory. I also noticed that the toolchain folder does not have a file named cc1.
Am I following the right procedure? Is there some other way to reference external shared library in Android code?
It is true that you should use Android toolchain.
Android NDK comes with detailed instructions on using its toolcahin: http://source-android.frandroid.com/ndk/docs/STANDALONE-TOOLCHAIN.html. If you have specific questions about this document, feel free to ask.

Android.mk not linking system library libandroid.so

In my android 2.3 project , i am using the native asset manager. In the docs it says add the
LOCAL_LDLIBS += -landroid to the android.mk file which I have
but the linker is giving the following error saying it can't find it
/android-ndk-r7/toolchains/arm-linux-androideabi-4.4.3/prebuilt/darwin-x86/bin/../lib/gcc/arm-linux-androideabi/4.4.3/../../../../arm-linux-androideabi/bin/ld: cannot find -landroid
I've compiled a sample in the NDK with the same library and that works so I can't understand why a different project is giving this problem
turned out I needed to target a later platform 2.3

Categories

Resources