Flutter Packaging and Release

This section covers how to package and publish Flutter applications to various platforms.


Build preparation

Before release, ensure the app is configured correctly.

pubspec.yaml Configuration

Example: Publishing Configuration

# Application Info
name
: my_app
description
: "My Flutter App"
version
: 1.0.0+1  # Version number (important!)

# App Icon
flutter
:
  uses-material-design
: true
  # Generating icons requires flutter pub run flutter_launcher_icons

Android configuration

Modify the application configuration in android/app/build.gradle:

Example: Android Configuration

// android/app/build.gradle

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

    defaultConfig {
applicationId "com.example.myapp" // application ID
minSdk = 21 // Minimum Android version
targetSdk = 34 // target version
versionCode 1 // Version code (increments with each release)
versionName "1.0.0" // version name
    }

    signingConfigs {
        release {
// Release signing configuration
            storeFile file("key.jks")
storePassword "password"
keyAlias "alias"
keyPassword "key password"
        }
    }
}

Android Build

Build APK

# 调试 APK
$ flutter build apk --debug

# 发布 APK
$ flutter build apk --release

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

Build App Bundle

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

iOS Build

Prerequisites

  • Install Xcode
  • Configure Apple Developer Account
  • Create App ID and Certificate

Command-line build

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

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

Build with Xcode

  1. Open the .xcworkspace file in the ios/ directory
  2. Selecting target devices and Signing configuration
  3. Click Product > Archive

Web Build

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

# 输出目录:build/web/

Web Configuration

Configure the application in web/index.html:

Example: Web Configuration

<!DOCTYPE html>
<html>
<head>
  <base href="/">
  <title>My Apps</title>
  <meta name="description" content="Flutter App">
  <!-- PWA support -->
  <link rel="manifest" href="manifest.json">
</head>
<body>
  <script src="flutter.js" defer></script>
</body>
</html>

Desktop Application Build

# Windows
$ flutter build windows --release

# macOS
$ flutter build macos --release

# Linux
$ flutter build linux --release

Before publishing, be sure to test the release version of your app; the debug version may contain additional debug information.

other extensions