Non-system libraries in linker flags: -lopencv_java3 - android

In the android.mk file I want to include the OpenCV3 library. so the file looks like this:
android.mk
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_EXPORT_C_INCLUDES := D:\path to\OpenCV-android-sdk\sdk\native\jni\include
include D:\path to\OpenCV-android-sdk\sdk\native\jni\OpenCV.mk
LOCAL_MODULE := MyLib
LOCAL_SRC_FILES := file1.cpp
LOCAL_SRC_FILES += file2.cpp
OPENGLES_LIB := -lGLESv1_CM
OPENGLES_DEF := -DUSE_OPENGL_ES_1_1
LOCAL_LDLIBS += -lGLESv1_CM -ldl -llog
include $(BUILD_SHARED_LIBRARY)
But when I build the project, I got this warning message:
Android NDK: WARNING:jni/Android.mk:MyLib: non-system libraries in linker flags: -lopencv_java3
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
How can I solve this issue ?

If you only use OpenCV from your C++ code, you don't need this libopencv_java.so. To indicate this, add
OPENCV_LIB_TYPE=STATIC
Before including OpenCV.mk.
Some explanations can be found at answers.opencv.org.

Try using LOCAL_STATIC_LIBRARIES or LOCAL_SHARED_LIBRARIES instead to list the library dependencies of the current module
Depending on which version you have (static/dylibs), change your LOCAL_LDLIBS to either LOCAL_STATIC_LIBRARIES or LOCAL_SHARED_LIBRARIES
Android.mk is a good reference to variables in the Android makefile

Related

cannot find -libsubstrate-dvm -libsubstrate

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.

Android NDK: Directive not visible to includes of static library

I simply want use a static library for an NDK project. The library works with build systems like automake, but in Android.mk I have a problem with the source files. For some reason, directives don't work over different header files and I get the following error:
error: 'myname' does not name a type
It seems that the directive defined in file1.hpp is not visible in file2.hpp which includes file1.hpp (as I said, this problem does not occur with other build systems like automake.
What am I doing wrong here?
Android.mk:
include $(CLEAR_VARS)
LOCAL_MODULE := libstat
LOCAL_LDLIBS := -lm
LOCAL_SRC_FILES := /home/dir/libstat.a
LOCAL_EXPORT_C_INCLUDES := /home/dir/src
include $(PREBUILT_STATIC_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := hello-jni
LOCAL_CFLAGS := -lm -ldl /home/dir/src
LOCAL_LDFLAGS := -L/home/dir/
LOCAL_C_INCLUDES += /home/dir/src
LOCAL_SRC_FILES := hello-jni.cpp
LOCAL_LDLIBS := -ggdb
LOCAL_STATIC_LIBRARIES := libstat
include $(BUILD_SHARED_LIBRARY)
src includes all header and source files. Any hint would be appreciated.

ADT tool chain not producing output for static libraries

Trying to build a static NDK library using Android's ADT Eclipse tool chain. However, whenever I build with BUILD_STATIC_LIBRARY, no output is produced: I get the message
make: Nothing to be done for `all'."
Any recommendations?
LOCAL_PATH := $(call my-dir)
STL_PATH := "C:/Android/ndk/sources/cxx-stl/gnu-libstdc++/4.6/include"
PLATFORM_INCLUDE := "C:/Android/ndk/sources/cxx-stl/gnu-libstdc++/4.6/libs/armeabi/include"
APP_STL := gnustl_static
include $(CLEAR_VARS)
LOCAL_MODULE := libCore
LOCAL_CPPFLAGS += -std=c++11 -fexceptions -D_OS_ANDROID
LOCAL_LDLIBS := -lGLESv2 -lEGL -lstdc++
LOCAL_C_INCLUDES += $(LOCAL_PATH)/Headers
...
LOCAL_SRC_FILES += Source/Engine/Game.cpp
...
include $(BUILD_STATIC_LIBRARY)
Here is the content of Android.mk file of two-libs sample project from Android NDK.
LOCAL_PATH:= $(call my-dir)
# first lib, which will be built statically
#
include $(CLEAR_VARS)
LOCAL_MODULE := libtwolib-first
LOCAL_SRC_FILES := first.c
include $(BUILD_STATIC_LIBRARY)
# second lib, which will depend on and include the first one
#
include $(CLEAR_VARS)
LOCAL_MODULE := libtwolib-second
LOCAL_SRC_FILES := second.c
LOCAL_STATIC_LIBRARIES := libtwolib-first
include $(BUILD_SHARED_LIBRARY)
You may try building the static library as part of another shared library as shown in the example.
I just did a ndk-build on the two-libs sample project and i could see the .a file along with .so in obj\local\armeabi directory.
Edit:
By default, ndk-build will only build shared libraries and executables, and the modules they depend on. To force a build specify libCore in APP_MODULES as follows.
APP_MODULES := libCore
or in command line as
ndk-build APP_MODULES=libCore

Build shared library linking to other not standard shared libarary

I have some two shared libraries and header for them.
I want to build third shared library using functions from previous two libs.
Have problem with makefile i think. When i try to build receive this:
Android NDK: /cygdrive/d/.../jni/Android.mk: Cannot find module with tag 'shared1' in import path
Android NDK: Are you sure your NDK_MODULE_PATH variable is properly defined ?
Android NDK: The following directories were searched:
Android NDK:
/cygdrive/d/.../jni/Android.mk:36: *** Android NDK: Aborting. . Stop.
structure of my project:
jni/
- myfile.c
- Android.mk
jni/dec/
- lot of header files
jni/enc/
- lot of header files
libs/armeabi/
- shared1.so
- shared2.so
also Android.mk sourse:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_C_INCLUDES := \
$(LOCAL_PATH)/dec \
$(LOCAL_PATH)/enc
LOCAL_SHARED_LIBRARIES := shared1 shared2
LOCAL_MODULE := mylib
LOCAL_SRC_FILES := myfile.c
LOCAL_LDLIBS += -lOpenSLES
LOCAL_LDLIBS += -llog
LOCAL_LDLIBS += -landroid
include $(BUILD_SHARED_LIBRARY)
$(call import-module, shared1)
$(call import-module, shared2)
Take a look to this question: Android JNI APK Packing
You need to give another name for libs/armeabi/ folder to avoid conflicts with NDK build and add the following code before the include $(CLEAR_VARS) statement:
include $(CLEAR_VARS)
LOCAL_MODULE:=shared1
LOCAL_SRC_FILES:=3rdparty_libs/shared1.so
include $(PREBUILT_SHARED_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE:=shared2
LOCAL_SRC_FILES:=3rdparty_libs/shared2.so
include $(PREBUILT_SHARED_LIBRARY)
As I understand it, the correct method is to use ndk-build and not invoking the compiler directly.
In Android.mk you need to specify a module for each static library you want to compile, and then specify that your shared library should use it.
Example of a modified Android.mk file of the hello-jni sample project:
LOCAL_PATH := $(call my-dir)
# Define vars for library that will be build statically.
include $(CLEAR_VARS)
LOCAL_MODULE := <module_name>
LOCAL_C_INCLUDES := <header_files_path>
LOCAL_SRC_FILES := <list_of_src_files>
# Optional compiler flags.
LOCAL_LDLIBS = -lz -lm
LOCAL_CFLAGS = -Wall -pedantic -std=c99 -g
include $(BUILD_STATIC_LIBRARY)
# First lib, which will be built statically.
include $(CLEAR_VARS)
LOCAL_MODULE := hello-jni
LOCAL_STATIC_LIBRARIES := <module_name>
LOCAL_C_INCLUDES := <header_files_path>
LOCAL_SRC_FILES := hello-jni.c
include $(BUILD_SHARED_LIBRARY)
If you want control over which modules to compile when you run ndk-build you can create create a Application.mk file (in the same directory as Android.mk) and list all the modules as in the following example:
APP_MODULES := <module_name_1> <module_name_2> ... <module_name_n>
I think it Helps you

Add shared lib.so to android project

I have an Android project using some native functions. Native functions are using some functions from external shared library "external_lib.so"
I've added to Android.mk: "-lexternal_lib -L/path/to/external/lib" line and myjni.so have been linked successfully. But during runtime myjni.so loading error occurred. The size of myjni.so reflects that external_lib.so is not included. How to fix the problem?
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := myjni
LOCAL_SRC_FILES := myjni.c
LOCAL_LDLIBS := -ldl -llog -lz -lexternal_lib -L/path/to/external/lib
include $(BUILD_SHARED_LIBRARY)
is the .so a third party prebuilt shared library?
if so, in your Android.mk, you need to have:
...
LOCAL_SHARED_LIBRARY := curl
...
LOCAL_LDLIBS += -L$(ANDROID_LIBCURL_LIB_PATH) -lcurl
LOCAL_SHARED_LIBRARIES := curl
include $(BUILD_SHARED_LIBRARY)

Categories

Resources