Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/qt/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Qt+;Android:不同项目通用的java文件的位置_Android_Qt - Fatal编程技术网

Qt+;Android:不同项目通用的java文件的位置

Qt+;Android:不同项目通用的java文件的位置,android,qt,Android,Qt,在Qt for Android中,项目中包含java文件。该位置在项目文件中配置了变量ANDROID\u PACKAGE\u SOURCE\u DIR 该位置还包含特定于项目的其他文件(资源等) 但是如果这些java文件在不同的项目中是通用的,那么您应该有单独的副本,在相应的ANDROID\u包\u SOURCE\u目录中的每个项目上都有一个副本 我的问题是,是否有人知道一种独立于项目位置指定java文件目录的方法。我对在Qt中开发Android应用程序还是相当陌生,但最近我开始了这一过程,遇到

在Qt for Android中,项目中包含java文件。该位置在项目文件中配置了变量ANDROID\u PACKAGE\u SOURCE\u DIR

该位置还包含特定于项目的其他文件(资源等)

但是如果这些java文件在不同的项目中是通用的,那么您应该有单独的副本,在相应的ANDROID\u包\u SOURCE\u目录中的每个项目上都有一个副本


我的问题是,是否有人知道一种独立于项目位置指定java文件目录的方法。

我对在Qt中开发Android应用程序还是相当陌生,但最近我开始了这一过程,遇到了与您完全相同的问题;我写了一些普通的C++/java代码,我想在几个不同的应用程序之间共享。C++代码很简单(共享库),但是,正如你所说的java代码,我不想在每个项目目录中都有相同的java代码的拷贝。 虽然花了一点时间,但我找到了一种很容易做到的方法

<>编译C++链接后,编译一个Qt Android项目时,运行一个编译脚本代码的Ant脚本(因此,你只需要在java文件夹中粘贴java源文件,而不需要编译jar文件)。p> ANT脚本是Android SDK的一部分,默认情况下会查看src文件夹并编译在那里找到的任何Java文件。因此,您真正需要确保的是,在运行ANT脚本之前,您希望用作应用程序一部分的所有Java文件都位于该文件夹中

ANDROID_PACKAGE_SOURCE_DIR变量告诉qMake在哪里找到需要复制到ANDROID构建文件夹的文件(包括任何特定于项目的Java代码)但是我们想要的是一个自定义目标,它在执行ANT脚本之前运行一段时间,手动将我们的公共Java文件复制到src文件夹,以便它们也可以编译到应用程序中

为此,我在*.pro文件中添加了以下内容:

# 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 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
first: $(first) copyCommonJavaFiles

copyCommonJavaFiles:
    $(COPY_DIR) C:\Users\bvanderlaan\Documents\GitHub\MyProject\MyProjectApp\..\CommonLib\android-sources\src C:\Users\bvanderlaan\Documents\GitHub\build-MyProject-Android_for_armeabi_v7a_GCC_4_9_Qt_5_4_1-Debug\MyProjectApp\..\android-build\src
运行qMake时,生成的Make文件将具有以下内容:

# 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 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
first: $(first) copyCommonJavaFiles

copyCommonJavaFiles:
    $(COPY_DIR) C:\Users\bvanderlaan\Documents\GitHub\MyProject\MyProjectApp\..\CommonLib\android-sources\src C:\Users\bvanderlaan\Documents\GitHub\build-MyProject-Android_for_armeabi_v7a_GCC_4_9_Qt_5_4_1-Debug\MyProjectApp\..\android-build\src

所以现在我构建我的普通C++作为一个共享库链接,我的普通java代码在蚂蚁脚本编译所有java代码之前被复制到SRC目录,并用我所拥有的任何项目特定java代码复制到我的应用程序中。这样就不需要在源代码树中的多个位置保留Java文件的副本,也不需要在编译之前使用外部构建脚本/工具来设置工作空间

我希望这能回答你的问题,对你有用


下次再进行富有想象力的思考和创造性的设计

谢谢您的回复。顺便说一句,我学到了一些关于qmake的新东西:-)也许唯一的问题仍然是,如果您的java代码有错误,QtCreator编辑器会指向复制文件夹中的源代码,而不是原始代码,因此您可能正在进行一些编辑,这些编辑可能会在以后被销毁。