nsgo.yaml
每次建置都讀取的專案檔:目標、建置參數與標籤、最低系統版本、圖示和啟動畫面。
name: Helloid: dev.example.hello # the bundle ID; without it, dev.nsgo. and the name's letters and digitsversion: 0.1.0build_number: 1 # CFBundleVersion and Android's versionCode; else from version# copyright: © 2026 Example # the Windows executable's details and installer, and the macOS About panel# appearance: dark # light or dark whatever the system's# i18n: { dir: locales, source: en } # the app's catalogs and the language they are written inicon: apple: assets/AppIcon.icon # macOS, iOS and watchOS, or an .icns for macOS windows: assets/IconWindows.png # optional Windows artwork linux: assets/IconLinux.png # optional Linux artwork png: assets/Icon.png # every other target tvos: assets/AppIconTV.brandassets # the Apple TV's layered icon and top shelf art, or a wide PNG watchos: assets/AppIconWatch.icon # the Apple Watch's own, drawn in circles, or a square PNG android: png: assets/IconAndroid.png # optional bitmap; valid without adaptive layers foreground: assets/IconForeground.png # Android's adaptive icon: 432 px, the logo within the center 264 px background: "#1F1F1F" # a color or a square PNG monochrome: assets/IconMonochrome.png # optional: the shape Android 13's themed icons tintdev: target: native # native, web, ios, ios_simulator, tvos, tvos_simulator, watchos, watchos_simulator, android, harmonyos or miniprogram_<platform> hot_reload: true # false builds once, watching no files # icon: { png: assets/Icon-dev.png } # replaces icon's files in dev's builds; defaults to assets/*-dev.*build: output: dist tags: [] # Go build tags every build, test and check of the app takes, such as timetzdata ldflags: [] # the app's own linker flags, such as -X main.releaseDate=2026-11-17 open: false # true opens the output directory after building installers: true # false leaves out the disk image, the Windows installer and the Linux packages jobs: 0 # how many targets build at once; 0 is half the CPUs, 1 one after another targets: [macos_arm64, macos_x64, windows_arm64, windows_x64, linux_arm64, linux_x64, ios, ios_simulator, tvos, tvos_simulator, watchos, watchos_simulator, android_arm64, web]# apple: { sign_in_with_apple: true } # the Sign in with Apple entitlement, for iOS, tvOS and Mac App Store builds# apple: { purchases: true } # StoreKit's library, which in-app purchases go through, in macOS, iOS and tvOS packages# apple: { privacy: { accessed_apis: { NSPrivacyAccessedAPICategoryDiskSpace: [E174.1] }, tracking: false } } # add required-reason APIs and tracking declarations to PrivacyInfo.xcprivacy# apple: { requires_full_screen: false } # let an iPad run the app in Split View, Slide Over and Stage Manager, in all four orientations# apple: { orientations: [portrait, landscape_left] } # the orientations a full-screen app takes on an iPad# apple: { multiple_scenes: true } # let an iPad open more than one window of the app, each showing the main view with its own state# apple: { info: { UIBackgroundModes: [audio] } } # background playback for iOS Picture in Picture# android: { permissions: [REQUEST_INSTALL_PACKAGES] } # manifest permissions beyond the runtime's# android: { recording: true } # the microphone service microphone.RecordWAV records in, with RECORD_AUDIO, the foreground-service permissions and POST_NOTIFICATIONS, which RecordWAV asks for so its notification shows from Android 13; a refusal still records# android: { uses_cleartext_traffic: true } # allow plain HTTP to any host in the APK and App Bundle# android: { background_downloads: true } # dataSync foreground service for cx.Download# android: { background_motion: true } # explicit finite motion shortService; streams also need a notification title# android: { loopback_cleartext: true } # allow plain HTTP to loopback in the APK and App Bundle# commands: [{ name: hello-cli, package: ./cmd/hello-cli }] # command-line programs the desktop packages ship beside the app: see Commands# windows: { command_line: true } # add <name>.com, a console companion that forwards arguments and streams to <name>.exe; not in store builds# windows: { path: true } # the installer puts the app's folder on the user's Path, so consoles find its commands# windows: { publisher: Example Ltd } # the company the Windows executable's details, its installer and the uninstall entry name; else windows.store.publisher_name# linux: { maintainer: "Jane Doe <jane@example.com>" } # the Linux packages' maintainer, else the app's name# linux: { categories: [Office, Dictionary] } # the freedesktop menu categories of the app's desktop entry, at least one a main category such as Office, Utility or Game, else menus file it under Other; your own start with X-# linux: { share: packaging/share } # files the .deb and Arch package install under /usr/share and the AppImage in its usr/share, such as metainfo/<id>.metainfo.xml or bash-completion/completions/<command># linux: { depends: { deb: [gstreamer1.0-plugins-good], arch: [gst-plugins-good] }, recommends: { deb: [gstreamer1.0-libav], arch: ["gst-libav: H.264 and AAC video"] } } # packages the .deb and Arch package also depend on and recommend, after GTK 4 and WebKitGTK 6, each as dpkg or pacman writes it# release: { github: me/hello } # the GitHub repository the install scripts and updates install from, else the Git remote origin's; tag_prefix: v by default# updates: { key: <public key> } # how the app updates, by platform and channel: see Updates# store: { dir: store } # store listings directory (YAML and Markdown per language)# miniprogram: { appid: { wechat: wx0123456789abcdef, alipay: "2021000000000000" }, custom_navigation: false } # the mini programs'在 targets 中(或在 nsgo build -target 與 nsgo check -target 中)僅寫作業系統名稱,代表包含其所有架構(windows 即代表 windows_arm64 與 windows_x64;android 僅代表 android_arm64,因為 x86_64 建置需要 NDK)。macos_universal(未包含在 macos 與 all 中)會同時建置兩種 macOS 架構並將其合併為單一應用程式,包含其函式庫與小工具。Steam 渠道會使用通用應用程式套件。安裝程式建置會將其打包為單一磁碟映像檔,並在直接發佈渠道上產生單一 Sparkle 訂閱源。nsgo test -target 也接受測試執行的目標架構名稱:桌面作業系統對應本機架構,Android 對應 arm64,因此在 x64 Windows 機器上執行 windows_x64 會執行 windows 目標測試,而若指定該目標無法執行的架構則會被拒絕並提示應使用的名稱。
參數、標籤與連結器參數
Section titled “參數、標籤與連結器參數”命令列旗標會覆寫對應名稱的設定,例如 -target、-version 或 -output;執行 -h 可列出所有旗標。
build.ldflags 存放應用程式自訂的連結器旗標,寫法與 go build 的 -ldflags 相同,例如 -X main.releaseDate=2026-11-17 或 -X 'main.channel=beta builds'。每個連結應用程式的建置都會套用它們:包含 dev 及其重新載入、build(含 -embed)以及所有目標上的 test -target。在 build 與 test 上傳入的 -ldflags 會附加於設定之後而非取代,可重複指定多個。它們位於工具自身 -X 旗標之前,且連結器會保留同一變數的最後一個值,因此 core.App 中的名稱、ID 與版本號仍會維持 nsgo.yaml 的設定。工具會傳遞自身的 -ldflags 給 go(這會取代 GOFLAGS 中的設定),因此連結器旗標應寫在此處;而在無頭模式 test 中位於目錄參數之後的 -ldflags 則是 go test 的參數,會全部取代原有設定。
工具為應用程式執行的每個 go 命令都會帶入 build.tags,涵蓋 dev 及其重新載入、build(含 -embed)、test -target 與 check,適用於所有目標平台。NSGo 自身的標籤(例如 dev 中的 nsgodev 或目標測試中的 nsgotest)會加入其中,GOFLAGS 中 -tags 的標籤也會一併保留以免被覆寫;GOFLAGS 的其餘旗標則原封不動套用。
每個建置在啟動時也都接受 NSGo 自身的命令列旗標,例如 --nsgo-fps(執行與除錯)。在 nsgo dev 中,Command/Control+R 可從任一開啟的視窗觸發重新載入,且即使主視窗關閉,只要仍有其他視窗保持應用程式函式執行,此快捷鍵依然有效。
最低系統版本
Section titled “最低系統版本”apple.info.LSMinimumSystemVersion 會提高 macOS 封裝檔的最低系統版本需求,而 apple.info.MinimumOSVersion 則會提高所選 iOS、tvOS 或 watchOS 封裝檔的最低版本需求。請填寫加引號的版本字串,例如 "14.2" 或 "18.0",包含一至三個數字部分。執行階段的最低底線分別為 macOS 13.0(Go 1.27)、iOS 15.0、tvOS 17.0 與 watchOS 26.0;低於底線或格式錯誤的值將會失敗。行動裝置鍵值必須滿足所有已選取行動目標的底線。App Clip 保留自身的 app_clip.minimum。這些數值會套用至封裝中繼資料、資源編譯、簽署專案以及應用程式的連結器;嵌入的 iOS 框架也會使用這些數值,其中 Mac Catalyst 為支援 Go 的 macOS 13 執行階段,最低須為 16.0。
icon.windows 與 icon.linux 用於為各自的應用程式封裝檔、安裝程式圖示與商店標誌選擇正方形 PNG 圖片。預設路徑為 assets/IconWindows.png 與 assets/IconLinux.png,若不存在則退回使用 icon.png;dev.icon 接受相同的設定與 -dev 預設檔名。icon.android.png 可獨立選擇 Android 點陣圖圖示,即使未設定自適應圖層亦有效。其他目標則保留共用的 icon.png 作為後備。
Apple TV 的圖示是一張分層卡片而非正方形:tvos 接受 Xcode 的 .brandassets(包含其 App Icon 圖層堆疊與 Top Shelf 圖片),或是一張寬幅圖片(如 1280×768),工具會將其縮放填滿卡片並依邊緣顏色襯底,同時置中於 Top Shelf 圖片上。若兩者皆無,則會將 PNG 置於卡片高度四分之三大小的位置。Apple Watch 會將圖示裁剪為圓形,因此 watchos 接受專為 watchOS 圓形繪製的 .icon 或正方形 PNG;若未設定,則依序退回使用 apple 與 png。兩者皆會如同 apple 與 png 一樣,自動尋找預設檔案 assets/AppIconTV.* 與 assets/AppIconWatch.*。
在 Android 上,icon.android.foreground 與 background 會組成自適應啟動器圖示(adaptive icon),讓啟動器能將其裁剪為各自形狀並套用動態位移,而不是將 png 縮小貼在預設底板上。每個圖層尺寸為 108 dp 正方形(即縮放至 432 px 的 PNG);啟動器會顯示中央 72 dp(288 px)區域,並可能裁掉中央 66 dp(264 px)圓圈以外的所有內容,因此請將標誌保留在該圓圈內,並讓背景填滿整個正方形。background 可以是 PNG 圖片或色碼(例如 "#1F1F1F")。monochrome 是一個僅看 Alpha 透明度的形狀圖層,供 Android 13 及以上版本在使用者開啟主題圖示時進行著色;若未提供,該圖示將維持原色。封裝檔會保留 icon.android.png(否則為 icon.png)作為一般點陣圖圖示,不過 Android 9(NSGo 支援的最舊版本)以上的啟動器都會優先採用自適應圖示;若未提供 png,工具會將前景疊加在背景上繪製產生。若未設定自適應圖層,啟動器就會顯示 Android 點陣圖或共用的 png。
設定 launch_screen 可在 iOS 與 Android 12 及以上版本顯示不透明背景、置中 PNG 圖片,或兩者兼有。圖片路徑相對於 nsgo.yaml。圖片會等比例縮放至 128 × 128 點或 dp 範圍內。使用長邊至少 512 像素的透明 PNG 可在高密度螢幕上保持銳利。
launch_screen: background: "#F5F1EA" image: assets/Launch.png dark: background: "#201C26" image: assets/LaunchDark.png除非 appearance 鎖定了外觀,否則系統會自動選擇淺色或深色外觀。省略 dark 中的任一欄位時會沿用對應的淺色設定值。省略背景或圖片則會保留平台的預設行為。嵌入式應用程式的啟動畫面由宿主應用程式提供。
Android 上的明文 HTTP
Section titled “Android 上的明文 HTTP”android.uses_cleartext_traffic: true 會允許 APK 或 App Bundle 向任意主機發送未加密的明文 HTTP 請求,同時設定 manifest 旗標與網路安全性設定。若未開啟此項,android.loopback_cleartext: true 則僅允許對 localhost、127.0.0.1 與 ::1 使用明文 HTTP(例如由應用程式自身提供服務的影片)。僅限本機迴圈的原則會拒絕其他主機的明文流量;當兩項設定皆為 true 時,允許所有主機的設定優先。對於嵌入式的 AAR,請在宿主應用程式的 Android 網路安全性設定中進行組態。
Android 原生類別
Section titled “Android 原生類別”在應用程式的 nsgo.yaml 中列出預先編譯的 Android 類別,即可在 core.Native 中使用自訂 View。
android: classes: [java/BadgeView.jar, java/Helpers.dex]除非使用絕對路徑,否則路徑皆相對於 nsgo.yaml。每個路徑指向一個 .dex 檔案,或包含 D8 根目錄 classes.dex、classes2.dex 及後續分片的 JAR 檔案。請使用 D8 搭配 --min-api 28 準備這些檔案。在 arm64 上,NSGo 僅憑 Go 即可從這些預先編譯的檔案建置出 APK 或 App Bundle。當列出的檔案變更時,Android 開發工作階段會自動重新建置。對於嵌入式的 AAR,由宿主應用程式的 Android 建置負責提供其 Java 相依性。D8 文件
Android 原生範例示範了如何註冊一個帶有公開 Context 建構函式的類別,並透過 Go prop 進行組態。