SoFunction
Updated on 2025-04-04

How to publish Android apps using Flutter

Set the name of the application, package name, application icon and launch

Android application resource configuration is set in main/, and the file content is as follows:

<manifest xmlns:andro
    package=".gesture_demo">
    <!--  is an  that
         calls (this); in its onCreate method.
         In most cases you can leave this as-is, but you if you want to provide
         additional functionality it is fine to subclass or reimplement
         FlutterApplication and put your custom class here. -->
    <application
        android:name=""
        android:label="gesture_demo"
        android:icon="@mipmap/ic_launcher">
        <activity
            android:name=".MainActivity"
            android:launchMode="singleTop"
            android:theme="@style/LaunchTheme"
            android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
            android:hardwareAccelerated="true"
            android:windowSoftInputMode="adjustResize">
            <intent-filter>
                <action android:name=""/>
                <category android:name=""/>
            </intent-filter>
        </activity>
        <!-- Don't delete the meta-data below.
             This is used by the Flutter tool to generate  -->
        <meta-data
            android:name="flutterEmbedding"
            android:value="2" />
    </application>
</manifest>

The recommended file generated by Flutter is that most of the content can be retained, but can be modified as needed.
The specific content that may be modified is as follows:

Attribute name use illustrate
package Application package name The unique identifier of an Android application, generally in format
android:label App display name Default is the project name, and it needs to be modified according to actual conditions
android:icon Application icon Replace the specified icon file
meta-data
   android:name
Resource Name Not alterable, used to generate Android plug-in for Flutter
meta-data
  value
Resource value Not alterable, used to generate Android plug-in for Flutter

Replace the app icon

Android provides icon configuration files of the following sizes. Icon files can be applied in the corresponding size directory of Android/app/src/main/res under the Flutter project.

Size alias Icon Size Screen size
mipmap-mdpi 48x48 320×480
mipmap-hdpi 72x72 480×800,480×854
mipmap-xhdpi 96x96 1280*720,720p
mipmap-xxhdpi 144x144 1920*1080,1080p
mipmap-xxxhdpi 192x192 3840×2160,4k

Replace the startup page

The application startup page image is in the launch_background.xml configuration file under android/app/src/main/drawable under the Flutter project. The default is a white background. The xml questionnaire is as follows:

<?xml version="1.0" encoding="utf-8"?>
<!-- Modify this file to customize your launch splash screen -->
<layer-list xmlns:andro>
    <item android:drawable="@android:color/white" />

    <!-- You can insert your own image assets here -->
    <!-- <item>
        <bitmap
            android:gravity="center"
            android:src="@mipmap/launch_image" />
    </item> -->
</layer-list>

The commented out part can be used to set the startup page picture. It should be noted that the size of some models may not be the same as the startup page picture, so the background color of the startup page can be set to be the same as the edge of the startup page picture.

&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;!-- Modify this file to customize your launch splash screen --&gt;
&lt;layer-list xmlns:andro&gt;
  	&lt;!-- Background color --&gt;
    &lt;item android:drawable="@android:color/white" /&gt;
		
  	&lt;!-- Startup page picture,Other elements can also be added --&gt;
    &lt;item&gt;
        &lt;bitmap
            android:gravity="center"
            android:src="@mipmap/launch_image" /&gt;
    &lt;/item&gt;
&lt;/layer-list&gt;

Set access permissions

Set application permissions in the file under Android/app/src (note that it is not the file under the src/profile folder), such as accessing the network, album, camera, etc. The development environment is set in android/src/debug. Here is an example file:

&lt;manifest xmlns:andro
    package=".animation_demo"&gt;

    &lt;uses-permission android:name=""/&gt;
    &lt;uses-permission android:name=".ACCESS_WIFI_STATE"/&gt;
    &lt;uses-permission android:name=".ACCESS_NETWORK_STATE"/&gt;
    
    &lt;application
        android:name=""
        android:label="Animation Demo"
        android:icon="@mipmap/ic_launcher"&gt;
        &lt;activity
            android:name=".MainActivity"
            android:launchMode="singleTop"
            android:theme="@style/LaunchTheme"
            android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
            android:hardwareAccelerated="true"
            android:windowSoftInputMode="adjustResize"&gt;
            &lt;intent-filter&gt;
                &lt;action android:name=""/&gt;
                &lt;category android:name=""/&gt;
            &lt;/intent-filter&gt;
        &lt;/activity&gt;
        &lt;!-- Don't delete the meta-data below.
             This is used by the Flutter tool to generate  --&gt;
        &lt;meta-data
            android:name="flutterEmbedding"
            android:value="2" /&gt;
    &lt;/application&gt;
&lt;/manifest&gt;

Configure version release parameters

Check if the configuration is correct in android/app/file:

  1. applicaitonId: Apply unique AppId, such as
  2. versionCode: Application version number
  3. versionName: Version number string
  4. minSdkVersion: Specify the lowest API level
  5. targetSdkVersion: Specifies the API level for which the application design runs

As shown below:

android {
    compileSdkVersion 28

    sourceSets {
         += 'src/main/kotlin'
    }

    lintOptions {
        disable 'InvalidPackage'
    }

    defaultConfig {
        // TODO: Specify your own unique Application ID (/studio/build/).
        applicationId ".animation_demo"
        minSdkVersion 16
        targetSdkVersion 28
        versionCode ()
        versionName flutterVersionName
        testInstrumentationRunner ""
    }

    buildTypes {
        release {
            // TODO: Add your own signing config for the release build.
            // Signing with the debug keys for now, so `flutter run --release` works.
            signingConfig 
        }
    }
}

Here you can see that versionCode and versionName are introduced from flutterVersionCode and flutterVersionName, where these two variables are defined above. Read from it first, if it is not defined in the file, so it can be set in localProperties or set in (priority value).

def flutterVersionCode = ('')
if (flutterVersionCode == null) {
    flutterVersionCode = '1'
}

def flutterVersionName = ('')
if (flutterVersionName == null) {
    flutterVersionName = '1.0'
}

Generate application signature

Create a keystore. If it has been created before, just introduce it in it.

#The ~/ is to store the keystore file in the ~/ directorykeytool -genkey -v -keystore ~/ -keyalg RSA -keysize 2048 -validity 10000 -alias key

Just enter your password and organization information as prompted.

Enter the keystore password:  
Enter a new password again: 
What is your first and last name?
  [Unknown]:  lag
What is your organizational unit name?
  [Unknown]:  island-coder
What is your organization name?
  [Unknown]:  RD
What is the name of your city or region?
  [Unknown]:  Coder
Your province/city/What is the name of the autonomous region?
  [Unknown]:  Island
The two letter country of the unit/What is the region code?
  [Unknown]:  CN
CN=lag, OU=island-coder, O=RD, L=Coder, ST=Island, C=CNIs it correct?
  [no]:  Y

Generating for the following objects 2,048 BitRSAKey pair and self-signed certificate (SHA256withRSA) (Validity period is 10,000 sky):
	 CN=lag, OU=island-coder, O=RD, L=Coder, ST=Island, C=CN
[In storage/Users/lag/]

Create a file in the Android directory to reference the keystore information:

storePassword={Keystore Password} #
keyPassword={Certificate Password}
keyAlias=key    #The alias corresponding to the command line -aliasstoreFile=/Users/lag/  #The corresponding path generated by the command

Modify the configuration file

In the file, add the following content under android:

	signingConfigs {
        release {
            keyAlias keystoreProperties['keyAlias']
            keyPassword keystoreProperties['keyPassword']
            storeFile = file(keystoreProperties['storeFile'])
            storePassword = keystoreProperties['storePassword']
        }
    }

    buildTypes {
        release {
            // TODO: Add your own signing config for the release build.
            // Signing with the debug keys for now, so `flutter run --release` works.
            signingConfig 
            
        }
    }

Pack

In the project directory, run the following command:

flutter build apk

By default, it is packaged by release, and the generated apk is under /outputs/apk/.

Things to note

After modifying the file, there may be a cache for flutter packaging. Run the following command at this time, clear the cache and package it again.

flutter clean

The above is the detailed content of how to use Flutter to publish Android applications. For more information about Flutter to publish Android applications, please follow my other related articles!