Adding libxml support to android ndk project - android

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

Related

Develop/Compile a lib for an android project

I have some cpp files in a directory (10 cpp files and ten relatives .h files corresponding to 10 classes).
I would like to create my own library with them (let call it libTest.a) in order to put it on an android project using NDK.
I have already :
C++ code
Create and configure the android project with NDK, so basically I have an Android.mk and a cpp file into the jni folder
I spent about 10 hours on the web trying to find someone who can explain how to compile its own lib.a
I found a lot about "how can I put a .a in an android project using ndk" but nothing about how to create a makefile, a config file or whatever in order to correctly compile and make a lib compatible with android.
The one who will give me some advices will made my day!
Thanks a lot
(My Android.mk below)
LOCAL_PATH := $(call my-dir)
# static library info
LOCAL_MODULE := libTest
LOCAL_SRC_FILES := ../prebuild/libTest.a
LOCAL_EXPORT_C_INCLUDES := ../prebuild/include
include $(PREBUILT_STATIC_LIBRARY)
include $(CLEAR_VARS)
LOCAL_C_INCLUDES += ../prebuild/include
LOCAL_MODULE := mlaudioengine
LOCAL_SRC_FILES := mlaudioengine.cpp
LOCAL_STATIC_LIBRARIES := libTest
include $(BUILD_SHARED_LIBRARY)

Android makefile can't find libs because of extra LOCAL_PATH in path

So I've been scratching my head for quite some time with this: basically, I have two Android makefile, one in my jni folder, and one in another folder that contains my native c++ code.
Thing is, for the following makefile,
LOCAL_PATH := $(call my-dir)
GENERATED_PATH := $(LOCAL_PATH)/../../generated/release/api/Android
############################ Includes ############################
#------------------------------------------------------------------ Assimp
LOCAL_MODULE := Assimp
LOCAL_EXPORT_C_INCLUDES := $(GENERATED_PATH)/assimp/include
LOCAL_SRC_FILES := $(GENERATED_PATH)/assimp/lib/libassimp.a
include $(PREBUILT_STATIC_LIBRARY)
# More Libraries included....
#....
I get the following error:
Android NDK: ERROR:jni/../../../appCommon/Android.mk:Assimp: LOCAL_SRC_FILES points to a missing file
Android NDK: Check that jni/../../../appCommon/jni/../../../appCommon/../../generated/release/api/Android/assimp/lib/libassimp.a exists or that its path is correct
What bugs me is that there's twice the LOCAL_PATH in the path where the ndk searches for the library. I've already read about a few cases like this one (like using the notdir macro) but couldn't find a satisfying solution.
How can I specify correctly (and not manually) the correct directory ?
So it turns out that the problem stems from the PREBUILT_STATIC_LIBRARY script, which looks for the lib in the following path: $(LOCAL_PATH)/$(LOCAL_SRC_FILES)
Thus, a simple workaround that worked is to have separate variables for the directories, like that:
GENERATED_PATH := ../../generated/release/api/Android
GENERATED_INCLUDE_PATH := $(LOCAL_PATH)/$(GENERATED_PATH)
and then use them like that:
LOCAL_MODULE := Assimp
LOCAL_EXPORT_C_INCLUDES := $(GENERATED_INCLUDE_PATH)/assimp/include
LOCAL_SRC_FILES := $(GENERATED_PATH)/assimp/lib/libassimp.a
include $(PREBUILT_STATIC_LIBRARY)

NDK: using user created .so when trying to build another .so

I'm trying to link some .so that I generated using the NDK to a new .so I'm trying to create,
as the old .so contains definitions of functions that I want to use in the new .so.
I've tried this Android.mk :
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := prog_test
LOCAL_SRC_FILES := main.c
LOCAL_MODULE_TAGS := optional
LOCAL_SHARED_LIBRARIES += mylib
include $(BUILD_SHARED_LIBRARY)
$(call import-module,<tag>) # with and without
I've also tried this method I found in stackoverflow NDK - How to use a generated .so library in another project but still no succes as I get always :
prebuilt/linux-x86/toolchain/arm-linux-androideabi-4.4.x/bin/../lib/gcc/arm-linux-androideabi/4.4.3/../../../../arm-linux-androideabi/bin/ld: error: cannot find -lmylib.so
I really appreciate any help to solve this issue.
B.R
you have to use include $(PREBUILD_SHARED_LIBRARY) instead of include $(BUILD_SHARED_LIBRARY)

Android NDK linking problems

I compiled Sox et al with NDK. So, I have all Android-friendly shared libs.
I made a simple test file which calls a sox function.
NDK build tells me:
undefined reference to `sox_open_read'
sox_open_read is defined in sox.h. I know it's finding sox.h because it gives me a warning about that file:
In file included from (...)/sox/sox.h:19
So maybe it wants to find sox_open_read in the actual libsox.so. Well, I've tried about a 100 different ways to tell it where the sox shared lib is e.g.
LOCAL_SHARED_LIBRARY := sox
LOCAL_LDLIBS := -L$(LOCAL_PATH_FULL)/jni/libs/libsox.so
However, It will work if I specify Sox as a static library:
#LOCAL_SHARED_LIBRARY := sox
LOCAL_STATIC_LIBRARIES := sox
LOCAL_LDLIBS := -L$(LOCAL_PATH_FULL)/jni/libs/libsox.so
It's my understanding that I don't want to staticly link to the sox lib - I want to dynamically link to it.
You should define libsox.so as a prebuilt library. Create a makefile as the following and put your prebuilt libsox.so in the same directory with this makefile. After that, you can use libsox same as you've rebuilt it. Don't forget to include this makefile into your build.
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := libsox
LOCAL_SRC_FILES := libsox.so
include $(PREBUILT_SHARED_LIBRARY)

how to include prebuilt shared libraries in apk with eclipse

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.

Categories

Resources