macos 如何构建本机 Mac OS X 安装程序(在非 Mac 平台上)?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/283480/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-21 05:58:10  来源:igfitidea点击:

How to build native Mac OS X installer (on a non-Mac platform)?

macosinstallerdmg

提问by michelemarcon

How can I build a native Mac OS X installer for my application, on a non-Mac platform?

如何在非 Mac 平台上为我的应用程序构建本机 Mac OS X 安装程序?

For example, I have a windows pc and a Java application. I want the windows pc to build an installer (possibly inside a .dmg archive) that works with Apple installer.

例如,我有一台 windows pc 和一个 Java 应用程序。我希望 Windows pc 构建一个与 Apple 安装程序一起使用的安装程序(可能在 .dmg 存档中)。

采纳答案by hogliux

It is now possible to create a native Mac OS X installer on a non-Mac platform. As Louis Gerbarg, the tricky bit is the BOM (bill-of-materials) file. However an open source version of mkbom (based on the osxbom code by Joseph Coffland) is now available at:

现在可以在非 Mac 平台上创建本机 Mac OS X 安装程序。作为 Louis Gerbarg,棘手的是 BOM(物料清单)文件。但是,mkbom 的开源版本(基于 Joseph Coffland 的 osxbom 代码)现在可在以下位置获得:

http://hogliux.github.io/bomutils

http://hogliux.github.io/bomutils

The website also has an easy to follow step-by-step tutorial on creating a Mac OS X installer on Linux ( http://hogliux.github.io/bomutils/tutorial.html).

该网站还提供了在 Linux 上创建 Mac OS X 安装程序的易于遵循的分步教程 ( http://hogliux.github.io/bomutils/tutorial.html)。

My company regularly build Mac OS X installers on linux with this method and so far we haven't had any major problems.

我的公司定期使用这种方法在 linux 上构建 Mac OS X 安装程序,到目前为止我们还没有遇到任何重大问题。

回答by Daniel Lopez

It is difficult to create a .dmg on Windows, but it is certainly possible to create a .app file structure that you can then zip, as others commented have mentioned. There are times when a regular .pkg will not cut it and you want to provide dialogs, pre-Installation checks, etc. You can do that with BitRock installbuilder, you can build installers for mac, Linux, Windows, Solaris from each of the other platforms.

在 Windows 上创建 .dmg 很困难,但正如其他评论所提到的,创建一个 .app 文件结构当然是可能的,然后您可以将其压缩。有时,常规的 .pkg 不会剪切它,而您想要提供对话框、安装前检查等。您可以使用BitRock installbuilder来做到这一点,您可以为 mac、Linux、Windows、Solaris 的每个构建安装程序其他平台。

回答by Nik Reiman

As others have already pointed out, you are really taking the hard solution to this problem, and your users will curse your name for it, unless you have a reallygood reason to do so. It is true, that certain types of applications will require installers for Mac OSX. These generally include:

正如其他人已经指出的那样,你真的走很难解决这个问题,你的用户会骂你的名字吧,除非你有一个真正好的理由这样做。确实,某些类型的应用程序需要 Mac OSX 的安装程序。这些一般包括:

  • Applications which install custom drivers (ie, kernel extensions)
  • Applications which need to install frameworks or other resources which for some reason could not be packaged within the application bundle
  • Applications which need to run as a system service and therefore must run some post-install scripts to launch the app during bootup
  • Poorly written programs which require making some type of changes to the user's system (ie, setting permissions on a folder or something), and the developer's hands are tied by marketing department weenies to distribute the application in the most painful way possible
  • 安装自定义驱动程序(即内核扩展)的应用程序
  • 需要安装框架或其他资源的应用程序由于某种原因无法打包在应用程序包中
  • 需要作为系统服务运行的应用程序,因此必须运行一些安装后脚本以在启动期间启动应用程序
  • 编写糟糕的程序,需要对用户系统进行某种类型的更改(即设置文件夹的权限或其他内容),而开发人员的双手被营销部门束缚,以最痛苦的方式分发应用程序

Ok, so that last point is a bit sarcastic, but do you get my drift here? :) Basically, if you are writing a normal, end-user application, you should distribute it in the normal way that Mac users would expect, which is a DMG file containing your application's bundle. Or if you want to be really fancy, stick an alias to the "Applications" folder inside of the DMG to help the user drag the program in there. Unless you are writing something which must install itself intothe system, rather than simply be run bythe system, there's no reason to use an installer here. Also, keep in mind that this is OSX, which already contains a fully-functioning Java JRE, so you don't need to worry about packaging the JRE in an installer or anything like that.

好的,最后一点有点讽刺,但你明白我的意思吗?:) 基本上,如果您正在编写一个普通的最终用户应用程序,您应该按照 Mac 用户期望的正常方式分发它,这是一个包含应用程序包的 DMG 文件。或者,如果您真的很喜欢,可以将别名粘贴到 DMG 内的“应用程序”文件夹中,以帮助用户将程序拖到那里。除非你写的东西必须自己安装系统中,而不是简单地由系统运行,否则没有理由在这里使用安装程序。另外,请记住,这是 OSX,它已经包含一个功能齐全的 Java JRE,因此您无需担心将 JRE 打包到安装程序或类似的东西中。

Now that you've been properly scolded for asking this question, I'll answer it with the assumption that your software falls in one of the categories above. Really, your best bet would be to go with a commercial solution such as VISE installer (which, again, I can state confidently that a vast majority of Mac users will recoil in terror when installing a product made with this tool), which allows you to do exactly what you are looking for here -- basically, to make a cross-platform installer which builds for the various platforms you want to support from a single installer file.

既然您已经因为提出这个问题而受到了适当的责骂,那么我将假设您的软件属于上述类别之一来回答。确实,您最好的选择是使用商业解决方案,例如 VISE 安装程序(再次,我可以自信地说,绝大多数 Mac 用户在安装使用此工具制作的产品时会因恐惧而退缩),它允许您完全按照您在此处寻找的内容——基本上,制作一个跨平台安装程序,该安装程序为您希望从单个安装程序文件支持的各种平台构建。

Again, though, your best bet here is to do what users of that platform are most comfortable with (which is why all the responses to your question urge you not to make an installer). That means, however, if you really must make an installer, you should use a non-cross-platform framework; windows users will feel most at home when presented with a standard MSI installer, and Mac users will feel most at home with an Apple Installer pkg. The PackageMaker program is notoriously limited, though, so if you must, you should use iceberginstead. This will mean a bit more maintainance for you, since you'll need to tend after two (or more) separate installers, but if your software is really so complex as to demand this, you should be willing to make the sacrifice for the comfort of your users.

不过,再一次,您最好的选择是做该平台用户最喜欢的事情(这就是为什么对您的问题的所有回答都敦促您不要制作安装程序的原因)。但是,这意味着,如果您确实必须制作安装程序,则应该使用跨平台框架;Windows 用户在使用标准 MSI 安装程序时会感到宾至如归,而 Mac 用户在使用 Apple Installer pkg 时会感到宾至如归。然而,PackageMaker 程序的局限性是出了名的,所以如果你必须这样做,你应该改用冰山。这对您来说意味着更多的维护,因为您需要在两个(或更多)单独的安装程序之后进行维护,但是如果您的软件确实如此复杂以至于需要这样做,您应该愿意为舒适而做出牺牲您的用户。

回答by Louis Gerbarg

So, a couple of quick questions.

所以,有几个简单的问题。

First, why do you want an installer? Most Mac users prefer apps that are just drag installed. If you are not writing Mac OS X specific code it is hard to imagine you need to place bits in special places, like Application Support or LaunchDaemons. Assuming everything you have just goes in one folder why bother with an installer at all?

首先,为什么要安装程序?大多数 Mac 用户更喜欢拖拽安装的应用程序。如果您不编写 Mac OS X 特定代码,很难想象您需要将位放置在特殊位置,例如应用程序支持或 LaunchDaemons。假设你所有的东西都放在一个文件夹里,为什么还要麻烦安装程序呢?

Second, why would it be a problem to build the Mac installer on a Mac? Surely you have a macintosh around to test the app (you are not just blindly shipping it for Mac without testing it on a Mac, right?).

其次,为什么在 Mac 上构建 Mac 安装程序会出现问题?你肯定有一台 macintosh 来测试这个应用程序(你不会只是盲目地为 Mac 发布它而不在 Mac 上测试它,对吧?)。

Okay, having said that, assuming you still have a good reason to actually build this on a PC, there are some bits that are not going to be easy. Basically a .pkg is a bunch of text scripts, localizations, an archive file (Archive.pax.gz), and a bill of materials (Archive.bom).

好吧,话虽如此,假设您仍然有充分的理由在 PC 上实际构建它,那么有些部分并不容易。基本上,.pkg 是一堆文本脚本、本地化、存档文件 (Archive.pax.gz) 和材料清单 (Archive.bom)。

Assuming not much changes between builds, you can make the installer on a Mac, and then just rebuild the bom and the pax.gz, replace them into the existing .pkg, and batch a few pieces of metadata. The pax should be easy enough to deal with (pax is a standard archive format), but the bom file may prove a bit trickier, since I do not believe it is publicly documented, and I doubt the tools for creating them (mkbom) are part of darwin (not opensource). So you are going to need to figure that out and write a custom tool to create the bom file.

假设构建之间没有太大变化,您可以在 Mac 上制作安装程序,然后只需重建 bom 和 pax.gz,将它们替换为现有的 .pkg,并批处理一些元数据。pax 应该很容易处理(pax 是标准的存档格式),但是 bom 文件可能有点棘手,因为我不相信它是公开记录的,而且我怀疑创建它们的工具 (mkbom)达尔文的一部分(非开源)。因此,您将需要弄清楚并编写一个自定义工具来创建 bom 文件。

In other words, this is likely to be a large amount of work.

换句话说,这很可能是一个很大的工作量。

回答by svinto

The usual way to install a app on a Mac is to drag the app to the application folder. Most programs come as a DMG containing the app and a symbolic link to the application folder. Why would you want it any other way? You need to think Mac to build a great Mac application! Look and feel is very important, especially for Mac users.

在 Mac 上安装应用程序的常用方法是将应用程序拖到应用程序文件夹中。大多数程序都以 DMG 形式出现,其中包含应用程序和指向应用程序文件夹的符号链接。你为什么要以其他方式?您需要考虑使用 Mac 来构建出色的 Mac 应用程序!外观和感觉非常重要,尤其是对于 Mac 用户。

回答by jcoffland

Check out this code for reading BOM files: https://cauldrondevelopment.com/svn/osxbom/trunk

查看此代码以读取 BOM 文件:https: //cauldrondevelopment.com/svn/osxbom/trunk

回答by saschabeaumont

Put everything into one JAR file, add it to a ZIP. Done.

将所有内容放入一个 JAR 文件中,然后将其添加到 ZIP 中。完毕。

But seriously, you're wanting to distribute your application to Macintosh users without testing it first? What planet are you on!?

但说真的,您想将您的应用程序分发给 Macintosh 用户而不先对其进行测试?你在哪个星球!?