使用Qt installer framework制作安装包

简述:

使用Qt库开发的应用程序,一般有两种发布方式:(1)静态编译发布。这种方式使得程序在编译的时候会将Qt核心库全部编译到一个可执行文件中。其优势是简单单一,所有的依赖库都集中在一起,其缺点也很明显,可执行程序体量较大,光Qt核心库加起来就得十多兆。(2)制作安装包发布。这种方式的原理也简单,就是将可执行程序和其依赖的库文件一起打包压缩,制作成安装包发布。制作安装包的工具挺多,这里介绍的是Qt官方的安装包制作框架Qt installer framework.这个框架由Qt官方出品,广泛应用于Qt library, Qt Creator等安装包产品。

系统环境:

linux 系统:Fedora 29  64bit

Qt5.11.3 : qt-opensource-linux-x64-5.11.3.run

installer framework : QtInstallerFramework-linux-x64.run

 

1. 打包前准备

打包前要确定所需要打包的运行文件、依赖库以及资源文件等

2. 目录组织结构

从Qt installer framework安装目录下的examples里面复制一个出来,在此基础上进行修改:

	|--root                         //根目录
		|--app.pro		//工程文件
		|--config                //配置
			|--config.xml	//配置文件
		|--packages		
			|--appDir
				|--data
				|--meta
					|--package.xml
		|--README

根目录下面创建两个子目录:config和packages。

1> config

在config目录下创建一个config.xml文件,该文件用于定制安装包的UI和行为,其基本格式如下:

<?xml version="1.0" encoding="UTF-8"?>
<Installer>
    <Name>License Agreement Example</Name>
    <Version>1.0.0</Version>
    <Title>License Agreement Example</Title>
    <Publisher>Qt-Project</Publisher>
    <StartMenuDir>Qt Installer Framework Example</StartMenuDir>
    <TargetDir>@HomeDir@/IfwExamples/licenseagreement</TargetDir>
</Installer>

<?xml version="1.0" encoding="UTF-8"?>
<Installer>
    <Name>软件名称</Name>
    <Version>版本号</Version>
    <Title>安装程序窗口标题</Title>
    <Publisher>发布者名称</Publisher>
    <!-- Directory name is used in component.xml -->
    <StartMenuDir>要生成的开始菜单目录</StartMenuDir>
    <TargetDir>@HomeDir@/.vris/xxx</TargetDir>
    <!-- TargetDir>默认安装路径</TargetDir -->
    <!-- RunProgram>@TargetDir@/init.sh</RunProgram -->
    <Logo>xxx.png</Logo>
    <RemoteRepositories>
        <Repository>
            <Url>http://localhost:9000/update/app/repository</Url>
            <!-- Url>http://www.your-repo-location/repository</Url -->
        </Repository>
    </RemoteRepositories>
</Installer>

<?xml version="1.0"?>
<Installer>
    <Name>Some Application</Name>
    <Version>1.0.0</Version>
    <Title>Some Application Setup</Title>
    <Publisher>Your Company</Publisher>
    <ProductUrl>http://www.your-fantastic-company.com</ProductUrl>
    <InstallerWindowIcon>installericon</InstallerWindowIcon>
    <InstallerApplicationIcon>installericon</InstallerApplicationIcon>
    <Logo>logo.png</Logo>
    <Watermark>watermark.png</Watermark>
    <RunProgram></RunProgram>
    <RunProgramArguments></RunProgramArguments>
    <RunProgramDescription></RunProgramDescription>
    <StartMenuDir>Some Application Entry Dir</StartMenuDir>
    <UninstallerName>SDKMaintenanceTool</UninstallerName>
    <AllowNonAsciiCharacters>true</AllowNonAsciiCharacters>
    <Background>background.png</Background>
 
    <TargetDir>@homeDir@/testinstall</TargetDir>
    <AdminTargetDir>@rootDir@/testinstall</AdminTargetDir>
    <RemoteRepositories>
        <Repository>
            <Url>http://www.your-repo-location/packages/</Url>
        </Repository>
    </RemoteRepositories>
</Installer>

其中,name和version子元素是必需的,其他子元素则是可选的,并且顺序可以任意。

2 > 组件

Qt installer framework引入了组件的概念。即每一个独立模块可以单独放在一个组件component中,对于大型程序这样清晰的结构有利于工程组织,降低复杂度。例子中比较简单,只使用了一个组件,根据需要可以创建多个组件。

packages
    - com.vendor.root
        - data
        - meta
    - com.vendor.root.component1
        - data
        - meta
    - com.vendor.root.component1.subcomponent1
        - data
        - meta
    - com.vendor.root.component2
        - data
        - meta

3 > packages

在packages目录下每个组件都需要创建两个子文件夹meta和data。

meta目录下用于存放一些配置文件,用于指定安装和部署过程。在meta文件夹中至少需要一个package.xml及所有在该文件中引用到的资源文件,如脚本文件、界面资源、翻译文件等。

package.xml文件描述了一个组件的基本信息,其格式如下:

<?xml version="1.0" encoding="UTF-8"?>
<Package>
    <DisplayName>README (requires license agreement)</DisplayName>
    <Description>README can only be installed if the user agrees to the licenses.</Description>
    <ReleaseDate>2019-09-30</ReleaseDate>
    <Version>固件的版本号</Version>
    <Default>true</Default>
    <Licenses>
        <License name="Creative Commons (CC0 1.0)" file="cc0.txt"/>
        <License name="GNU GENERAL PUBLIC LICENSE Version 3" file="gpl3.txt"/>
    </Licenses>
    <!-- Licenses>许可信息名称以及许可文件名</Licenses -->
    <!--Default>默认是否选中协议</Default-->
    <!-- Script>脚本文件</Script -->
</Package>

<?xml version="1.0" encoding="UTF-8"?>
<Package>
    <DisplayName>显示的名称</DisplayName>
    <Description>描述</Description>
    <Version>4480</Version>
    <ReleaseDate>发行日期</ReleaseDate>
    <Default>true</Default>
    <!-- Script>installscript.js</Script -->
</Package>

<?xml version="1.0"?>
<Package>
    <DisplayName>QtGui</DisplayName>
    <Description>Qt gui libraries</Description>
    <Description xml:lang="de_de">Qt GUI Bibliotheken</Description>
    <Version>1.2.3</Version>
    <ReleaseDate>2019-09-30</ReleaseDate>
    <Name>com.vendor.root.component2</Name>
    <Dependencies>com.vendor.root.component1</Dependencies>
    <Virtual>false</Virtual>
    <Licenses>
        <License name="License Agreement" file="license.txt" />
    </Licenses>
    <Script>installscript.qs</Script>
    <UserInterfaces>
        <UserInterface>specialpage.ui</UserInterface>
        <UserInterface>errorpage.ui</UserInterface>
    </UserInterfaces>
    <Translations>
        <Translation>sv_se.qm</Translation>
        <Translation>de_de.qm</Translation>
    </Translations>
    <DownloadableArchives>component2.7z, component2a.7z</DownloadableArchives>
    <AutoDependOn>com.vendor.root.component3</AutoDependOn>
    <SortingPriority>123</SortingPriority>
    <UpdateText>This changed compared to the last release</UpdateText>
    <Default>false</Default>
    <ForcedInstallation>false</ForcedInstallation>
    <Essential>false</Essential>
    <Replaces>com.vendor.root.component2old</Replaces>
</Package>

其中License节中指定了协议条款,file属性指定了协议条款所在的文件。UserInterfaces和Translations节分别指定了界面资源文件和翻译文件。Script节指定了脚本文件,在脚本文件中可以对安装过程进行更为详细的定制。

data文件夹中则用于存放我们实际需要打包的程序文件(依赖库, 运行文件等),Qt installer framework在制作过程中用archivegen会将这些文件压缩成7zip格式。安装过程中自动从压缩包中提取出数据文件。

4 > .pro 工程文件

作用是生成安装包程序,关键命令是:

binarycreator --online-only -c $$PWD/config/config.xml -p $$PWD/packages ${QMAKE_FILE_OUT}
TEMPLATE = aux
INSTALLER = installer
INPUT = $$PWD/config/config.xml $$PWD/packages
example.input = INPUT
example.output = $$INSTALLER
example.commands = ../../bin/binarycreator -c $$PWD/config/config.xml -p $$PWD/packages ${QMAKE_FILE_OUT}
example.CONFIG += target_predeps no_link combine
QMAKE_EXTRA_COMPILERS += example
OTHER_FILES = README

#TEMPLATE = subdirs
TEMPLATE = aux
INSTALLER = xxxInstaller
INPUT = $$PWD/config/config.xml $$PWD/packages
xxx.input = INPUT
xxx.output = $$INSTALLER
#xxx.commands = binarycreator -c $$PWD/config/config.xml --repository $$PWD/packages/xxx/data/repository -p $$PWD/packages ${QMAKE_FILE_OUT}
xxx.commands = binarycreator --online-only -c $$PWD/config/config.xml -p $$PWD/packages ${QMAKE_FILE_OUT}
#binarycreator -c config/config.xml -p packages installer
xxx.CONFIG += target_predeps no_link combine
QMAKE_EXTRA_COMPILERS += xxx
OTHER_FILES = README
DISTFILES += \
    packages/AI/meta/package.xml \
    packages/xxx/meta/package.xml

3、创建存储库

使用repogen工具创建一个软件包目录的所有软件包的联机存储库:
repogen -p ${DIR_PACKAGES} ${DIR_REPOSITORY}
存储库目录结构如下:

	|--repository                        
		|--Updates.xml		
		|--xxx               
			|--4480autostart.7z	
			|--4480autostart.7z.sha1
			|--4480content.7z
			|--4480content.7z.sha1
			|--4480lib64.7z
			|--4480lib64.7z.sha1
			|--4480meta.7z
			|--4480share.7z
			|--4480share.7z.sha1

创建存储库后,将其上传到Web服务器。 且在安装程序配置文件(config.xml)中指定存储库的位置。

Update.xml文件描述了一个存储库更新的基本信息,其格式如下:
 

<Updates>
 <ApplicationName>{AnyApplication}</ApplicationName>
 <ApplicationVersion>1.0.0</ApplicationVersion>
 <Checksum>true</Checksum>
 <PackageUpdate>
  <Name>psyBar</Name>
  <DisplayName>xxx</DisplayName>
  <Description>xxx APP</Description>
  <Version>4480</Version>
  <ReleaseDate>2019-09-30</ReleaseDate>
  <Default>true</Default>
  <UpdateFile CompressedSize="23335175" OS="Any" UncompressedSize="41776361"/>
  <DownloadableArchives>autostart.7z,lib64.7z,share.7z,content.7z</DownloadableArchives>
  <SHA1>f4ee0c953ece442d13fa68cfdaa7eb96f9e1e919</SHA1>
 </PackageUpdate>
</Updates>

4、静默升级

maintenancetool --silentUpdate -v
	|--xxx                      
		|--components.xml	
		|--installer.dat            
		|--maintenancetool	
		|--maintenancetool.dat
		|--maintenancetool.ini
		|--network.xml
		|--lib-install.sh

 

 

参考:

使用Qt installer framework制作安装包

Qt5+安装包制作(Qt Installer Framework)

Qt Installer Framework 使用说明(二)

 

 

 

 

  • 1
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值