在 Qt for Android 中包含多个源目录
Posted
技术标签:
【中文标题】在 Qt for Android 中包含多个源目录【英文标题】:Include multiple source directories in Qt for Android 【发布时间】:2019-10-21 04:01:50 【问题描述】:我想在 Qt for android 项目中包含来自多个目录(在项目之间共享)的 Java 源代码。在http://imaginativethinking.ca/what-the-heck-how-do-i-share-java-code-between-qt-android-projects/ 上描述了一种复制 Java 源文件的方法:
# This line makes sure my custom manifest file and project specific java code is copied to the android-build folder
ANDROID_PACKAGE_SOURCE_DIR = $$PWD/android
# This is a custom variable which holds the path to my common Java code
# I use the $$system_path() qMake function to make sure that my directory separators are correct for the platform I'm compiling on as you need to use the correct separator in the Make file (i.e. \ for Windows and / for Linux)
commonAndroidFilesPath = $$system_path( $$PWD/../CommonLib/android-sources/src )
# This is a custom variable which holds the path to the src folder in the output directory. That is where they need to go for the ANT script to compile them.
androidBuildOutputDir = $$system_path( $$OUT_PWD/../android-build/src )
# Here is the magic, this is the actual copy command I want to run.
# Make has a platform agnostic copy command macro you can use which substitutes the correct copy command for the platform you are on: $(COPY_DIR)
copyCommonJavaFiles.commands = $(COPY_DIR) $$commonAndroidFilesPath $$androidBuildOutputDir
# I tack it on to the 'first' target which exists by default just because I know this will happen before the ANT script gets run.
first.depends = $(first) copyCommonJavaFiles
export(first.depends)
export(copyCommonJavaFiles.commands)
QMAKE_EXTRA_TARGETS += first copyCommonJavaFiles
对于更高的 Qt 版本,代码必须更改为:
commonAndroidFilesPath = $$system_path($$PWD/android/src)
androidBuildOutputDir = $$system_path($$OUT_PWD/../android-build)
createCommonJavaFilesDir.commands = $(MKDIR) $$androidBuildOutputDir
copyCommonJavaFiles.commands = $(COPY_DIR) $$commonAndroidFilesPath $$androidBuildOutputDir
first.depends = $(first) createCommonJavaFilesDir copyCommonJavaFiles
export(first.depends)
export(createCommonJavaFilesDir.commands)
export(copyCommonJavaFiles.commands)
QMAKE_EXTRA_TARGETS += first createCommonJavaFilesDir copyCommonJavaFiles
这是标准方式吗,还是有一些内置功能可以在 Qt for Android 项目中包含多个 Java 源目录?
问候,
【问题讨论】:
【参考方案1】:一个更清洁的解决方案是这个:
CONFIG += file_copies
COPIES += commonJavaFilesCopy
commonJavaFilesCopy.files = $$files($$system_path($$PWD/android/src))
commonJavaFilesCopy.path = $$OUT_PWD/android-build
【讨论】:
以上是关于在 Qt for Android 中包含多个源目录的主要内容,如果未能解决你的问题,请参考以下文章
Fabric Crashlytics for android - 如何在 stackTrace 区域中包含附加信息
如何在 Android 菜单 xml 的多个菜单中包含一个通用菜单项?