I'm attempting to load the libjnigraphics.so prebuilt library to my project, however when I deploy the application, I am receiving this error:
06-17 22:35:28.741: INFO/dalvikvm(298): Unable to dlopen(/data/data/com.foo/lib/libndkfoo.so): Cannot load library: link_image[1721]: 29 could not load needed library 'libjnigraphics.so' for 'libndkfoo.so' (load_library[1051]: Library 'libjnigraphics.so' not found)
It compiles perfectly, fine.
Here's my Android.mk as well:
LOCAL_PATH := $(call my-dir)
# Add prebuilt libjnigraphics
include $(CLEAR_VARS)
LOCAL_MODULE := libjnigraphics
LOCAL_SRC_FILES := libjnigraphics.so
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/include
include $(PREBUILT_SHARED_LIBRARY)
include $(CLEAR_VARS)
# Here we give our module name and source file(s)
LOCAL_MODULE := ndkfoo
LOCAL_SRC_FILES := ndkfoo.c
LOCAL_SHARED_LIBRARY := libjnigraphics
#LOCAL_LDLIBS += -libjnigraphics
LOCAL_LDLIBS += -llog
include $(BUILD_SHARED_LIBRARY)
Is there a special place I need to put the libjnigraphics.so? Right now I have it in the jni folder, however I've tried it in multiple other places and it still fails. Any help?
The device has to be running Foyo (Android 2.2, target platform android-8) to be able to use libjnigraphics.so. It doesn't matter what is in your SDK or project directories, this library is part of the device's system libraries.
You can compile your code using the NDK with android-8, but then it will give link-time errors when you side-load the apk and your device happens to be running 2.1 or earlier.
There's this SO question with a workaround, but it shouldn't be relied upon and will crash on some devices. Here's a post on the android-ndk group explaining the issues.
just try these changes:
LOCAL_PATH := $(call my-dir)
# Add prebuilt libjnigraphics
include $(CLEAR_VARS)
LOCAL_MODULE := graphics-prebuilt
LOCAL_SRC_FILES := libjnigraphics.so
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/include
include $(PREBUILT_SHARED_LIBRARY)
include $(CLEAR_VARS)
# Here we give our module name and source file(s)
LOCAL_MODULE := ndkfoo
LOCAL_SRC_FILES := ndkfoo.c
LOCAL_SHARED_LIBRARY := graphics-prebuilt
LOCAL_LDLIBS += -llog
include $(BUILD_SHARED_LIBRARY)
Related
I'm using ndk-build to build a set of shared library(.so) for my android project. I configured and made the source code of C++ library(gdal-2.2.2).
everything was ok.("./configure & make & make install" was successful).
So i created my jni folder like this documentation.
but when I'm trying to use ndk-build on windows, I get a lot of error like "Undefined refrence to somthing".
I've spent a lot of time on this project. Is there someone to help me?
Thanks.
Update
I used configure like this on ubuntu 16.04:
./configure --prefix=/home/mahdi/Desktop/build/ --with-spatialite=yes --with-spatialite-soname=libspatialite.so --host=i686-linux-android CXXFLAGS="-D_GLIBCXX_USE_CXX11_ABI=0" LIBS="-lsupc++ -lstdc++"
After make & make install step I created JNI. this is my directory.
jniwrap
jni
gdal
Android.mk
Application.mk
gdal_wrap.cpp
gdalconst_wrap.c
gnm_wrap.cpp
libgdal.a
ogr_wrap.cpp
osr_wrap.cpp
Android.mk
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := gdal
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/gdal/include
LOCAL_SRC_FILES := libgdal.a
LOCAL_EXPORT_LDLIBS := -lz
include $(PREBUILT_STATIC_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := gdaljni
LOCAL_SRC_FILES := gdal_wrap.cpp
LOCAL_STATIC_LIBRARIES := gdal
include $(BUILD_SHARED_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := gdalconstjni
LOCAL_SRC_FILES := gdalconst_wrap.c
LOCAL_STATIC_LIBRARIES := gdal
include $(BUILD_SHARED_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := ogrjni
LOCAL_SRC_FILES := ogr_wrap.cpp
LOCAL_STATIC_LIBRARIES := gdal
include $(BUILD_SHARED_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := osrjni
LOCAL_SRC_FILES := osr_wrap.cpp
LOCAL_STATIC_LIBRARIES := gdal
include $(BUILD_SHARED_LIBRARY)
Aplication.mk
APP_STL := gnustl_shared
APP_CFLAGS := Android.mk
APP_ABI := x86
APP_PLATFORM := android-14
Then I used android-ndk-r16b in windows-x86_64 but I faced with these errors like this picture:
There was a lot of "undefined reference error" that i can't show here.
Note: for making gdal Java Binding I used swig and jdk7 on my ubuntu 16.04.
When you build libgdal.a on your ubuntu machine, you must have sqlite3, which resolves #include "sqlite3.h".
These include files are enough for a static library, but to create libgdaljni.so you also need libsqlite3.a. You can cross-compile it for Android it yourself on the same ubuntu machine, but it is probably OK to get prebuilt library e.g. from https://github.com/couchbase/couchbase-lite-java-native/tree/master/vendor/sqlite/libs/android.
Copy this file (for appropriate ABI) to the same directory, and modify your Android.mk accordingly:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := sqlite3
LOCAL_SRC_FILES := libsqlite3.a
include $(PREBUILT_STATIC_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := gdal
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/gdal/include
LOCAL_SRC_FILES := libgdal.a
LOCAL_EXPORT_LDLIBS := -lz
LOCAL_STATIC_LIBRARIES := sqlite3
include $(PREBUILT_STATIC_LIBRARY)
*continued without changes*
If you still have "undefined reference error", this could mean that some other libraries should be added.
I am using prebuilt openssl in my project.after loading app is crashing and giving this error
java.lang.UnsatisfiedLinkError: dlopen failed: could not load library "libcrypto.so.1.0.0" needed by "libPrivateSsl.so"; caused by library "libcrypto.so.1.0.0" not found
my android.mk looks like this
LOCAL_PATH := $(call my-dir)
# Prebuilt libssl
include $(CLEAR_VARS)
LOCAL_MODULE := ssl
LOCAL_SRC_FILES := precompiled/libPrivateSsl.so
include $(PREBUILT_SHARED_LIBRARY)
# Prebuilt libcrypto
include $(CLEAR_VARS)
LOCAL_MODULE := crypto
LOCAL_SRC_FILES := precompiled/libPrivateCrypto.so
include $(PREBUILT_SHARED_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := myLibrary
TARGET_PLATFORM := android-3
LOCAL_SRC_FILES := native-lib.cpp
LOCAL_C_INCLUDES = $(LOCAL_PATH)/include
LOCAL_LDLIBS := -llog
LOCAL_SHARED_LIBRARIES := ssl crypto
include $(BUILD_SHARED_LIBRARY)
loading library in activity like this
static {
System.loadLibrary("PrivateSsl");
System.loadLibrary("PrivateCrypto");
System.loadLibrary("myLibrary");
}
i am using Kit-kat for testing with Ubuntu System.
please help me to solve this error.
You downloaded some wrong version of OpenSSL for Android, which was not built correctly (similar to this one. Android does not support versioning in SONAMEs.
You can find a better prebuilt version of OpenSSL, but this is not recommended. For these libraries to be entrusted with your secret communications, you should better make sure that you yourself build it from a trusted (official) source, and it does not leak your private information to some rogue third party.
As a minimal fix, you can try to use the patchelf utility to fix the SONAME in your library.
i solved this issue by making some little changes in android.mk file
i removed .so files and placed .a files.
my android.mk looks like this now
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := ssl_static
LOCAL_SRC_FILES := precompiled/libssl.a
include $(PREBUILT_STATIC_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := crypto_static
LOCAL_SRC_FILES :=precompiled/libcrypto.a
include $(PREBUILT_STATIC_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := myLibrary
LOCAL_SRC_FILES := native-lib.cpp
LOCAL_C_INCLUDES = $(LOCAL_PATH)/include
LOCAL_LDLIBS := -llog
LOCAL_STATIC_LIBRARIES := ssl_static crypto_static
include $(BUILD_SHARED_LIBRARY)
got this idea from here
link
I got a problem in android.mk.It always show me that cannot find -lsubstrate-dvm and -lsubstrate. I don't know what it is? Could someone tell me how to solve this problem ? Here is the logcat:
Android NDK:non-system libraries in linker flags: -libsubstrate-dvm -libsubstrate
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
cannot find -libsubstrate-dvm
cannot find -libsubstrate
Here is the android.mk
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := substrate
LOCAL_SRC_FILES := libsubstrate.so
include $(PREBUILT_SHARED_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := substrate-dvm
LOCAL_SRC_FILES := libsubstrate-dvm.so
include $(PREBUILT_SHARED_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := cydiasubstrate.cy
LOCAL_SRC_FILES := cydiasubstrate.cy.cpp
LOCAL_LDLIBS := -llog -L$(LOCAL_PATH) -lsubstrate-dvm -lsubstrate -lz
LOCAL_ARM_MODE := arm
APP_ALLOW_MISSING_DEPS=true
include $(BUILD_SHARED_LIBRARY)
please help me to fix this issue.
substrate-dvm is the name of the module being built, it relies on a prebuild library, not on sources, so you should look for libsubstrate-dvm.so
You could follow the following link for further help:
https://blog.gdssecurity.com/labs/2014/12/16/hooking-non-public-methods-with-the-ndk-using-mobile-substra.html
to include the Substrate libraries. The easiest way to
do this is to navigate to the ‘/sdk/extras/saurikit/cydia_substrate/’
directory and copy ‘substrate.h’ and navigate to the
‘/sdk/extras/saurikit/cydia_substrate/lib//’ directory and copy
‘libsubstrate-dvm.so’ file into the jni folder of the project.
I am trying to compile a ndk module for my android app with a Shared Library provided with these drivers:
http://www.extendo-printer.de/fileadmin/user_upload/extendo/Drivers/X-56-Hengstler-Extendo-LinuxDrivers-S684018-R2-V1_01-FINAL-2009JUL15.zip
I can compile fine with the defaults (using Hello JNI example). But when I add my code the my C file which references a .so library I need to work with I get compile errors stating it can not find the methods defined in the library. When I try to include it in Android.mk in LOCAL_SRC_FILES i get warnings when it builds (unsupported file extension) but it builds, but than my native method call fails (java.lang linkage error). Is there a proper way to include a .so and than reference it's functions in your native C code?
current Android.mk
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := x56-jni
LOCAL_LDLIBS := libExoApi.so
LOCAL_SRC_FILES := x56-jni.c
include $(BUILD_SHARED_LIBRARY)
I tried with LOCAL_SHARED_LIBRARIES as well with same build error. I've also tried adding to LOCAL_SRC_FILES as stated above (LOCAL_SRC_FILES := x56-jni.c libExoApi.so) with a "," and as well as \ syntax.
Update
I've updated Android.mk to:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := libExoApi
LOCAL_SRC_FILES := libExoApi.so
include $(PREBUILT_SHARED_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := x56-jni
LOCAL_LDLIBS := libExoApi.so
LOCAL_SRC_FILES := x56-jni.c
LOCAL_SHARED_LIBRARIES := libExoApi
include $(BUILD_SHARED_LIBRARY)
This fails at:
[exec] Unable to recognise the format of the input file `/var/folders/_6/6jjydzjs457fnpsc9_5cgl980000gn/T//michael/usbserial-generated/libs/armeabi/libExoApi.so'
I am trying to include static cpp library in android. This library is already compiled(on mac os) and i have its include files.
Here is my Android.mk file
LOCAL_PATH := $(call my-dir)
include $(call all-subdir-makefiles)
include $(CLEAR_VARS)
LOCAL_MODULE:= utils
LOCAL_SRC_FILES:= libUtils.a
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/utils
include $(PREBUILT_STATIC_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := sample
LOCAL_SRC_FILES := sample_cpp.cpp
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)
LOCAL_STATIC_LIBRARIES := utils
LOCAL_LDLIBS := -llog
include $(BUILD_SHARED_LIBRARY)
and here is Application.mk file
APP_STL := stlport_static
APP_CPPFLAGS = -fexceptions
but whenever it try to compile it using NDK i get the error
(Path of file)/libUtils.a: file not recognized: File format not recognized
collect2: ld returned 1 exit status
From the comments and so on it sounds like you trying to use a non arm version of the library. You should build the library with the ndk. The documentation has even documentation on how to do that.
For example building sigc++ could be like (from a project of mine, where sigc++ resides in the sigc++ subdirectory)
# SIGC++ Library built as static library
LOCAL_MODULE := sigc
LOCAL_PATH = $(CURRENT_DIR)
LOCAL_CPP_EXTENSION := .cc
LOCAL_SRC_FILES := sigc++/signal.cc sigc++/signal_base.cc sigc++/trackable.cc
LOCAL_SRC_FILES += sigc++/functors/slot_base.cc sigc++/adaptors/lambda/lambda.cc
LOCAL_SRC_FILES += sigc++/connection.cc sigc++/functors/slot.cc
LOCAL_C_INCLUDES := sigc++
include $(BUILD_STATIC_LIBRARY)
But you should really read how the compiling linking works. I am afraid building for android with ndk is more low level than using Xcode or Msvc.