Flutter Android packaging app

1. First, cmd executes the following command to generate the key library key.jks

keytool -genkey -v -keystore ~/key.jks -keyalg RSA -keysize 2048 -validity 10000 -alias key

2. Create a file key.properties in the \android\ directory of the project.
For example, my absolute path "D:\AndroidStudioProjects\lanying\android\key.properties"
is the content of my key.properties:

storePassword= 你之前在秘钥库设置的密码
keyPassword= 你之前在秘钥库设置的密码
keyAlias=key
storeFile= key.jks的路径

3. After creation, reference and configure related information in android\app\build.gradle

(3.1) Refer to the key library information in the properties file, note that the code must be configured on the android node

//1. 代码必须配置在android节点的上面
def keystoreProperties = new Properties()
def keystorePropertiesFile = rootProject.file('key.properties')
if (keystorePropertiesFile.exists()) {
    
    
    keystoreProperties.load(new FileInputStream(keystorePropertiesFile))
}

(3.2) Next, use the signature configuration information ( note that these codes are written in the android tag , I wrote it at the end)

 
// 2. 使用签名配置信息 Start
    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
        }
    }
    signingConfigs {
    
    
        release {
    
    
            keyAlias keystoreProperties['keyAlias']
            keyPassword keystoreProperties['keyPassword']
            storeFile keystoreProperties['storeFile'] ? file(keystoreProperties['storeFile']) : null
            storePassword keystoreProperties['storePassword']
        }
    }
    buildTypes {
    
    
        release {
    
    
            signingConfig signingConfigs.release
        }
    } 

4. Configure and modify the app name in android\app\src\main\AndroidManifest.xml
in the attribute android:label="this is the name of the app" in the application tag

5. Finally, open the powershell package in the project directory
(1) execute the empty command first

flutter clean 

(2) Re-execute the packaging command

flutter build apk

(3) Return path after successful packaging
Insert picture description here

Guess you like

Origin blog.csdn.net/m0_43413873/article/details/107224555