Flutter パッケージングとリリース

このセクションでは、Flutter アプリを各プラットフォームにパッケージングしてリリースする方法を紹介します。


ビルドの準備

リリース前に、アプリ設定が正しいことを確認してください。

pubspec.yaml の設定

例:リリース設定

# アプリ情報
name
: my_app
description
: "私の Flutter アプリ"
version
: 1.0.0+1  # バージョン番号(重要!)

# アプリアイコン
flutter
:
  uses-material-design
: true
  # アイコン生成には flutter pub run flutter_launcher_icons が必要です

Android の設定

android/app/build.gradle のアプリ設定を変更します:

例:Android の設定

// android/app/build.gradle

android {
    namespace "com.example.myapp"
    compileSdk = 34

    defaultConfig {
applicationId "com.example.myapp" // アプリ ID
minSdk = 21 // 最低 Android バージョン
targetSdk = 34 // ターゲットバージョン
versionCode 1 // バージョンコード(リリースごとに増加)
versionName "1.0.0" // バージョン名
    }

    signingConfigs {
        release {
// リリース署名設定
            storeFile file("key.jks")
storePassword "パスワード"
keyAlias "エイリアス"
keyPassword "キーパスワード"
        }
    }
}

Android のビルド

APK のビルド

# 调试 APK
$ flutter build apk --debug

# 发布 APK
$ flutter build apk --release

# 带签名(需要配置 signingConfigs)
$ flutter build apk --release --target-platform android-arm64

App Bundle のビルド

# 构建 App Bundle(推荐用于 Google Play)
$ flutter build appbundle --release

iOS のビルド

事前準備

  • Xcode をインストールします
  • Apple 開発者アカウントを設定します
  • App ID と証明書を作成します

コマンドラインでのビルド

# 模拟器版本
$ flutter build ios --simulator --no-codesign

# 发布版本(需要签名)
$ flutter build ipa --release

Xcode を使用したビルド

  1. ios/ ディレクトリで .xcworkspace ファイルを開きます
  2. ターゲットデバイスと Signing 設定を選択します
  3. Product > Archive をクリックします

Web のビルド

# 构建 Web 版本
$ flutter build web --release

# 输出目录:build/web/

Web の設定

web/index.html でアプリを設定します:

例:Web の設定

<!DOCTYPE html>
<html>
<head>
  <base href="/">
  <title>私のアプリ</title>
  <meta name="description" content="Flutter アプリ">
  <!-- PWA サポート -->
  <link rel="manifest" href="manifest.json">
</head>
<body>
  <script src="flutter.js" defer></script>
</body>
</html>

デスクトップアプリのビルド

# Windows
$ flutter build windows --release

# macOS
$ flutter build macos --release

# Linux
$ flutter build linux --release

リリース前に必ずアプリのリリースバージョンをテストしてください。デバッグバージョンには追加のデバッグ情報が含まれている場合があります。

その他の拡張