android - 如何为每个项目构建关闭 C++ 编译器

标签 android c++ eclipse android-ndk

我的 Android - 项目内容超过 20 个 C++ 和 C 库。当我编译我的项目时,我编译所有这些库。但我不更改 C 代码 - 我只更改 java 代码。也许有一种方法可以避免每次都编译库?我使用 eclipse(Java 和 NDK)和 ant。 提前致谢!

编辑1:

Android.mk

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)

LOCAL_MODULE                  := DeflatingDecompressor-v3
LOCAL_SRC_FILES               := DeflatingDecompressor/DeflatingDecompressor.cpp
LOCAL_LDLIBS                  := -lz

include $(BUILD_SHARED_LIBRARY)

include $(CLEAR_VARS)

LOCAL_MODULE                  := LineBreak-v2
LOCAL_SRC_FILES               := LineBreak/LineBreaker.cpp LineBreak/liblinebreak-  2.0/linebreak.c LineBreak/liblinebreak-2.0/linebreakdata.c LineBreak/liblinebreak-  2.0/linebreakdef.c

include $(BUILD_SHARED_LIBRARY)

include $(CLEAR_VARS)

EXPAT_DIR                     := expat-2.0.1

LOCAL_MODULE                  := expat
LOCAL_SRC_FILES               := $(EXPAT_DIR)/lib/xmlparse.c $(EXPAT_DIR)/lib/xmlrole.c      $(EXPAT_DIR)/lib/xmltok.c
LOCAL_CFLAGS                  := -DHAVE_EXPAT_CONFIG_H
LOCAL_C_INCLUDES              := $(LOCAL_PATH)/$(EXPAT_DIR)
LOCAL_EXPORT_C_INCLUDES       := $(LOCAL_PATH)/$(EXPAT_DIR)/lib

include $(BUILD_STATIC_LIBRARY)

include $(CLEAR_VARS)

LOCAL_MODULE                  := NativeFormats-v2
LOCAL_CFLAGS                  := -Wall
LOCAL_LDLIBS                  := -lz -llog
LOCAL_STATIC_LIBRARIES        := expat

LOCAL_SRC_FILES               := \
NativeFormats/main.cpp \
NativeFormats/JavaNativeFormatPlugin.cpp \
NativeFormats/JavaPluginCollection.cpp \
NativeFormats/util/AndroidUtil.cpp \
NativeFormats/util/JniEnvelope.cpp \
NativeFormats/zlibrary/core/src/constants/ZLXMLNamespace.cpp \
NativeFormats/zlibrary/core/src/encoding/DummyEncodingConverter.cpp \
NativeFormats/zlibrary/core/src/encoding/Utf16EncodingConverters.cpp \
NativeFormats/zlibrary/core/src/encoding/Utf8EncodingConverter.cpp \
NativeFormats/zlibrary/core/src/encoding/JavaEncodingConverter.cpp \
NativeFormats/zlibrary/core/src/encoding/ZLEncodingCollection.cpp \
NativeFormats/zlibrary/core/src/encoding/ZLEncodingConverter.cpp \
NativeFormats/zlibrary/core/src/filesystem/ZLDir.cpp \
NativeFormats/zlibrary/core/src/filesystem/ZLFSManager.cpp \
NativeFormats/zlibrary/core/src/filesystem/ZLFile.cpp \
NativeFormats/zlibrary/core/src/filesystem/ZLInputStreamDecorator.cpp \
NativeFormats/zlibrary/core/src/filesystem/zip/ZLGzipInputStream.cpp \
NativeFormats/zlibrary/core/src/filesystem/zip/ZLZDecompressor.cpp \
NativeFormats/zlibrary/core/src/filesystem/zip/ZLZipDir.cpp \
NativeFormats/zlibrary/core/src/filesystem/zip/ZLZipEntryCache.cpp \
NativeFormats/zlibrary/core/src/filesystem/zip/ZLZipHeader.cpp \
NativeFormats/zlibrary/core/src/filesystem/zip/ZLZipInputStream.cpp \
NativeFormats/zlibrary/core/src/language/ZLCharSequence.cpp \
NativeFormats/zlibrary/core/src/language/ZLLanguageDetector.cpp \
NativeFormats/zlibrary/core/src/language/ZLLanguageList.cpp \
NativeFormats/zlibrary/core/src/language/ZLLanguageMatcher.cpp \
NativeFormats/zlibrary/core/src/language/ZLStatistics.cpp \
NativeFormats/zlibrary/core/src/language/ZLStatisticsGenerator.cpp \
NativeFormats/zlibrary/core/src/language/ZLStatisticsItem.cpp \
NativeFormats/zlibrary/core/src/language/ZLStatisticsXMLReader.cpp \
NativeFormats/zlibrary/core/src/library/ZLibrary.cpp \
NativeFormats/zlibrary/core/src/logger/ZLLogger.cpp \
NativeFormats/zlibrary/core/src/util/ZLFileUtil.cpp \
NativeFormats/zlibrary/core/src/util/ZLStringUtil.cpp \
NativeFormats/zlibrary/core/src/util/ZLUnicodeUtil.cpp \
NativeFormats/zlibrary/core/src/xml/ZLAsynchronousInputStream.cpp \
NativeFormats/zlibrary/core/src/xml/ZLPlainAsynchronousInputStream.cpp \
NativeFormats/zlibrary/core/src/xml/ZLXMLReader.cpp \
NativeFormats/zlibrary/core/src/xml/expat/ZLXMLReaderInternal.cpp \
NativeFormats/zlibrary/core/src/unix/filesystem/ZLUnixFSDir.cpp \
NativeFormats/zlibrary/core/src/unix/filesystem/ZLUnixFSManager.cpp \
NativeFormats/zlibrary/core/src/unix/filesystem/ZLUnixFileInputStream.cpp \
NativeFormats/zlibrary/core/src/unix/filesystem/ZLUnixFileOutputStream.cpp \
NativeFormats/zlibrary/core/src/unix/library/ZLUnixLibrary.cpp \
NativeFormats/zlibrary/text/src/model/ZLCachedMemoryAllocator.cpp \
NativeFormats/zlibrary/text/src/model/ZLTextModel.cpp \
NativeFormats/zlibrary/text/src/model/ZLTextParagraph.cpp \
NativeFormats/zlibrary/ui/src/android/filesystem/JavaFSDir.cpp \
NativeFormats/zlibrary/ui/src/android/filesystem/JavaInputStream.cpp \
NativeFormats/zlibrary/ui/src/android/filesystem/ZLAndroidFSManager.cpp \
NativeFormats/zlibrary/ui/src/android/library/ZLAndroidLibraryImplementation.cpp \
NativeFormats/fbreader/src/bookmodel/BookModel.cpp \
NativeFormats/fbreader/src/bookmodel/BookReader.cpp \
NativeFormats/fbreader/src/formats/EncodedTextReader.cpp \
NativeFormats/fbreader/src/formats/FormatPlugin.cpp \
NativeFormats/fbreader/src/formats/PluginCollection.cpp \
NativeFormats/fbreader/src/formats/fb2/FB2BookReader.cpp \
NativeFormats/fbreader/src/formats/fb2/FB2CoverReader.cpp \
NativeFormats/fbreader/src/formats/fb2/FB2MetaInfoReader.cpp \
NativeFormats/fbreader/src/formats/fb2/FB2Plugin.cpp \
NativeFormats/fbreader/src/formats/fb2/FB2Reader.cpp \
NativeFormats/fbreader/src/formats/fb2/FB2TagManager.cpp \
NativeFormats/fbreader/src/formats/css/StyleSheetParser.cpp \
NativeFormats/fbreader/src/formats/css/StyleSheetTable.cpp \
NativeFormats/fbreader/src/formats/html/HtmlBookReader.cpp \
NativeFormats/fbreader/src/formats/html/HtmlDescriptionReader.cpp \
NativeFormats/fbreader/src/formats/html/HtmlEntityCollection.cpp \
NativeFormats/fbreader/src/formats/html/HtmlPlugin.cpp \
NativeFormats/fbreader/src/formats/html/HtmlReader.cpp \
NativeFormats/fbreader/src/formats/html/HtmlReaderStream.cpp \
NativeFormats/fbreader/src/formats/oeb/NCXReader.cpp \
NativeFormats/fbreader/src/formats/oeb/OEBBookReader.cpp \
NativeFormats/fbreader/src/formats/oeb/OEBCoverReader.cpp \
NativeFormats/fbreader/src/formats/oeb/OEBMetaInfoReader.cpp \
NativeFormats/fbreader/src/formats/oeb/OEBPlugin.cpp \
NativeFormats/fbreader/src/formats/oeb/OEBTextStream.cpp \
NativeFormats/fbreader/src/formats/oeb/XHTMLImageFinder.cpp \
NativeFormats/fbreader/src/formats/rtf/RtfBookReader.cpp \
NativeFormats/fbreader/src/formats/rtf/RtfDescriptionReader.cpp \
NativeFormats/fbreader/src/formats/rtf/RtfPlugin.cpp \
NativeFormats/fbreader/src/formats/rtf/RtfReader.cpp \
NativeFormats/fbreader/src/formats/rtf/RtfReaderStream.cpp \
NativeFormats/fbreader/src/formats/txt/PlainTextFormat.cpp \
NativeFormats/fbreader/src/formats/txt/TxtBookReader.cpp \
NativeFormats/fbreader/src/formats/txt/TxtPlugin.cpp \
NativeFormats/fbreader/src/formats/txt/TxtReader.cpp \
NativeFormats/fbreader/src/formats/util/EntityFilesCollector.cpp \
NativeFormats/fbreader/src/formats/util/MergedStream.cpp \
NativeFormats/fbreader/src/formats/util/MiscUtil.cpp \
NativeFormats/fbreader/src/formats/util/XMLTextStream.cpp \
NativeFormats/fbreader/src/formats/xhtml/XHTMLReader.cpp \
NativeFormats/fbreader/src/formats/doc/DocBookReader.cpp \
NativeFormats/fbreader/src/formats/doc/DocMetaInfoReader.cpp \
NativeFormats/fbreader/src/formats/doc/DocPlugin.cpp \
NativeFormats/fbreader/src/formats/doc/DocStreams.cpp \
NativeFormats/fbreader/src/formats/doc/OleMainStream.cpp \
NativeFormats/fbreader/src/formats/doc/OleStorage.cpp \
NativeFormats/fbreader/src/formats/doc/OleStream.cpp \
NativeFormats/fbreader/src/formats/doc/OleStreamParser.cpp \
NativeFormats/fbreader/src/formats/doc/OleStreamReader.cpp \
NativeFormats/fbreader/src/formats/doc/OleUtil.cpp \
NativeFormats/fbreader/src/formats/doc/DocInlineImageReader.cpp \
NativeFormats/fbreader/src/formats/doc/DocFloatImageReader.cpp \
NativeFormats/fbreader/src/library/Author.cpp \
NativeFormats/fbreader/src/library/Book.cpp \
NativeFormats/fbreader/src/library/Comparators.cpp \
NativeFormats/fbreader/src/library/Library.cpp \
NativeFormats/fbreader/src/library/Tag.cpp

LOCAL_C_INCLUDES              := \
$(LOCAL_PATH)/NativeFormats/util \
$(LOCAL_PATH)/NativeFormats/zlibrary/core/src/constants \
$(LOCAL_PATH)/NativeFormats/zlibrary/core/src/encoding \
$(LOCAL_PATH)/NativeFormats/zlibrary/core/src/filesystem \
$(LOCAL_PATH)/NativeFormats/zlibrary/core/src/image \
$(LOCAL_PATH)/NativeFormats/zlibrary/core/src/language \
$(LOCAL_PATH)/NativeFormats/zlibrary/core/src/library \
$(LOCAL_PATH)/NativeFormats/zlibrary/core/src/logger \
$(LOCAL_PATH)/NativeFormats/zlibrary/core/src/util \
$(LOCAL_PATH)/NativeFormats/zlibrary/core/src/xml \
$(LOCAL_PATH)/NativeFormats/zlibrary/text/src/model

include $(BUILD_SHARED_LIBRARY)

编辑2:

构建.xml

<?xml version="1.0" encoding="UTF-8"?>
<project name="FBReaderJ" default="help">
<loadproperties srcFile="local.properties" />
<property file="ant.properties" />
<loadproperties srcFile="project.properties" />

<!-- quick check on sdk.dir -->
<fail
  message="sdk.dir is missing. Make sure to generate local.properties using 'android      update project'"
unless="sdk.dir"
/>

<target name="init" description="Initialization...">
    <fail message="Ant 1.7.0 or higher is required. Please upgrade your ant.">
        <condition>
            <not>
                <antversion property="ant.version"   atleast="1.7.0"/>
            </not>
        </condition>
    </fail>
</target>

<target name="native" unless="native.libraries.are.uptodate">
    <fail message="Native libraries are not up-to-date. Please run ndk-build     manually.">
        <condition>
            <os family="windows" />
        </condition>
    </fail>
    <echo message="Building native libraries..."/>
    <exec executable="${ndk.dir}/ndk-build" />
    <echo message="DONE (Building native libraries)"/>
</target>

<target name="check.native.libraries" depends="init">
    <echo message="Checking if native libraries are up-to-date..."/>
    <condition property="native.libraries.are.uptodate" value="true">
        <and>
            <!-- Check if libDeflatingDecompressor exists and is up to   date -->
            <available file="./libs/armeabi/libDeflatingDecompressor-  v3.so" />
            <uptodate   targetfile="libs/armeabi/libDeflatingDecompressor-v3.so">
                <srcfiles dir="jni/DeflatingDecompressor" includes="**/*.cpp"/>
            </uptodate>
            <!-- Check if libLineBreak exists and is up to date -->
            <available file="./libs/armeabi/libLineBreak-v2.so" />
            <uptodate property="libLineBreak-build-is-not-required"   targetfile="libs/armeabi/libLineBreak-v2.so">
                <srcfiles dir="jni/LineBreak"   includes="**/*.cpp,**/*.c,**/*.h"/>
            </uptodate>
            <!-- Check if libNativeFormats exists and is up to date -->
            <available file="./libs/armeabi/libNativeFormats-v2.so" />
            <uptodate property="libNativeFormats-build-is-not-required"   targetfile="libs/armeabi/libNativeFormats-v2.so">
                <srcfiles dir="jni/NativeFormats" includes="**/*.cpp,**/*.c,**/*.h"/>
            </uptodate>
        </and>
    </condition>
    <echo message="DONE (Checking if native libraries are up-to-date)"/>
</target>

<target name="resources" depends="init, check.native.libraries">
    <echo message="Cleaning up the 'res/drawable' folder..." />
    <delete dir="res/drawable/">
        <files includes="**"/>
    </delete>
    <echo message="DONE (Cleaning up the 'res/drawable' folder)" />

    <echo message="Copying icons files to 'res/drawable/' folder..." />
    <copy todir="res/drawable" verbose="false" overwrite="true" flatten="true">
        <fileset file="icons/fbreader.png" />
        <fileset dir="icons/" includes="*/*" />
    </copy>
    <echo message="DONE (Copying icons files to 'res/drawable/' folder)" />
</target>

<target name="-pre-build" depends="init, resources, native">
</target>
<!--
<target name="-pre-compile">
</target>

<target name="-post-compile">
</target>
-->
<target name="clean">
    <echo message="Deleting temporary files..." />
    <delete dir="gen" />
    <delete dir="bin" />
    <delete dir="res/drawable" />
    <delete dir="out" />
    <delete dir="obj" />
    <echo message="DONE (Deleting temporary files)" />
</target>

<target name="distclean" depends="clean">
    <echo message="Deleting native libraries..." />
    <delete dir="libs/armeabi" />
    <delete dir="libs/armeabi-v7a" />
    <delete dir="libs/x86" />
    <delete dir="libs/mips" />
    <delete dir="libs/mips-r2" />
    <delete dir="libs/mips-r2-sf" />
    <echo message="DONE (Deleting native libraries)" />
</target>

<import file="${sdk.dir}/tools/ant/build.xml" />
</project>

最佳答案

除非您使用NDK r8c,否则您可以无条件为您的项目调用ndk-build。它只会将 libDeflatingDecompressor-v3.so 文件从 obj/local/armeabi 复制到 libs/armeabi,剥离符号信息并小心所有依赖项和设置。

但是在最新的r8c版本中,有一个错误会导致无条件完全重建。我已发布a fix最近遇到这个错误。

关于android - 如何为每个项目构建关闭 C++ 编译器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13544478/

相关文章:

android - Flutter - 单击添加新的小部件

Android In app Billing V3 不工作

android - 使用 fetch 在 react-native 中发布一个 blob

android - 在android中使用自定义数据集创建 ListView ?

c++ - Lua C++ lib sethook : Gives error with hook function arg

java - 在 eclipse 中运行 java 应用程序与直接运行它有何不同?

c++ - 为什么 vector.push_back(auto_ptr) 无法编译?

c++ - 不在 make 过程中命名类型

使用变量的 Eclipse Java 项目构建路径

eclipse - eclipse 中的 tomcat - 由于先前的错误启动失败