Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
@Article(time: 30) {
@Intro(title: "Build Game2048 for Android") {
Build the Game2048 sample as an Android APK and play it on an arm64 device or emulator.
}

## Get the sample

On macOS or Linux, use Git to clone the [`android/dev` branch of OpenSwiftUI-Samples](https://github.com/OpenSwiftUIProject/OpenSwiftUI-Samples/tree/android/dev).
Run the remaining commands from the root of this checkout.

```sh
git clone --branch android/dev \
https://github.com/OpenSwiftUIProject/OpenSwiftUI-Samples.git samples-android
cd samples-android
```

## Prepare the build tools

Install Make, Python 3, and JDK 17 or later.
Use [Swiftly](https://www.swift.org/install/) to install the Swift 6.3.2 toolchain.

```sh
swiftly install 6.3.2
```

Install the [Android SDK command-line tools](https://developer.android.com/tools/sdkmanager).
Set `ANDROID_HOME` to the Android SDK directory. Add its `cmdline-tools/latest/bin`
and `platform-tools` directories to your `PATH`. Install Android SDK Platform 35,
the platform tools, and Android NDK r27d.

```sh
sdkmanager "platforms;android-35" "platform-tools" "ndk;27.3.13750724"
```

Install the matching Swift SDK for Android and link it to the NDK. This command
also fetches OpenSwiftUI and the other dependencies for the sample.

```sh
make android_setup ANDROID_INSTALL_SDK=1
```

## Build the APK

To build Game2048 without a device, run the following command.

```sh
make android SAMPLE=Game2048
```

The debug APK is at `Android/dist/Game2048/Game2048-debug-arm64-v8a.apk`.

## Play the game

Connect a device with USB debugging enabled, or start a virtual device in
Android Studio’s Device Manager. Use an `arm64-v8a` device or system image with
API level 28 or later. When `adb devices` lists one device with status `device`,
build, install, and launch Game2048 with one command.

```sh
make android_run SAMPLE=Game2048
```

@ContentAndMedia {
Swipe across the board to move the tiles. When two tiles with the same
number merge, the score increases.

@Image(source: game2048-android.png, alt: "Game2048 on an Android phone, with numbered tiles and the score above the board.")
}

To select a device by serial number or start a named emulator, see the
[Android build guide](https://github.com/OpenSwiftUIProject/OpenSwiftUI-Samples/blob/android/dev/Docs/OpenSwiftUI.md#android-build-and-deployment).
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
@Article(time: 20) {
@Intro(title: "Build Game2048 for WASI") {
Compile Game2048 for the WebAssembly System Interface (WASI), then serve
the game from your computer and play it in a browser.
}

## Get the sample

On macOS or Linux, use Git to clone the [`wasi/dev` branch of OpenSwiftUI-Samples](https://github.com/OpenSwiftUIProject/OpenSwiftUI-Samples/tree/wasi/dev).
Run the remaining commands from the root of this checkout.

```sh
git clone --branch wasi/dev \
https://github.com/OpenSwiftUIProject/OpenSwiftUI-Samples.git samples-wasi
cd samples-wasi
```

## Prepare the build tools

Install Make and Python 3. Use
[Swiftly](https://www.swift.org/install/) to install the Swift 6.3.2 toolchain.

```sh
swiftly install 6.3.2
```

Install the matching Swift SDK for WebAssembly and fetch the sample’s dependencies.

```sh
make web_setup WEB_INSTALL_SDK=1
```

## Build the web bundle

To build Game2048 as a static site, run the following command.

```sh
make web SAMPLE=Game2048
```

The `Web/dist/Game2048/` directory contains `index.html` and the compiled game
in `Bundle/Game2048Web.wasm`. To deploy the game, publish the entire directory
to a static web host.

## Play the game

To build the game and serve it locally, run the following command.

```sh
make web_run SAMPLE=Game2048
```

@ContentAndMedia {
Open `http://127.0.0.1:8000/` in your browser. Click the board and use
the arrow keys to move the tiles. Press Control-C in the terminal to stop
the server.

@Image(source: game2048-web.png, alt: "Game2048 in a browser window with a four-by-four board and a score above it.")
}

For a different port or output directory, see the
[web build guide](https://github.com/OpenSwiftUIProject/OpenSwiftUI-Samples/blob/wasi/dev/Docs/OpenSwiftUI.md#web-build-and-deployment).
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
@Article(time: 15) {
@Intro(title: "Build Game2048 for macOS") {
Build the Game2048 sample with OpenSwiftUI and play it in a window on your Mac.
}

## Get the sample

Install Xcode 26.6 or later and mise. Clone the
[`main` branch of OpenSwiftUI-Samples](https://github.com/OpenSwiftUIProject/OpenSwiftUI-Samples/tree/main).

```sh
git clone --branch main \
https://github.com/OpenSwiftUIProject/OpenSwiftUI-Samples.git samples-macos
cd samples-macos
```

## Generate the Xcode workspace

From the root of the checkout, run the setup target. It uses mise to install
Tuist and generates `OpenSwiftUISamples.xcworkspace`, which includes the
`Game2048App` scheme. The default configuration builds OpenSwiftUI from source.

```sh
make apple_setup
```

## Build and play the game

Build Game2048 and open it on your Mac.

```sh
make macOS_run SAMPLE=Game2048
```

@ContentAndMedia {
Use the arrow keys to slide the tiles. When two tiles with the same
number merge, the score increases. Click the restart button to start
a new game.

@Image(source: game2048-macos.png, alt: "A macOS window with the Game2048 board, score, and restart button.")
}

To build the app without launching it, run `make macOS SAMPLE=Game2048`.
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,24 @@
set up data flow, and build the navigation while watching it unfold in
Xcode’s preview.
}

@Chapter(name: "Build Cross-Platform Game2048") {
Game2048 uses the same Swift views for its board, tiles, and score on
macOS, iOS, Android, and the web.

On a Mac with Xcode and mise installed, clone the
[`main` branch of OpenSwiftUI-Samples](https://github.com/OpenSwiftUIProject/OpenSwiftUI-Samples/tree/main#build-and-run).
From the root of the checkout, run `make apple_setup`. Then run
`make macOS_run SAMPLE=Game2048` to play on your Mac or
`make iOS_run SAMPLE=Game2048` to play in an iOS simulator.

Follow the Android tutorial to build an APK from `android/dev` or the
WASI tutorial to build a static web bundle from `wasi/dev`. All three
branches also accept `SAMPLE=HelloWorld` in the build and run commands.

@Image(source: game2048-macos.png, alt: "Game2048 running in a macOS window.")
@TutorialReference(tutorial: "doc:Build-Game2048-for-macOS")
@TutorialReference(tutorial: "doc:Build-Game2048-for-Android")
@TutorialReference(tutorial: "doc:Build-Game2048-for-WASI")
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion Sources/OpenSwiftUI/OpenSwiftUI.docc/OpenSwiftUI.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ You can integrate OpenSwiftUI views with objects from the [UIKit](https://develo

## Topics

### Esentials
### Essentials

- <doc:Introducing-OpenSwiftUI>

Expand Down
Loading