Set the application name, package name, application icon, and startup

The android application resource configuration is set in the main/ Androidmanifest.xml file as follows:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.gesture_demo">
    <! -- io.flutter.app.FlutterApplication is an android.app.Application that calls FlutterMain.startInitialization(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="io.flutter.app.FlutterApplication"
        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="android.intent.action.MAIN"/>
                <category android:name="android.intent.category.LAUNCHER"/>
            </intent-filter>
        </activity>
        <! -- Don't delete the meta-data below. This is used by the Flutter tool to generate GeneratedPluginRegistrant.java -->
        <meta-data
            android:name="flutterEmbedding"
            android:value="2" />
    </application>
</manifest>

Copy the code

The document generated by Flutter suggests that most of the content can be left as it is, but can be modified as needed. The contents that may be modified are as follows:

The property name use instructions
package The name of packages The unique identifier of an Android application is in the format of com.xxxx. XXX
android:label Application display name The default project name must be changed as required
android:icon Application icon Replace the specified icon file
meta-data

   android:name
The name of the resource Unchangeable, android plugin for Flutter generation
meta-data

  value
Resource value Unchangeable, android plugin for Flutter generation

Replace the app icon

Android provides icon profiles in the following sizes, which can be applied to the Android /app/ SRC /main/res directory under the Flutter project.

Size alias Size of the icon The screen size
mipmap-mdpi 48×48 320 x 480
mipmap-hdpi 72×72 480 * 800480 * 854
mipmap-xhdpi 96×96 1280 * 720720 p
mipmap-xxhdpi 144×144 1920 * 1080108 0 p
mipmap-xxxhdpi 192×192 3840 x 2160, 4 k

Replace startup page

Application start page images in the Flutter project under the android/app/SRC/main/drawable launch_background. Under the XML configuration file, the default is a white, XML questionnaire as shown below:


      
<! -- Modify this file to customize your launch splash screen -->
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <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>

Copy the code

The commented out part can be used to set the boot page image. Note that some models may not be the same size as the boot page image, so you can set the boot page background color to be consistent with the boot page image edge.


      
<! -- Modify this file to customize your launch splash screen -->
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
  	<! -- Background color -->
    <item android:drawable="@android:color/white" />
		
  	<! -- Launch page image, you can also add other elements -->
    <item>
        <bitmap
            android:gravity="center"
            android:src="@mipmap/launch_image" />
    </item>
</layer-list>

Copy the code

Setting access Permissions

In the Androidmanifest.xml file under Android /app/ SRC (note that it is not the Androidmanifest.xml file under SRC /profile), set application permissions such as access to the web, albums, cameras, etc. The development environment is set in the Androidmanifest.xml of Android/SRC /debug. Here is an example file:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.animation_demo">

    <uses-permission android:name="android.permission.INTERNET"/>
    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
    
    <application
        android:name="io.flutter.app.FlutterApplication"
        android:label="Animation 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="android.intent.action.MAIN"/>
                <category android:name="android.intent.category.LAUNCHER"/>
            </intent-filter>
        </activity>
        <! -- Don't delete the meta-data below. This is used by the Flutter tool to generate GeneratedPluginRegistrant.java -->
        <meta-data
            android:name="flutterEmbedding"
            android:value="2" />
    </application>
</manifest>

Copy the code

Configure version release parameters

Check whether the configuration is correct in the Android /app/build.gradle file:

  1. ApplicaitonId: indicates the unique AppId of an application, such as com.lios.HelloWorld
  2. VersionCode: indicates the version number of the application
  3. VersionName: indicates the version number
  4. MinSdkVersion: Specifies the lowest API level
  5. TargetSdkVersion: Specifies the API level at which the application is designed to run

As follows:

android {
    compileSdkVersion 28

    sourceSets {
        main.java.srcDirs += 'src/main/kotlin'
    }

    lintOptions {
        disable 'InvalidPackage'
    }

    defaultConfig {
        // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
        applicationId "com.example.animation_demo"
        minSdkVersion 16
        targetSdkVersion 28
        versionCode flutterVersionCode.toInteger()
        versionName flutterVersionName
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }

    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 signingConfigs.debug
        }
    }
}
Copy the code

It can be seen that versionCode and versionName are introduced from flutterVersionCode and flutterVersionName, where these two variables are defined on build.gradle. Properties. If it is not defined in that file, it can be set in localProperties or build.gradle (the value in local.properties is taken first).

def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
if (flutterVersionCode == null) {
    flutterVersionCode = '1'
}

def flutterVersionName = localProperties.getProperty('flutter.versionName')
if (flutterVersionName == null) {
    flutterVersionName = '1.0'
}
Copy the code

Generating an application Signature

Create a keystore. If you have created one before, introduce it in key.properties.

JKS stores the keystore file key. JKS in the ~/ directory
keytool -genkey -v -keystore ~/key.jks -keyalg RSA -keysize 2048 -validity 10000 -alias key

Copy the code

Enter the password and organization information as prompted.

Enter the keystore password: Enter the new password again: what is your first and last name? [Unknown]: Lag What is the name of your organization? [Unknown]: Island-coder What is the name of your organization? [Unknown]: RD What is the name of your city or area? Coder what is the name of your province/city/region? [Unknown]: Island What is the two-letter country code for this unit? [Unknown]: CN CN=lag, OU= islen-coder, O=RD, L= coder, ST= island, C=CN [No]: Y is generating for the following objects2.048Bit RSA key pair and self-signed certificate (SHA256withRSA) (Validity period:10.000CN=lag, OU= islen-coder, O=RD, L= coder, ST= island, C=CNkey.jks]

Copy the code

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

StorePassword ={keystore password} #
KeyPassword ={certificate password}
keyAlias=key    # corresponds to the alias after -alias on the command line
storeFile=/Users/lag/key.jks  # The data pair path of key.jks generated by the corresponding command
Copy the code

Modifying a Configuration File

In the build.gradle file, add the following 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 signingConfigs.release
            
        }
    }
Copy the code

packaging

In the project directory, run the following command:

flutter build apk
Copy the code

Default press release packaging, generated apk in build. The app/outputs/apk/app – the apk.

Matters needing attention

After modifying the Androidmanifest.xml file, the flutter package may exist in a cache. At this point, run the following command to clear the cache and repackage.

flutter clean
Copy the code