Flutter Android creates a certificate and packs it
1. Use Android Studiu to quickly create a certificate
Use Android Studiu to open the project, right-click to open it in Android mode
Choose the first option and click Next
Select the address to create a new certificate file, I put it in the android folder of the project
The two passwords need to be remembered and will be used later, after filling in, click OK, if there is a permission problem, please open the full access permission of the folder
You can close other windows after the creation is successful.
After the certificate is created, please create a file named key.properties in the android folder of the project
在文件中填入以下内容
storePassword=创建证书输入的密码
keyPassword=创建证书输入的密码
keyAlias=证书标识符
storeFile=../证书文件名
2. Configure the signature in gradle
Configure signing for your application by editing the android/app/build.gradle file
1. Replace
android {
for:
def keystorePropertiesFile = rootProject.file("key.properties")
def keystoreProperties = new Properties()
keystoreProperties.load(new FileInputStream(keystorePropertiesFile))
android {
2. Replace
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
}
}
for:
signingConfigs {
release {
keyAlias keystoreProperties['keyAlias']
keyPassword keystoreProperties['keyPassword']
storeFile file(keystoreProperties['storeFile'])
storePassword keystoreProperties['storePassword']
}
}
buildTypes {
release {
signingConfig signingConfigs.release
}
}
If you need to turn on obfuscation or other details, please see the official website: release the Android version of the APP
Finally use the command line to package:
运行flutter build apk (flutter build 默认会包含 --release选项)。
打包好的APK位于/build/app/outputs/apk/app-release.apk。
You can also install the release APK on the device
用USB您的Android设备连接到您的电脑
运行 flutter install