Android: How to properly link my own static libraries?

I have an Android project written in C ++ and I have a problem with the binding phase. The code is placed in some static libraries that must be linked.

I found many questions and answers online on this topic, and most of them suggest putting my libraries in LOCAL_STATIC_LIBRARIES in the Android.mk file. But, if I do this, I find that the contents of LOCAL_STATIC_LIBRARIES simply ignored: my libraries are not linked, and adding any dummy text here does not cause any error or warning messages.

I tried this as follows:

 LOCAL_STATIC_LIBRARIES := MyLib.a 

or with the full path:

 LOCAL_STATIC_LIBRARIES := $(LOCAL_PATH)/MyLib.a 

none of them worked.

If I put my static libraries in LOCAL_LDLIBS , then it will be linked, but I got a warning about non-system libraries, and probably the build will be wrong.

The contents of my Android.mk file:

 LOCAL_LDLIBS := $(LOCAL_PATH)/MyLib.a ... 

and I got this message:

 Android NDK: WARNING:jni/Android.mk:myapp: non-system libraries in linker flags: jni/MyLib.a 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 

I could not find how to use LOCAL_STATIC_LIBRARIES , please help me!

I have android-ndk-r9 and android-sdk_r22.2.1 on OpenSuSE x86 and using target = android-18

+6
source share
2 answers

See the JBL answer here .

The variable LOCAL_STATIC_LIBRARIES does not work. First you need a section that defines the library that you want to include:

 include $(CLEAR_VARS) LOCAL_PATH = . LOCAL_MODULE := curl LOCAL_EXPORT_C_INCLUDES := ../curl/include LOCAL_SRC_FILES := ../curl/lib/libcurl.a include $(PREBUILT_STATIC_LIBRARY) 

THEN, you can enable it using

 include $(CLEAR_VARS) LOCAL_MODULE = mylib CFLAGS = ... ... LOCAL_STATIC_LIBRARIES = curl include $(BUILD_STATIC_LIBRARY) 
+5
source

Most likely the problem is that you are providing a library extension:

 LOCAL_STATIC_LIBRARIES := MyLib.a 

I think it should be written as:

 LOCAL_STATIC_LIBRARIES := MyLib 
+1
source

Source: https://habr.com/ru/post/955305/


All Articles