AppImage打包

AppImage打包:

一、下载工具链

复制代码
linuxdeploy,linuxdeploy-plugin-qt
下载命令
`
wget https://github.com/linuxdeploy/linuxdeploy/releases/download/continuous/linuxdeploy-x86_64.AppImage
wget https://github.com/linuxdeploy/linuxdeploy-plugin-qt/releases/download/continuous/linuxdeploy-plugin-qt-x86_64.AppImage

chmod +x linuxdeploy-*.AppImage
`

二、构建AppDir目录

a. 添加.desktop文件及icon文件等,执行 build_AppDir.sh

三、确认目录现在完整如下(非常关键)

复制代码
	myproject/

└── usr/

├── bin/myproject

├── lib/...

├── share/

├── applications/

│ └── myproject.desktop ✅ 必须

└── icons/

└── hicolor/

└── 256x256/apps/

└── myproject.png ✅ 必须

四、构建AppImage

执行构建命令前先临时设置LD_LIBRARY_PATH添加依赖库路径
linuxdeploy-x86_64.AppImage \ --appdir myproject \ --executable myproject/usr/bin/myproject \ --plugin qt \ --output appimage

五、打包完成后的必做验证步骤(2 条命令)

1️⃣ 验证 AppImage 能启动:

./myproject-x86_64.AppImage

2️⃣ 验证依赖是否全部来自包内:

./myproject-x86_64.AppImage --appimage-extract

ldd squashfs-root/usr/bin/myproject | grep usr/lib

六、AppImage读取配置文件相关修改

打包后路径对应

./xxx.conf //当前目录此时对应的时AppImage包所在路径

applicationDirPath() //此时对应的路径为AppImage包目录下的/usr/bin

  1. APPImage包只读的配置文件路径可直接一起打包,修改查找路径:

#ifdef BUILD_APPIMAGE

strAppPath = QCoreApplication::applicationDirPath()

  • "/.../share/myproject/dist/combinnav";

#else

strAppPath = QDir::currentPath()+"/dist/combinnav";

#endif

复制代码
1. 需要安装后修改的,
a. 默认配置仍然放在 AppImage 内(只读模板)
b. 启动时自动复制到"用户可写目录"
你必须保证 main() 启动第一行就执行这段代码:

void initConfDir()

{

QString userConfDir =

QStandardPaths::writableLocation(

QStandardPaths::AppConfigLocation) + "/conf";

QString defaultConfDir =

QCoreApplication::applicationDirPath()

  • "/.../share/myapp/conf";

QDir userDir(userConfDir);

if (!userDir.exists())

userDir.mkpath(".");

QDir src(defaultConfDir);

for (const QFileInfo &fi : src.entryInfoList(QDir::Files)) {

QString dst = userConfDir + "/" + fi.fileName();

if (!QFile::exists(dst)) {

QFile::copy(fi.absoluteFilePath(), dst);

}

}

}

在 main() 中:

复制代码
int main(int argc, char *argv[])

{

QApplication app(argc, argv);

initConfDir(); // ✅ 必须在任何读配置之前

MainWindow w;

w.show();

return app.exec();

}

c. 之后 所有写配置操作只允许使用用户目录

复制代码
//写入示例

QString confDir =

QStandardPaths::writableLocation(

QStandardPaths::AppConfigLocation) + "/conf";

QSettings def(confDir + "/default.ini", QSettings::IniFormat);

def.setValue("ui/theme", "dark"); // ✅ 这里一定可写

def.sync();

复制代码
或者用户手动修改后直接使用
#ifdef BUILD_APPIMAGE
    QString confDir =
    QStandardPaths::writableLocation(
        QStandardPaths::AppConfigLocation) + "/conf";
    QSettings m_settings(confDir + "/default.ini", QSettings::IniFormat);
    qDebug()<< Q_FUNC_INFO << "Appimage Config Path:" << confDir + "/default.ini";
#else
    QSettings m_settings("./conf/default.ini", QSettings::IniFormat);
    qDebug() << Q_FUNC_INFO << "Config Path:" << "./conf/default.ini";
#endif

七、其他

  1. 本地缓存runtime

    a. 手动下载runtime包

    wget -O runtime-x86_64 https://github.com/AppImage/type2-runtime/releases/download/continuous/runtime-x86_64

    b. 设置环境变量让 appimagetool 使用本地 runtime(关键)

    export APPIMAGE_RUNTIME_FILE=~/appimage/runtime/runtime-x86_64

    c. 重新运行你的 linuxdeploy 打包命令

  2. 兼容本地调试及Appimage的配置路径写法

    confdir.h

相关推荐
欧云服务器5 天前
怎么让脚本命令可以同时在centos、debian、ubuntu执行?
ubuntu·centos·debian
~远在太平洋~5 天前
Debian系统如何删除多余的kernel
linux·网络·debian
~远在太平洋~6 天前
debian系统已安装python3.12却无法执行python命令
chrome·python·debian
木子欢儿9 天前
在 Debian 13(以及 12)上安装和配置 tightvncserver 并让普通用户使
运维·前端·debian
l1t16 天前
在debian 13.1容器中安装使用redrock postgresql
运维·postgresql·debian
木子欢儿16 天前
debian 13 安装配置ftp 创建用户admin可以访问 /mnt/Data/
linux·运维·服务器·数据库·debian
地球空间-技术小鱼17 天前
搜罗Linux桌面环境(Desktop Environments)列表
linux·运维·服务器·笔记·学习·ubuntu·debian
木子欢儿17 天前
Debian挂载飞牛OS创建的RAID分区和Btrfs分区指南
运维·debian
市安19 天前
基于Debain构建Ngxin镜像
运维·nginx·docker·云原生·容器·debian·镜像
henry10101019 天前
Debian/Ubuntu EC2实例上一键部署WireGuard
ubuntu·云计算·debian·aws