I am trying to build a shared library using prebuilt static library, the respective Android.mk file is below.
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
#Include kerne headers in a proper way later on
#LOCAL_C_INCLUDES:= $(LOCAL_PATH)/../../../../kernel/include
LOCAL_MODULE := sensors.$(TARGET_BOARD_PLATFORM)
LOCAL_MODULE_TAGS := optional
LOCAL_PRELINK_MODULE := false
LOCAL_MODULE_PATH := $(TARGET_OUT_SHARED_LIBRARIES)/hw
LOCAL_STATIC_LIBRARIES := LibFusion_ARM_cpp
#LOCAL_LDFLAGS := $(LOCAL_PATH)/LibFusion_ARM_cpp.a
LOCAL_SHARED_LIBRARIES := liblog libcutils
#include any shared library dependencies
LOCAL_LDFLAGS := $(LOCAL_PATH)/libimu.a
LOCAL_PRELINK_MODULE := false
LOCAL_SRC_FILES := sensors_u8500.cpp
include $(BUILD_SHARED_LIBRARY)
The files present in the folder is
Android.mk , LibFusion_ARM_cpp.a , libimu.a , MEMSAlgLib_eCompass.h , sensors_u8500.cpp
The error what I am getting while building is below,
**make: *** No rule to make target `out/target/product/u8500/obj/STATIC_LIBRARIES/LibFusion_ARM_cpp_intermediates/LibFusion_ARM_cpp.a', needed by `out/target/product/u8500/obj/SHARED_LIBRARIES/sensors.montblanc_intermediates/LINKED/sensors.montblanc.so'. Stop.**
What is the issue here?
Unable to build the shared library. I mean unable to generate libsensor.so file. facing the above mentioned error. ** make: * No rule to make target
It seems that the build system cannot find LibFusion_ARM_cpp.a. AFAIK, you have to first specify a pre-built library module using PREBUILT_STATIC_LIBRARY with LibFusion_ARM_cpp.a set as LOCAL_SRC_FILES and LOCAL_MODULE as LibFusion_ARM_cpp. This will basically copy the specified static library to the default directory the build system searches through for all of the necessary modules.
I did two things to understand the case:
A. In the above shown make file, I added the below so as to ensure that this .a file gets copied into the build.
include $(CLEAR_VARS)
LOCAL_MODULE := LibFusion_ARM
LOCAL_SRC_FILES := LibFusion_ARM_cpp.a
include $(BUILD_STATIC_LIBRARY)
When I build it using mm -n, command I see this strange statement rm -f ... of the LibFusion_ARM.a. Of course the build fails saying it's not able to locate the STATIC LIB.
mkdir -p out/target/product/u8500/obj/STATIC_LIBRARIES/LibFusion_ARM_intermediates/
rm -f out/target/product/u8500/obj/STATIC_LIBRARIES/LibFusion_ARM_intermediates/LibFusion_ARM.a
echo "target StaticLib: LibFusion_ARM (out/target/product/u8500/obj/STATIC_LIBRARIES/LibFusion_ARM_intermediates/LibFusion_ARM.a)"
mkdir -p out/target/product/u8500/obj/SHARED_LIBRARIES/sensors.montblanc_intermediates/LINKED/
.
.
Why does this deletion happens? I am not sure. This is causing the problem. Please provide suggestions.
B. I added the below lines in the make file:
include $(CLEAR_VARS)
LOCAL_MODULE := LibFusion_ARM
LOCAL_SRC_FILES := LibFusion_ARM_cpp.a
include $(PREBUILT_STATIC_LIBRARY)
I see the below error:
make: *** No rule to make target `out/target/product/u8500/obj/STATIC_LIBRARIES/LibFusion_ARM_intermediates/LibFusion_ARM.a', needed by `out/target/product/u8500/obj/SHARED_LIBRARIES/sensors.montblanc_intermediates/LINKED/sensors.montblanc.so'.
Stop.
Clearly in the second case, the file LibFusion_ARM is not getting copied (even obj/STATIC_LIBRARIES/LibFusion_ARM_intermediates directory is not created).
Needless to emphasis, if I manually copy the file LibFusion_ARM_cpp.a as LibFusion_ARM.a then the build goes through.
Related
I am using the Android NDK to build a shared library. I have include a snippet from my Android.mk file that is causing me a few issues.
LOCAL_PATH := $(call my-dir)
..#other module here
..#other module here
include $(CLEAR_VARS)
LOCAL_MODULE := spatialite
LOCAL_C_INCLUDES := ../../../projects/externalappsdk/include
LOCAL_SRC_FILES := sqlite3.c \
spatialite.c
include $(BUILD_SHARED_LIBRARY)
My spatialite.c file includes some header files that are located in a folder that is external to the application project folder. I have included that folder in LOCAL_C_INCLUDES as shown above, but on running ndk-build, it still cannot locate these includes. What is the correct way of allowing the ndk-build command to identify where these includes are located. Any help will be greatly appreaciated.
UPDATE:
I wanted to add that spatialite itself need not be visible to the Java layer. I will thereafter be building another module which uses spatialite. I am not sure if this makes a difference to the way I declare the module on the Android.mk file.
The compiler output is shown below:
jni/spatialite.c:102:20: fatal error: geos_c.h: No such file or directory
#include
The .h file that is being imported in spatialite.c is located at C:/projects/externalappsdk/include. The spatialite.c and Android.mk are located at C:/mobile/myandroidproject/jni/
The include directive within my spatialite.c file is shown below:
#ifndef OMIT_GEOS /* including GEOS */
#include <geos_c.h>
#endif
ANSWER:
I managed to get this working using help from the answers provided by Chris which I have accepted. However, I had to make one change to the Android.mk file as is shown below:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := spatialite
LOCAL_C_INCLUDES := ../../projects/externalappsdk/include
LOCAL_SRC_FILES := sqlite3.c \
spatialite.c
include $(BUILD_SHARED_LIBRARY)
Note, that the LOCAL_C_INCLUDES goes two levels back instead of three.
Without a
LOCAL_PATH := $(call my-dir)
At the top of the Android.mk, I was unable to build a replica of your project as described, however the error was different than your report - without that directive the compiler was searching for the C source files in an NDK system directory rather in the jni/ folder.
$ cd mobile/myandroidproject/jni
$ ndk-build
Compile thumb : spatialite <= spatialite.c
SharedLibrary : libspatialite.so
Install : libspatialite.so => libs/armeabi/libspatialite.so
File: ./mobile/myandroidproject/jni/Android.mk
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := spatialite
LOCAL_C_INCLUDES := ../../../projects/externalappsdk/include
LOCAL_SRC_FILES := sqlite3.c \
spatialite.c
include $(BUILD_SHARED_LIBRARY)
File: ./mobile/myandroidproject/jni/spatialite.c
#include <geos_c.h>
File: ./mobile/myandroidproject/jni/sqlite3.c
//empty file
File: ./projects/externalappsdk/include/geos_c.h
//empty file
At minimum you should add the LOCAL_PATH line to your Android.mk
If that does not solve the problem, then please update your question with any differences between your project structure and my recreation of it.
Use LOCAL_EXPORT_C_INCLUDE_DIRS instead of LOCAL_C_INCLUDES
Good Day everyone. Still trying to figure out what's wrong with adding xml library.(Previos thread Cannot find libxml2 in android ndk project)
In jni folder: i jave prebuild libxml.so, which i successfully builded, android.mk and start-spice.c. Start-spice.c needs libxml in order to work.
Android.mk:
include $(CLEAR_VARS)
LOCAL_MODULE := libxml
LOCAL_SRC_FILES :=libxml.so
include $(PREBUILT_SHARED_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := start-spice
LOCAL_SRC_FILES := start-spice.c
LOCAL_LDLIBS := -lxml
LOCAL_SHARED_LIBRARIES= xml
include $(BUILD_SHARED_LIBRARY)
And still it says that cannot find libxml/parser.h
Maybe someone could tell me what's wrong?
The think is that in .ci use libxml methods from linux and here i downloaded libxml2 and builded it - is there any difference?
Are you remembering to add the .h directories of libxml to the list of include directories for the other modules? I don't see any -I flags or LOCAL_C_INCLUDES being set
I have a problem with an ndk-build script that builds a static library.
The problem is that this script gets included by our application's larger build script, which gets called with ndk-build all
The build script for the static library looks like this:
# LoadBalancing-cpp
LOCAL_PATH := $(call my-dir)
all_static_libraries = common-cpp-static-prebuilt \
photon-cpp-static-prebuilt
lib_suffix := ${APP_OPTIM}_android_${APP_ABI}
lib_loadbalancing_cpp_static_name := loadbalancing-cpp-prebuilt-static_${lib_suffix}
include $(CLEAR_VARS)
LOCAL_MODULE := loadbalancing-cpp-static-prebuilt
LOCAL_SRC_FILES := lib$(lib_loadbalancing_cpp_static_name).a
LOCAL_STATIC_LIBRARIES := $(all_static_libraries)
include $(PREBUILT_STATIC_LIBRARY)
$(call import-module,common-cpp-prebuilt)
$(call import-module,photon-cpp-prebuilt)
The problem is, building a static library requires the LOCAL_SRC_FILES to point to a single value (the path to the library), however when called with ndk-build all in this case, it will contain multiple values (since lib_suffix will point to all available architectures).
Is there a way to build this file using ndk-build all ?
You can use TARGET_ARCH variable which is managed by ndk-build:
lib_suffix := $(APP_OPTIM)_android_$(TARGET_ARCH)
... and so on.
Essentially, ndk-build will "call" your Android.mk file multiple times, each time setting the TARGET_ARCH variable differently.
How can I specify shared libraries to load in the Android.mk when compiling with ndk-build ?
Edit: This is my Android.mk
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := lib-crypto
LOCAL_SRC_FILES := libcrypto.so
include $(PREBUILT_SHARED_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := tema1
LOCAL_SRC_FILES := tema1.c
LOCAL_SHARED_LIBRARIES := lib-crypto
LOCAL_C_INCLUDES := /home/aleksei/openSSL0.9.8/include
include $(BUILD_EXECUTABLE)
libcrypto.so is the library that I have built for android. I want to make a program using it. Now it gives me this error:
Install : libcrypto.so => libs/armeabi/libcrypto.so
Executable : tema1
./obj/local/armeabi/libcrypto.so: undefined reference to `dladdr'
collect2: ld returned 1 exit status
make: *** [obj/local/armeabi/tema1] Error 1
PREBUILT_SHARED_LIBRARY
Points to a build script used to specify a prebuilt shared library.
Unlike BUILD_SHARED_LIBRARY and BUILD_STATIC_LIBRARY, the value
of LOCAL_SRC_FILES must be a single path to a prebuilt shared
library (e.g. foo/libfoo.so), instead of a source file.
You can reference the prebuilt library in another module using
the LOCAL_PREBUILTS variable (see docs/PREBUILTS.html for more
information).
read more from http://source-android.frandroid.com/ndk/docs/ANDROID-MK.html
Show me what you have done till yet and where you facing problem.?
I had the same problem. To fix it, I did the following:
In the same directory as your Android.mk file, create a file named Application.mk
Add the following line of code into Application.mk:
"APP_PLATFORM := android-8"
If you already have an Application.mk file, just add the code in step 2 to the existing file. Now call ndk-build and see if it links. ndk-build may be compiling with an old version of libdl which does not have dladdr(). The code in step 2 will cause ndk-build to use an updated libdl which has dladdr().
I have a shared library libfoo.so and need to use it in my android app.
My first try was to have in Android.mk:
include $(CLEAR_VARS)
LOCAL_MODULE := test
LOCAL_SRC_FILES := test.cpp
LOCAL_LDLIBS := -L$(PATH_TO_FOO) -lfoo
include $(BUILD_SHARED_LIBRARY)
in my activity, I have:
statis
{
System.loadLibrary("foo");
}
This builds correctly, however I noticed that created apk doesnt include libfoo.so (also I see it is not copied to libs/armeabi). I guess for that reason I have UnsatisfiedLinkError when executing my app.
I saw in some other posts that I need to add $(PREBUILD_SHARED_LIBRARY), so I add the following to my Android.mk:
include $(CLEAR_VARS)
LOCAL_MODULE:= foo
LOCAL_SRC_FILES := $(FOO_PATH)/libfoo.so
include $(PREBUILD_SHARED_LIBRARY)
But now I am getting the build error:
foo: LOCAL_SRC_FILES points to a missing file.
I am sure that the path is correct. Note that the libfoo.so was having origionally the version number at the end, though I had to remove it (and leave only .so) since ndk-build complained.
What am I doing wrong?
The include appears to be misspelt:
include $(PREBUILD_SHARED_LIBRARY)
should be
include $(PREBUILT_SHARED_LIBRARY)
Found the solution!! LOCAL_SRC_FILES can not have absolute or relative paths, just the filename. The path must be set in LOCAL_PATH.
So in my case, instead of:
LOCAL_SRC_FILES := $(FOO_PATH)/libfoo.so
I have now:
LOCAL_PATH := $(FOO_PATH)
LOCAL_SRC_FILES := libfoo.so
And this works ok.
In eclipse, i add a static library by copying the file in the path project/libs/armeabi/ and rebuild the project after cleaning it. This includes the .so in the apk.