Android 在 Qt 中包含多个源目录

Include multiple source directories in Qt for Android

我想在 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 中为 Android 项目包含多个 Java 源目录?

此致,

一个更简洁的解决方案是:

CONFIG += file_copies
COPIES += commonJavaFilesCopy
commonJavaFilesCopy.files = $$files($$system_path($$PWD/android/src))
commonJavaFilesCopy.path = $$OUT_PWD/android-build