问题
I am currently having trouble including resources from the NDK manifest file and I am sure that it is a quick fix error. There are plenty of files that are shared between projects and operating systems in a large library. Therefore, in order to keep the files up to date with other projects and keep from updating each individual project with the latest API each time an update occurs, a whole bunch of native header and source code files need to be referenced with relative paths.
Within Eclipse, I have clicked and dragged across the files (without copying them, but by using a relative path) that would be needed by the current application in a local folder structure in the project.
/projectFolder /jni /externalProjectFiles /src /include
With this folder structure within Eclipse I have an Android.mk file with the following structure:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := projectLib
LIBRARY_SRC_FOLDER := $(wildcard $(LOCAL_PATH)/externalProjectFiles/src/*.cpp)
LOCAL_C_INCLUDES := $(LOCAL_PATH)/externalProjectFiles/include
LOCAL_SRC_FILES := projectLibNDK.c
LOCAL_SRC_FILES += $(LIBRARY_SRC_FOLDER:$(LOCAL_PATH)/%=%)
LOCAL_LDLIBS := -L$(SYSROOT)/usr/lib -llog -landroid
LOCAL_CFLAGS := -Wno-multichar -D_ANDROID -DLIBDIR="\"c\""
LOCAL_CFLAGS += -DUSE_TCP_LOOPBACK -DMDNS_UDS_SERVERPATH=\"/var/run/mdnsd\" -DIN_LIBRARY -DBUILDING_LIBICONV -DUSE_BONJOUR
LOCAL_CFLAGS += -DXR_TARGET_ANDROID -DKS_BUILDING_KS -Wno-psabi -Wno-multichar -D_GNU_SOURCE -DHAVE_IPV6=0 -DNOT_HAVE_SA_LEN
LOCAL_CFLAGS += -DUSES_NETLINK -DHAVE_LINUX -DTARGET_OS_LINUX
LOCAL_CPPFLAGS := -frtti -fexceptions
include $(BUILD_SHARED_LIBRARY)
However, when I attempt to include the first header in the projectLibNDC.c it prints the error of "No such file or directory".
#include "externalFile.h"
Is the approach that I am taking a possible solution?
Do I have to provide the relative paths in the Android.mk file itself for the files? That would be a bit more of a hassle instead of referencing a local folder of referenced files.
In theory, it sounds as though I would be able to create a library through the NDK in this manner. But, perhaps I am not setting up the project properly. Any aide would be helpful; JNI has a tendency to throw me around on occasion.
EDIT: It would seem that Eclipse (which is an amazing IDE) does not have any glue behind the references to the linked files that it keeps in its project settings. If I drag referenced files into the project, there are no physical files put into those folders to represent a linked files existence. That information is only stored in project settings apparently. Which is not helpful for the Android.mk file.
This means that any scripts or makefiles would not have any reference as to what files are supposed to be included. Unfortunately, I will have to reference folders and files individually from the makefile itself. I might leave the references in the project as a hint to their existence from other programmers. Unfortunate that I cannot design it that way, but that is the conclusion that I have received thus far.
回答1:
In the end, the approach that I decided to take was to include the relative paths to the files in the makefile individually. It was not the cleanest solution but it worked and provided a decent environment to work with later.
...
LOCAL_C_INCLUDES += $(COMMON_COMPUTATION_PATH)
LOCAL_C_INCLUDES += $(COMMON_DATASET_PATH)
...
LOCAL_SRC_FILES += $(COMMON_COMPUTATION_PATH)/matrixRT.cpp $(COMMON_COMPUTATION_PATH)/multiplRT.cpp
LOCAL_SRC_FILES += $(COMMON_COMPUTATION_PATH)/multiplSqRT.cpp $(COMMON_COMPUTATION_PATH)/multiplSq1978RT.cpp
...
Starting with a previous library that had linked files in it already within an iOS application, I can drag over those resources into local folders within the Eclipse project. Then select 'Link to files' from PROJ_LOC. Since both projects have the same relative path to all the files that I would be using, this worked like a charm and saved me from finding and dropping over individual ones that I need.
Since the shared files are only piecemeal of what would be needed in those directories I cannot get away with creating a single folder reference to source files with a wild card. However, I believe that in the end it would be best to request an organizational folder structure for mobile software so that we can indeed just reference the files that would be needed in mobile projects.
So in the end, I could not use the linked files as a reference from the manifest files. If it works for you user1368342 has mentioned that an OS level link file could be made and used from within a manifest file. However, for portability reasons across multiple OS platforms I decided not to go that route.
At least with a setup this way, the user can see the linked files that are included in the project library that is being built. They can also get updates on the screen and in the manifest when files change and get updated, along with the capability to handle any errors that arise from compiling it directly from within the project.
The downside is that when a new file needs to be introduced it will need to be added to both the project and the manifest, instead of in one single location. But, it's an acceptable solution for me. Hopefully anyone else who comes across an issue such as this one finds the approach useful.
回答2:
As mentioned in the comments, I also had problems with Eclipse references once. I used symbolic links at the OS level instead.
Problem might arise if you version a project using symbolic links (but I believe it is still worth trying). In my case, I had a main project that was versioned (and containing all the physical files), and the symbolic links were used to compile a library that wasn't.
来源:https://stackoverflow.com/questions/15645743/referencing-relative-path-resources-from-android-ndk-manifest-file