exporting_for_ios.rst 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. .. _doc_exporting_for_ios:
  2. Exporting for iOS
  3. =================
  4. .. seealso::
  5. This page describes how to export a Godot project to iOS.
  6. If you're looking to compile export template binaries from source instead,
  7. read :ref:`doc_compiling_for_ios`.
  8. These are the steps to load a Godot project in Xcode. This allows you to
  9. build and deploy to an iOS device, build a release for the App Store, and
  10. do everything else you can normally do with Xcode.
  11. .. attention::
  12. Projects written in C# can be exported to iOS as of Godot 4.2, but support
  13. is experimental and :ref:`some limitations apply <doc_c_sharp_platforms>`.
  14. Requirements
  15. ------------
  16. - You must export for iOS from a computer running macOS with Xcode installed.
  17. - Download the Godot export templates. Use the Godot menu: Editor > Manage Export Templates
  18. Export a Godot project to Xcode
  19. -------------------------------
  20. In the Godot editor, open the **Export** window from the **Project** menu. When the
  21. Export window opens, click **Add..** and select **iOS**.
  22. The **App Store Team ID** and (Bundle) **Identifier** options in the **Application** category
  23. are required. Leaving them blank will cause the exporter to throw an error.
  24. .. note:: | If you encounter an error during export similar to
  25. | ``JSON text did not start with array or object and option to allow fragments not set``
  26. | then it might be due to a malformated **App Store Team ID**!
  27. | The exporter expects a (10 characters long) code like ``ABCDE12XYZ`` and not, e.g., your name as Xcode likes to display in the *Signing & Capabilities* tab.
  28. | You can find the code over at `developer.apple.com <https://developer.apple.com/account/resources/certificates/list>`_ next to your name in the top right corner.
  29. After you click **Export Project**, there are still two important options left:
  30. * **Path** is an empty folder that will contain the exported Xcode project files.
  31. * **File** will be the name of the Xcode project and several project specific files and directories.
  32. .. image:: img/ios_export_file.webp
  33. .. note:: This tutorial uses **exported_xcode_project_name**, but you will use your
  34. project's name. When you see **exported_xcode_project_name**
  35. in the following steps, replace it with the name you used instead.
  36. .. note:: Avoid using spaces when you choose your **exported_xcode_project_name** as
  37. this can lead to corruption in your XCode project file.
  38. When the export completes, the output folder should look like this:
  39. .. image:: img/ios_export_output.webp
  40. .. warning::
  41. Exporting for the iOS simulator is currently not supported as per
  42. `GH-102149 <https://github.com/godotengine/godot/issues/102149>`__.
  43. Apple Silicon Macs can run iOS apps natively, so you can run exported iOS projects
  44. directly on an Apple Silicon Mac without needing the iOS simulator.
  45. Opening **exported_xcode_project_name.xcodeproj** lets you build and deploy
  46. like any other iOS app.
  47. Active development considerations
  48. ---------------------------------
  49. The above method creates an exported project that you can build for
  50. release, but you have to re-export every time you make a change in Godot.
  51. While developing, you can speed this process up by linking your
  52. Godot project files directly into your app.
  53. In the following example:
  54. * **exported_xcode_project_name** is the name of the exported iOS application (as above).
  55. * **godot_project_to_export** is the name of the Godot project.
  56. .. note:: **godot_project_to_export** must not be the same as **exported_xcode_project_name**
  57. to prevent signing issues in Xcode.
  58. Steps to link a Godot project folder to Xcode
  59. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  60. 1. Start from an exported iOS project (follow the steps above).
  61. 2. In Finder, drag the Godot project folder into the Xcode file browser.
  62. .. image:: img/ios_export_add_dir.webp
  63. 3. In the dialog, make sure to select Action: **Reference files in place** and Groups: **Create folders**. Uncheck Targets: **exported_xcode_project_name**.
  64. .. image:: img/ios_export_file_ref.webp
  65. 4. See the **godot_project_to_export** folder in the Xcode file browser.
  66. 5. Select the godot project in the Project navigator. Then on the other side of the XCode window, in the File Inspector, make these selections:
  67. * **Location**: Relative to Project
  68. * **Build Rules**: Apply Once to Folder
  69. * add your project to **Target Membership**
  70. .. image:: img/ios_export_file_inspector.webp
  71. .. image:: img/ios_export_target_membership.webp
  72. 7. Delete **exported_xcode_project_name.pck** from the Xcode project in the project navigator.
  73. .. image:: img/ios_export_delete_pck.webp
  74. 8. Open **exported_xcode_project_name-Info.plist** and add a string property named
  75. **godot_path** (this is the real key name) with a value **godot_project_to_export**
  76. (this is the name of your project)
  77. .. image:: img/ios_export_set_path.webp
  78. That's it! You can now edit your project in the Godot editor and build it
  79. in Xcode when you want to run it on a device.
  80. Plugins for iOS
  81. ---------------
  82. Special iOS plugins can be used in Godot. Check out the
  83. :ref:`doc_plugins_for_ios` page.
  84. Environment variables
  85. ---------------------
  86. You can use the following environment variables to set export options outside of
  87. the editor. During the export process, these override the values that you set in
  88. the export menu.
  89. .. list-table:: iOS export environment variables
  90. :header-rows: 1
  91. * - Export option
  92. - Environment variable
  93. * - Encryption / Encryption Key
  94. - ``GODOT_SCRIPT_ENCRYPTION_KEY``
  95. * - Options / Application / Provisioning Profile UUID Debug
  96. - ``GODOT_IOS_PROVISIONING_PROFILE_UUID_DEBUG``
  97. * - Options / Application / Provisioning Profile UUID Release
  98. - ``GODOT_IOS_PROVISIONING_PROFILE_UUID_RELEASE``
  99. Troubleshooting
  100. ---------------
  101. xcode-select points at wrong SDK location
  102. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  103. xcode-select is a tool that comes with Xcode and among other things points at iOS SDKs on your Mac.
  104. If you have Xcode installed, opened it, agreed to the license agreement, and installed the command line tools,
  105. xcode-select should point at the right location for the iPhone SDK.
  106. If it somehow doesn't, Godot will fail exporting to iOS with an error that may look like this:
  107. ::
  108. MSB3073: The command ""clang" <LOTS OF PATHS AND COMMAND LINE ARGUMENTS HERE>
  109. "/Library/Developer/CommandLineTools/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk"" exited with code 1.
  110. In this case, Godot is trying to find the ``Platforms`` folder containing the iPhone SDK inside the
  111. ``/Library/Developer/CommandLineTools/`` folder, but the ``Platforms`` folder with the iPhone SDK is
  112. actually located under ``/Applications/Xcode.app/Contents/Developer``. To verify this, you can open
  113. up Terminal and run the following command to see what xcode-select points at:
  114. ::
  115. xcode-select -p
  116. To fix xcode-select pointing at a wrong location, enter this command in Terminal:
  117. ::
  118. sudo xcode-select -switch /Applications/Xcode.app
  119. After running this command, Godot should be able to successfully export to iOS.
  120. Export options
  121. --------------
  122. You can find a full list of export options available in the
  123. :ref:`class_EditorExportPlatformIOS` class reference.