尝试为Android构建Xerces-C++

问题描述 投票:0回答:3

我正在寻找一种为 Android 构建 Xerces-C++ 库的方法,我需要它作为 Delta3D 游戏引擎的依赖项,但找不到任何相关信息。我非常感谢专业建议。

android c++ build xml-parsing xerces
3个回答
3
投票

您可以从 here 复制带有 Android 构建脚本的 xercesc 库。
只需将其复制到您的 jni 文件夹中并运行 ndk-build


2
投票

大多数 Android 开发都是用 Java 完成的。 Delta3D 游戏引擎采用 C++ 语言,这意味着您需要从 Android 本机开发套件 (NDK) 开始。 FAQ 声称该库使用跨平台依赖项,因此理论上您应该能够在 Android 上使用它。 但是,它是为 OpenGL 而不是 OpenGL ES(Android 中使用的子集)编写的。 这可能会导致问题。 另一个问题是内存占用。 要在 Android 下进行编译,可能需要做大量的工作。 您可能会考虑使用已经移植到 Android(或为其编写)的库,而不是移植该库所需的所有工作,更不用说编写游戏了。 除非,您已经有一个用这个游戏引擎编写的游戏,我理解为什么您只想移植该库。


0
投票

如果您想构建 Xerces 库,请按照以下步骤操作:

  1. 将 Xerces 源代码复制到 jni 文件夹中。
  2. 修改您的 Android.mk 和 Application.mk 文件,如下所示。

Xerces 的 Android.mk

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)

# List of all subdirectories in src/xercesc/
XERCES_SUBDIRS := $(shell find $(LOCAL_PATH)/src/xercesc/ -type d)

# Name of the library
LOCAL_MODULE := xerces1

# Check the target architecture
ifeq ($(TARGET_ARCH), armeabi-v7a)
    LOCAL_CFLAGS += -march=armv7-a
endif

# Exclude specific files and include all .cpp files from the root and subdirectories
LOCAL_SRC_FILES := $(filter-out src/xercesc/util/Transcoders/MacOSUnicodeConverter/MacOSUnicodeConverter.cpp, $(wildcard $(LOCAL_PATH)/xerces/src/*.cpp))

# Include paths for Xerces-C++ headers
LOCAL_C_INCLUDES := $(LOCAL_PATH)/src \
                    $(LOCAL_PATH)/include \
                    $(LOCAL_PATH)/include/xercesc/util \
                    $(LOCAL_PATH)/include/xercesc/util/MsgLoaders/InMemory \
                    $(LOCAL_PATH)/include/xercesc/dom \
                    $(LOCAL_PATH)/include/xercesc/dom/impl \
                    $(LOCAL_PATH)/include/xercesc/validators/schema/identity \
                    $(LOCAL_PATH)/include/xercesc/util/Transcoders/IconvGNU \
                    $(LOCAL_PATH)/include/xercesc/sax

# Compilation flags
LOCAL_CFLAGS := -Os -DHAVE_CONFIG_H -frtti -fexceptions

# Specify the C++ file extension
LOCAL_CPP_EXTENSION := .cpp

# Add the source files from the root of the src directory
LOCAL_SRC_FILES := $(wildcard $(LOCAL_PATH)/src/*.cpp)

# Add the source files from all subdirectories of src/xercesc
LOCAL_SRC_FILES += $(foreach subdir, $(XERCES_SUBDIRS), $(wildcard $(subdir)/*.cpp))

# Build as a shared library
include $(BUILD_SHARED_LIBRARY)

jni 文件夹的Android.mk

# Define the local path for the current directory
LOCAL_PATH := $(call my-dir)

# Specify the STL to use
APP_STL := c++_shared

# Include the Xerces-C++ Android.mk file
include $(LOCAL_PATH)/xerces/Android.mk

# Clear any previous settings
include $(CLEAR_VARS)

# Define the module name for the Xerces library
LOCAL_MODULE := xerces

# Specify the source files to be compiled
# If you want to include specific files, adjust accordingly
LOCAL_SRC_FILES := $(wildcard $(LOCAL_PATH)/xerces/src/*.cpp)

# Include directories for Xerces-C++ headers
LOCAL_C_INCLUDES := $(LOCAL_PATH)/xerces/include \
                    $(LOCAL_PATH)/xerces/include/xercesc/util \
                    $(LOCAL_PATH)/xerces/include/xercesc/dom \
                    $(LOCAL_PATH)/xerces/include/xercesc/validators/schema/identity \
                    $(LOCAL_PATH)/xerces/include/xercesc/sax

# Compiler flags
LOCAL_CFLAGS := -Os -frtti -fexceptions -DHAVE_CONFIG_H

# Build as a shared library
include $(BUILD_SHARED_LIBRARY)

jni 文件夹的Application.mk

# Set the project path
APP_PROJECT_PATH := $(call my-dir)/..

# Specify the application ABI (Architecture Binary Interface)
APP_ABI := armeabi-v7a  # Set to armeabi-v7a for 32-bit ARM

# Specify the platform level (API level)
APP_PLATFORM := android-21  # Minimum API level for your application

# Specify the STL to use
APP_STL := c++_shared

# Additional compiler flags
APP_CFLAGS := -g -Os -frtti -fexceptions -DHAVE_CONFIG_H

# Enable PIE (Position Independent Executable)
APP_PIE := true 

# Additional flags for linking
SDL_EXCLUDE_LIBGCC := -Wl,--exclude-libs,libgcc.a
SDL_EXCLUDE_LIBUNWIND := -Wl,--exclude-libs,libunwind.a
APP_LDFLAGS = $(if $(filter clang%, $(NDK_TOOLCHAIN_VERSION)), $(SDL_EXCLUDE_LIBGCC) $(if $(filter armeabi%, $(APP_ABI)), $(SDL_EXCLUDE_LIBUNWIND)))

# Disable debug mode by default
ifneq ($(NDK_DEBUG),1)
APP_CFLAGS += -Oz -DNDEBUG  # Use optimized settings for release builds
endif

构建 Xerces 库

ndk-构建

© www.soinside.com 2019 - 2024. All rights reserved.