Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

Flutter Packaging and Publishing

Flutter Packaging and Publishing

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


Build Preparation

Before publishing, ensure the application is configured correctly.

pubspec.yaml configuration

Example: Release Configuration

Application Information

name

:

my_app

description

:

"My Flutter App"

version

:

1.0.0+

1

 

Version number (important!)

Application 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 (incremented on 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



# With signature (requires configuring signingConfigs)

$ flutter build apk --release --target-platform android-arm64

Build App Bundle



# Build App Bundle (recommended for Google Play)

$ flutter build appbundle --release


iOS Build

Preparation

Command-line build



# Simulator version

$ flutter build ios --simulator --no-codesign



# Release version (requires signing)

$ flutter build ipa --release

Build using Xcode

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

Web Build



# Build Web version

$ flutter build web --release



# Output directory: build/web/

Web Configuration

Configure the application in web/index.html:

Example: Web Configuration

 

 

<p>My App</p>

 

 

 

 


Desktop Application Build



# Windows

$ flutter build windows --release



# macOS

$ flutter build macos --release



# Linux

$ flutter build linux --release

Be sure to test the release version of the application before publishing; the debug version may contain additional debug information.