With the release of our game Lana & Tom I wanted to submit a standalone version of the game to the Mac Store. Let me show you how we did it! Head to the Unity Manual, we’ll be done in no ti..
First, we’re going to get Unity to build the Xcode project. Open the Build Settings from the top menu (File Build Settings). Click Add Open Scenes to add the Main scene to the list of scenes that will be built. Click Build to build. Return to the Build Settings dialog. In the Windows Explorer dialog that appears, create a new folder to hold Unity's build output. Generally, we name the folder 'App'. Select the newly created folder and click Select Folder. Once Unity has finished building, a Windows Explorer window will open to the project root directory.
With an outdated manual, it's not straightforward to deliver your game to the mac store today. Here I'll be trying to put together all the missing bits. May this article serve as a reminder that hitting the build button in Unity is often only the beginning.
Prerequisites
Application & Installer certificates
App is set up in the iTunes Connect Store Application Loader Step-By-Step Guide
1. Add a fix for a common resolution problem on retina devices in your startup code. Commonly this goes into your first scene (We usually have a Startup.cs file on the first object in the hierachy).
UnityScript (adapted from the manual)
Our C# translation
2. Go to your Standalone Player Settings and enable 'Mac App Store Validation'. You'll find the options Under The Resolutions and Settings Panel.
3. Go to the Build Settings and Build your app. Make sure the name of your app is the same as used in your iTunes Connect profile. Otherwise your app will be rejected in app review!
4. Now we need to update our Info.plist manually. Unity will generate a template version for us. Go to the .app package and open it with 'Show Package Contents'. Open Info.plist in your favorite Text Editor. See the official guidelines (CoreFoundationKeys, LaunchServicesKeys).
These entries need your attention.
Add this key to the list. Looks like Unity forgot about this one!
5. Save the Info.plist inside your package and don’t forget to create a copy since Unity will overwrite the file the next time you make a build!
6. Navigate to the Resources folder inside your .app package. There should be an .icns file (mine was called PlayerIcon.icns). It contains the wrong icon sizes for the Mac Store so we have to build our own set.
All the required files for your iconset.
Generate all image files and put them in a folder. Name the folder like the .icns file in your app package and use .iconset as the extension (we now have a folder called PlayerIcon.iconset). Now we need to convert the folder into a real icon set. Fire up your terminal, navigate your .iconset folder and perform the following command:
You should end up with a new .icns file. Overwrite the .icns file in the package with the created one.
7. (Optional) Overwrite the default UnityPlayerIcon.png also found in the Resources folder with your own image.
8. Fix read permissions on all the content in your .app package. In the Terminal type:
9. Next we’ll need to create an .entitlements file. For convenience, name it like your .app package. Open the file in your favorite text editor and copy the following snippet into it: This is the most basic .entitlements file with near zero capabilities. It worked for our app, because we didn’t need anything special. It might not work for you!
If it doesn't work for you: Unity mentions the Unity Entitlements Tool to easily generate an .entitlements file but the link in the manual is broken. After some search: Here is the download link for the latest version . Luckily I didn't need to use it for our little app, so good luck to you! Make sure you read the guide!
Save the file with the .entitlements ending, for convenience it should be located besides your .app package.
10. Next we’ll need to sign our app. It’s important you have the correct certificate - 'Mac App Distribution' - in your keychain. Fire up the terminal again and navigate to the folder of your your .app package. Then type the following command to sign the package:
Double check that you used the correct profile name! Even a missing space will make the command fail (our correct company name was: 'gentlymad UG (haftungsbeschraenkt) (XXXXXXXXX)'). See your keychain and copy the profile name from there. Also, something the Unity manual doesn’t tell you: Use the --deep parameter to make sure to sign everything in the package.
11. Next we’ll need to build our package. Again, make sure you have the correct profile. This time we need: 'Mac Installer Distribution' in your keychain. In the Terminal we’ll fire the following command:
12. Start the Application Loader. Click on choose and select the newly created package. If you want to get feedback on the status of your app, go to 'Window > Lookup Status…' and type in your SKU/vendor id. You'll see a small list about the status of the import process.
13. Wait for Apple to review your build > ??? > Profit.
Hope this helps you guys out when building for the Mac store. Please leave a comment if you come across any issues!
Cheers,
Matthias Update 13/05/2016
Just found the following shell script that should ease things considerably.https://github.com/DaVikingCode/FromUnityAppToMacAppStore
https://duccgt.weebly.com/blog/best-ear-training-app-mac. 中文 | English
This blog records how to setup and config the application bundle which will be submitted to the AppStore or Steam by using the CLI tools. Mostly, we use XCode for developing iOS and macOS applications, which automatically handles the code signing and configurations. https://duccgt.weebly.com/blog/cannot-move-app-to-bar-mac. But when exporting an app bundle from Unity Editor, we have to do this work by using command line tools that are provided by Apple.
In the begining, let’s get some preliminary knowledege about the
CodeSign and Distributions . Or you can just skip this part then jump into the process parts.
Submit to Steam store or third-party distribution
Submit to macOS AppStore Bundle Config and Code SigningBasic Concepts
Apple provides code signing tool which is called
codesign . In general, the execuatable application in macOS system presents as a folder that has name with .app suffix. It’s different from windows. So for signing the app become more complicated, because we are facing a bunch of files not just a single .exe file.
Designated Requirement(DR)
Every application requires a Designated Requirement(DR) when code signing. The DR is identified by the bundle’s BundleID.
Resource envelope
CodeSign tool will process all sourcefile and non-sourcefile. Every file calculates a hash string, then combined these hashes into a final hash value which will be attched to the application bundle.
Any modification apply to the signed files will change the hash that belonging to this files, and obviously affects final hash. By using this method, other security programs can verify the identity and integrality.
The concept for files signature data is call
Resource envelope .
Resource envelope has two versions, the latest v2 version will check all the files inside the bundle. After OSX Mavericks 10.9, all app use the v2 version.
Even if we didn’t touch the bundle file, any extra file added to the
Game.app bundle folder, will casue the bundle codesign verification failed.
Process application bundle
Modifiy the BundleId
Directly open the Plist file
Game.app/Contents/Info.plist change the value of key CFBundleIdentifier 。
Remove useless files
Unity Edtiro always genereate
.meta files for all the imported macOS library. These .meta file were placed at illegal path for application bundle. And causing the codesign process failed. We must delete them.
Unity Build For LinuxCodeSigning
Signing Third-party libs
Apple requires all the libraries must be signed before submiting to AppStore or Notarization.
All libraries include
.dylib .framework and .bundle .
When submiting to AppStore, the third-party libs must be signed by current
Apple Developer , even if them were codesigned or not. Which means that we also need to codesign the common shared libs such as libssl.dylib .
Entitlements Files
Before use codesign tool, we need to create
.entitlements file. Xcode usually create them for us, but now we are using CLI tools and tackling with exported binary file, don’t we? The entitlements file which used for AppStore submission differ from the Steam one.
The minimal configurations are provided below, other key/value pairs must be added if there have other capabilities.
For macOS AppStore
For Steam
CodeSign Tool
codesign command for signing a single file
Parameter sign should be filled with the name of certificate. Like
Mac Developer:XXXXX(TEAMID) . Codesign tool will search all the certs in user’s keychain, find the correct one. Throwing error when found multiple certs match the inputs.
Command for verification the codesign status.
Success with these outputs.
Submit to SteamStore and non AppStore distribution
The binary app which submitted to SteamStore must be notarized by Apple, otherwise the program will be blocked by GateKeeper when user try to launch the app.
Unity Build Mac App
The specified notarizing docs from Apple Notarizing macOS Software Before Distribution
Generate Certificate
First step is creating a certificate. Signin to the Apple Developer website then generate a
Developer ID Application cert.
Only the account holder of the developer team can create this
Developer ID Application Certificate ,even if the user have admin permission role. Just like any other developer cert, export a CSR file from keychain tool, then upload for swapping a .cert file.
Bundle preparation
Now we have a
Game.app binary bundle, and a Developer ID Application Certificate . But before signing, bundle needs to be preprocessed.
Following the instruction of first part Process-application-bundle.
Fix SteamLib
Most of developer use third-party Steamworks Librlabrecque/Steamworks.NET with Unity, because the VALVE didn’t provide the C# version SDK。Before codesign we needs some patches。
https://duccgt.weebly.com/blog/astropad-mac-app-store. The lib file of
rlabrecque/Steamworks.NET is Steam_api.bundle .
No we have successfully processing the Steamwork library. These rules are also demanded with the other libraries. You should apply the patches if there exist.
CodeSigning
The instruction of apple developer doc recommands that codesign all libs before signing the final bundle. Using
--deep parameter does not guarantee the correctness with nested libraries. It’s just for codesign patching after file modification.
I just write a simple bash script for codesign command execution.
$BINARY = ‘Game.app’
Emphasis:
--sign parameter will automatically match, just input “Developer ID Application:”.
Submit to Notarization
Warning: We should use the command
ditto for archive the budnle, use zip cause the missing of signature infomation
2.Submission
Now we have the ziped bundle. It’s time for notarization.
Parameter
asc-provider requires ProviderShortname .
It’s commonly equals
Team ID which can be found at‘Apple Developer/Membership/Team ID’.
But unfortunately, my apple developer account is pretty old. These are not equal.
Don’t worry, apple provide the tools for quering the ProviderShortName .
If everything gose well, we may get a
RequestId like ‘1809fca2-XXXX-XXXX-XXXX-14aa62f6XXXX’.
With this ReqId, we can query the result of notarization. It needs about 5mins for apple server processing the notarization. Maybe longer depends on the file size.
When processing finish, Apple will send an email to your developer ID.
If the notarization failed, all erros can be find by check the log file.
Please keep in mind that we can’t staple with
Game.app.zip file.Staple only apple to app bundle. When staples successfully, zip the Game.app again, then we can submit it to the user or SteamStore.
Submit to macOS App StoreCertificate Creation
Two different certificate are required when submit to macOS AppStore
Mac App Distribution Certificate is used for bundle CodeSign .
Mac Installer Distribution Certificate is used for pack bundle then uploading to itunes server for review.
Bundle Configuration
Same as Submit-to-SteamStore-and-non-AppStore-distribution
Generate .pkg file
After codesign, we need to pack
Game.app into Game.app.pkg .
Use
productbuild tool
Use AppLoader for uploading
Now we have
Game.app.pkg bundle which is permitted for uploading.
It same process like iOS developement. use application loader tool for uploading to itunes server. Due to the removal of GUI version ApplcaitionLoader with Xcode11,
we can only submit with command line use xcrun altool .
Tips:
xcrun altool --validate-app will not found all the erros, because apple itunes server will do the more stricter validation.
If get some output like
no error uploading package ,means upload successfully.
Apple will also send an email when validation failed. Like this:
App Store Connect: Your app 'XXXXX' (Apple ID: 123456789 Version: 1.0 Build: 0) has one or more issues
But if the validation got through, no email sent. Remember to check the itunes connect dashboard.
Fix all the errors that apple email mentions. After solve the errors, the process steps of codesign->pkg->upload must be executed completely. Do not forget to increse the build version number.
Every uploading task requires different build version number. FAQ
I just list some common errors.
code object is not signed at all In subcomponent: PATH_TO_THE_FILE.
Delete these files before codesign.
Unity Build And Run
Some libs are not signed, or signed with incorrect cert.
The certificate is out-of-date, download the new one.
Unity Mac Build On Windows
If you do the
codesign or productbuild via ssh, you should unlock the keychain with CLI. Because some process require user password to unlock the keychain. There is no password dialog pop up when these program request an access to the keychain.
Unity Mac App Builder
Reference
Unity Manual: Delivering your application to the Mac App Store
gist:how-to-notarize-unity-for-macos.md Notarizing macOS Software Before Distribution Technical Note TN2206:macOS Code Signing In Depth
Thanks for reading, If there are any mistake or question, feel free to leave a comment below.
Comments are closed.
|
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |