1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

【Swift SDK For Android】Hello, Worldを出力する

Last updated at Posted at 2025-10-30

概要

  • Swift SDK For AndroidでHello, World!!を出力する。

Swift SDK For Androidの環境構築が済んでいる方が対象の記事です。
まだの方は以下の記事をご覧ください。

手順

1. 任意のディレクトリに移動する

$ cd SampleProject

2. Swiftに新しいパッケージを作ってもらう

  • 自分の場合はディレクトリの名前をSwiftForAndroidという名前にしました。そのフォルダ名に対応するSwiftファイルを自動で作ってくれています。
$ swiftly run swift package init --type executable

Creating executable package: SwiftForAndroid
Creating Package.swift
Creating .gitignore
Creating Sources
Creating Sources/SwiftForAndroid/SwiftForAndroid.swift

3. ビルド

3-1. コンパイルを行う

$ swiftly run swift build

Building for debugging...
ld: warning: building for macOS-11.0, but linking with dylib '/usr/lib/swift/libswiftCore.dylib' which was built for newer version 13.0
ld: warning: building for macOS-11.0, but linking with dylib '/usr/lib/swift/libswiftSwiftOnoneSupport.dylib' which was built for newer version 13.0
[8/8] Applying SwiftForAndroid
Build complete! (5.28s)
  • 筆者環境がMac0S-11.0なので、13.0以上にしてほしいというwarningが発生しています

3-2. ビルドする

$ .build/debug/{YOUR_PROJECT_NAME}

ドキュメントではhelloとなっていますが自分のプロジェクト名を指定してください

結果

  • 無事Hello, Worldが出力されました。
Hello, world!

追記

  • 2025年10月30日現在、snapshotのモジュールがSwift6.3でコンパイルされているらしく、最新版のSwift6.2とは互換性がなく、ターミナルで進められるのはここまでのようだと、私は思っています。
 $ swiftly run swift build --swift-sdk x86_64-unknown-linux-android28 --static-swift-stdlib
Building for debugging...
error: emit-module command failed with exit code 1 (use -v to see invocation)

<unknown>:0: error: module compiled with Swift 6.3 cannot be imported by the Swift 6.2 compiler: /Users/省略/Library/org.swift.swiftpm/swift-sdks/swift-DEVELOPMENT-SNAPSHOT-2025-10-16-a-android-0.1.artifactbundle/swift-android/swift-resources/usr/lib/swift_static-x86_64/android/Swift.swiftmodule/x86_64-unknown-linux-android.swiftmodule
  • 下記の記事を見るにサンプルリポジトリ自体は公開されているのでAndroid Studio経由でビルドするとSwiftForAndroidのサンプルアプリを起動できるようです。

参考

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?