0%

mac android studio flutter 打包 apk

  • Create a keystore
1
2
keytool -genkey -v -keystore ~/key.jks -keyalg RSA -keysize 2048 -validity 10000 -alias key

  • /android文件夹下生成属性文件关联秘钥 key.properties
1
2
3
4
5
storePassword=<password from previous step>
keyPassword=<password from previous step>
keyAlias=key
storeFile=<location of the key store file, such as /Users/<user name>/key.jks>

  • /android/app/build.gradle文件里增加load代码
1
2
3
4
5
6
7
8
9
def keystoreProperties = new Properties()
def keystorePropertiesFile = rootProject.file('key.properties')
if (keystorePropertiesFile.exists()) {
keystoreProperties.load(new FileInputStream(keystorePropertiesFile))
}

android {
...
}
  • 在buildTypes之前增加签名配置代码
1
2
3
4
5
6
7
8
9
10
11
12
13
signingConfigs {
release {
keyAlias keystoreProperties['keyAlias']
keyPassword keystoreProperties['keyPassword']
storeFile keystoreProperties['storeFile'] ? file(keystoreProperties['storeFile']) : null
storePassword keystoreProperties['storePassword']
}
}
buildTypes {
release {
signingConfig signingConfigs.release
}
}
  • 运行编译命令
1
flutter build apk
  • 运行结果
1
2
3
Running Gradle task 'assembleRelease'... Done                     143.3s (!)
✓ Built build/app/outputs/flutter-apk/app-release.apk (79.9MB).

完。

参考:https://flutter.dev/docs/deployment/android