【Flutter】Android打包发布

1. 生成一个签名密钥

可以用keytool命令生成一个私有密钥。在Windows上keytool命令放在JDK的bin目录中(比如C:\Program Files\Java\jdkx.x.x_x\bin),你可能需要在命令行中先进入那个目录才能执行此命令。

$ keytool -genkey -v -keystore my-release-key.keystore -alias my-key-alias -keyalg RSA -keysize 2048 -validity 10000

2. 创建key.properties文件(your_project/android/key.properties

#创建KEY时输入的密钥库密码
storePassword=666666
#创建KEY时输入的密钥密码
keyPassword=666666
#密钥名称[默认是key,这里我设置为my-key-alias]
keyAlias=my-key-alias
#签名的存放路径【我把生成的my-release-key.keystore文件扔到了d盘】
storeFile=D:/my-release-key.keystore

3. 修改your_project/android/app/build.gradle

...
def keystorePropertiesFile = rootProject.file("key.properties")
def keystoreProperties = new Properties()
keystoreProperties.load(new FileInputStream(keystorePropertiesFile))

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.debug
            signingConfig signingConfigs.release
        }
    }
}

4. 生成apk

$ flutter build apk

生成的app-release.apk 在项目的your_project/build/output/apk/release目录下

5. 安装

$ adb install app-release.apk

你可能感兴趣的:(【Flutter】Android打包发布)