Fatal error, no such file or directory ( eclipse android ) - android

I'm developing a cocos2d-x project, as its universal it works on android and iOS.
I recently added text to speech functionality using flite. In xcode all I do to use flite, is drag in the folder of the headers and c files into my xcode project, and then I can include its headers and use it. No problems there.
However in eclipse I can't get the compiler to see the files, and it keeps bombing out with the fatal error I mentioned. Specifically: fatal error: flite.h no such file or directory.
I've tried to include the folder in the includes section of eclipse under C/C++ general but no luck. I think this may have something to do with my android.mk file, guidance on how to set this up for this purpose would be greatly appreciated. On a side note, my project is set up so that my .cpp and .h files exist elsewhere on my computer and not in my actual project. Likewise for my flite source files. (I did try add them to my project however, out of desperation but the compiler still couldn't find them)
Thanks for your time.
PS: How does one refer to flite, is it a library/framework etc?
Edit
I tried to modify my Android.mk file, to locate the flite headers. My additions are indicated below
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := game_shared
LOCAL_MODULE_FILENAME := libgame
LOCAL_SRC_FILES := hellocpp/main.cpp \
../../Classes/AppDelegate.cpp \
../../Classes/HelloWorldScene.cpp \
../../Classes/CCLabelTTFExtension.cpp \
../../Classes/menuScene.cpp \
../../Classes/text_Parse.cpp \
../../Classes/FileTS.cpp
LOCAL_C_INCLUDES := $(LOCAL_PATH)/../../Classes/
#my addition
LOCAL_C_INCLUDES += $(LOCAL_PATH)/flite/
dirs := $(shell /flite -type d)
cfilestemp1 := $(shell find /src -type d)
cfilestemp2 := $(shell find $(cfilestemp1) -name *.c)
cfilestemp3 := $(sort $(cfilestemp2))
cfiles := $(subst $(LOCAL_PATH)/,,$(cfilestemp3))
LOCAL_SRC_FILES += \
$(cfiles)
#end my addition
LOCAL_WHOLE_STATIC_LIBRARIES := cocos2dx_static cocosdenshion_static cocos_extension_static
include $(BUILD_SHARED_LIBRARY)
$(call import-module,CocosDenshion/android) \
$(call import-module,cocos2dx) \
$(call import-module,extensions)
include $(CLEAR_VARS)
This got me closer, well, gave me different errors. Now the compiler complains of undefined references in my FileTS.cpp file, the file which is using flite in my project. (Note: My flite headers and source files are now added to my project in the jni folder)

The easiest way is to put all the source code into your Classes folder and list the cpp files in LOCAL_SRC_FILES like mainScene.cpp . this will make sure your library get build into your game object files.

Related

How to generate a shared library temporary and pack it into a APK package

I have a android app called "ABC" which needs to pack a jni shared library called "libxxx-jni.so". So the source tree is likes as below:
ABC
+- Android.mk
+- java
+- res
+- jni
+- Android.mk
+- xxx.cpp
The Android.mk of ABC app is:
LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE_TAGS := optional
LOCAL_PACKAGE_NAME := ABC
LOCAL_SRC_FILES := $(call all-java-files-under, java)
LOCAL_RESOURCE_DIR += \
$(LOCAL_PATH)/res
LOCAL_JNI_SHARED_LIBRARIES := libxxx-jni
include $(BUILD_PACKAGE)
# Also build sub-targets under this one: the shared library.
include $(call all-makefiles-under, $(LOCAL_PATH))
And the Android.mk of jni library xxx is:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := libxxx-jni
LOCAL_SRC_FILES := xxx.cpp
LOCAL_SHARED_LIBRARIES := \
libutils \
libcutils
LOCAL_LDLIBS += -llog
LOCAL_C_INCLUDES += \
$(JNI_H_INCLUDE)
include $(BUILD_SHARED_LIBRARY)
I put these source code in android aosp source tree, and use android build environment to build whole system.
My problem is I need to pack the libxxx-jni.so into my Settings apk. Currently, after build completed, I see the libxxx-jni.so is located at /system/lib. In APK's lib sub-folder, I only see a link to the /system/lib/libxxx-jni.c.
That's not my expectation. I want to pack the so in my APK's lib sub-folder, not just a link. And I don't want to the libxxx-jni.so is appeared in /system/lib.
I didn't use IDE (eclipse or android studio), and I only use Android.mk in aosp source tree.
How should I modify these Android.mk to meet my expectation? Thanks.
Add this to Android.mk:
LOCAL_MODULE_TAGS := samples
There's several ways to achieve bundling of JNI .so's in the apk when using AOSP, basically all listed in the build system:
a) make TARGET_BUILD_APPS become true: one way to do this is by building your app via tapas instead of lunch: . build/envsetup.sh; lunch <yourlunchtarget>; m <yourapp> becomes . build/envsetup.sh; tapas <yourapp> [arm|x86|arm64|x86_64] [eng|userdebug|user]; make.
b) set LOCAL_COMPRESSED_MODULE to true.
c) set LOCAL_MODULE_TAGS to samples or tests as noted by huisinro. Not sure about the side effects and if your app is not a sample or a test this feels semantically wrong.

Android NDK - Additional Include Directories

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

Adding libxml support to android ndk project

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

NDK compiling multiple libraries

I am using native code in my android app. Firstly I was only using one library. So everything worked fine. But now I have to integrate one more library into it. I've no idea what should be the ideal structure of the jni folder of my project (as in where to place the entire code, etc.). I found a work around. I created two folders inside jni .i.e library1 and library2. Again created a jni folder inside both the folders and placed respective code in the folders.
I got it to compile. Both .so files are being generated, but I am unable to use it in my application. I cant load the library using System.loadLibrary("library1.so"); Also tried providing full path. But failed
Also I have no idea what to write inside the parent jni folder's Android.mk file.
Current structure:
project_folder -> jni -> library1 -> jni -> "source code" an Android.mk is written here
project_folder -> jni -> library2 -> jni -> "source code" an Android.mk is written here
UPDATE #1 :
Gdbserver : [arm-linux-androideabi-4.6] libs/armeabi/gdbserver
Gdbsetup : libs/armeabi/gdb.setup
make: *** No rule to make target `jni/zap/jni/zap/zap/error.c', needed by `obj/local/armeabi/objs-debug/zap/jni/zap/zap/error.o'. Stop.
I am not using Application.mk.
This is my Android.mk:
TOP_PATH := $(call my-dir)
# Build library 1
include $(CLEAR_VARS)
LOCAL_PATH := $(TOP_PATH)/zap
LOCAL_MODULE := zap
LOCAL_C_INCLUDES := $(LOCAL_PATH)/zap
LOCAL_SRC_FILES := $(LOCAL_PATH)/zap/error.c \
$(LOCAL_PATH)/zap/hello-jni.c \
$(LOCAL_PATH)/zap/zap.c \
$(LOCAL_PATH)/zap/zapd.c \
$(LOCAL_PATH)/zap/zaplib.c
include $(BUILD_SHARED_LIBRARY)
The best structure I've found is to use the jni/ folder for ndk-build makefiles only, and keep the source outside in their own folders. This is easy to add to existing projects without restructuring your tree under jni.
However, you do have to be careful about how you handle the LOCAL_PATH variable and use of $(call my-dir). Here's a working example:
MyProject/
library1/
source1.cpp
library2/
source2.cpp
jni/
Android.mk
Application.mk
Android.mk:
# TOP_PATH refers to the project root dir (MyProject)
TOP_PATH := $(call my-dir)/..
# Build library 1
include $(CLEAR_VARS)
LOCAL_PATH := $(TOP_PATH)/library1
LOCAL_MODULE := library1
LOCAL_C_INCLUDES := $(LOCAL_PATH)
LOCAL_SRC_FILES := source1.cpp
include $(BUILD_SHARED_LIBRARY)
# Build library 2
include $(CLEAR_VARS)
LOCAL_PATH := $(TOP_PATH)/library2
LOCAL_MODULE := library2
LOCAL_C_INCLUDES := $(LOCAL_PATH)
LOCAL_SRC_FILES := source2.cpp
include $(BUILD_SHARED_LIBRARY)
You can optionally split out the sections in Android.mk to their own makefiles.
I discovered that when compiling from the command line, I can include multiple libraries by running android update project twice, once with each library:
android update project -l ../SDK/library1/ --path . --name $name --target 23 --subprojects
android update project -l ../SDK/library2/ --path . --name $name --target 23 --subprojects
ant release

"undefined reference to" (function) & "in archive is not an object" Android ndk-build

I'll expose my problem quickly. I am trying to port curl on Android and to use it within my app. I built the curl library with the ARM toolchain, configured and made (a couple times to make sure I didn't do nothing wrong the first time).
I then proceeded to put the newly created libcurl.a and my curljni.c into my jni folder, as long as the following Android.mk :
LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE:= libcurl
LOCAL_SRC_FILES := libcurl.a
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/include/curl
include $(PREBUILT_STATIC_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := curljni
LOCAL_SRC_FILES := curljni.c
LOCAL_C_INCLUDES := $(LOCAL_PATH)/include/curl
LOCAL_STATIC_LIBRARIES := libcurl
include $(BUILD_SHARED_LIBRARY)
I've been trying a lot of things and I'm pretty sure it looks good now, but whenever I try to build with the ndk-build tool I obtain the following :
Note : curljni.c makes calls to functions within the libcurl library and its easy.h and curl.h files. They are then included in top of the file.
I also tried to ask for the whole library to get loaded into my Android app, using LOCAL_WHOLE_STATIC_LIBRARIES instead of LOCAL_STATIC_LIBRARIES, but without much more success :
Previously :
Downloaded curl.7.28.0
Made a standalone toolchain for ARM 4.6
Fixed several files within curl whose linebreaks were DOS like and needed Unix like (bug in configure) - one of which was depcomp, linked to libcurl_la-file.lo
./configure --host=arm-linux-androidaebi --with-zlib --enable-ipv6
make/make install
Added the resulting libcurl.a from curl\lib.libs
Ok,
Your Problem is that your library libcurl.a is not builded with Android ndk gcc ..
You have done :
$ ./configure --host=arm-linux-androidaebi --with-zlib --enable-ipv6
$ make
$ make install
this will generate a library using your PC gcc ..NOt good .
What i do is to configure open source library l for android using line command (or like you have done):
./configure --build=x86_64-unknown-linux-gnu --host=arm-linux-androideabi --target=arm-linux-androideabi
But then you schould not call make and make install ! .
You have to create an android.mk whinch will compile all source file in your libcurl + your jni file ' curljni.c' and put all in one lib : here an example of Android.mk compiling SQLITE3
###################################################
# SQLITE3
###################################################
include $(CLEAR_VARS)
LOCAL_MODULE := Mysqlite3
MY_LOCAL_SQLITE_SRC := $(LOCAL_PATH)/sqlite/
LOCAL_CPPFLAGS := -g
LOCAL_CPPFLAGS += -I $(MY_LOCAL_SQLITE_SRC)
LOCAL_EXPORT_C_INCLUDES:=$(MY_LOCAL_SQLITE_SRC)
FILE_LIST :=$(wildcard $(MY_LOCAL_SQLITE_SRC)*.c*)
LOCAL_SRC_FILES += $(FILE_LIST:$(LOCAL_PATH)/%=%)
# My SQLITE3 JNI FILE
LOCAL_SRC_FILES +=mysqlite_jni.cpp
# include native NDK library liblog and libz
LOCAL_LDLIBS := -llog -lz
include $(BUILD_SHARED_LIBRARY)

Categories

Resources