在Android版Qt中包含多个源目录

时间:2019-10-21 04:01:50

标签: java android qt qmake

我想在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

这是标准的做法吗?还是存在一些内置功能,可以在Android项目的Qt中包括多个Java源目录?

此致

1 个答案:

答案 0 :(得分:0)

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

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