vscode打包flutter发布版apk文件

> 参考文档:https://flutter.dev/docs/deployment/android ### 1、查看keytool安装路径,AndroidStudio toolschain目录 ``` flutter doctor -v ``` ### 2、生成证书,并复制到项目\android\app\目录下 ``` C:\AndroidStudio\jre\bin\keytool -genkey -v -keystore d:\flutter-app.jks -storetype JKS -keyalg RSA -keysize 2048 -validity 36500 -alias nc65 C:\AndroidStudio\jre\bin\keytool -importkeystore -srckeystore d:\flutter-app.jks -destkeystore d:\flutter-app.jks -deststoretype pkcs12 ``` ### 3、在项目\android\目录下添加key.properties配置文件 ``` storePassword=xxxxxxxx keyPassword=xxxxxxxx keyAlias=nc65 storeFile=flutter-app.jks ``` ### 4、修改项目\android\app\目录下的build.gradle文件,增加证书及编译相关配置信息 ``` # android 代码块之前添加内容 def keystoreProperties = new Properties() def keystorePropertiesFile = rootProject.file('key.properties') if (keystorePropertiesFile.exists()) { keystoreProperties.load(new FileInputStream(keystorePropertiesFile)) } android { ... # android代码块内替换buildTypes代码块内容 signingConfigs { release { keyAlias keystoreProperties['keyAlias'] keyPassword keystoreProperties['keyPassword'] storeFile keystoreProperties['storeFile'] ? file(keystoreProperties['storeFile']) : null storePassword keystoreProperties['storePassword'] } } buildTypes { release { signingConfig signingConfigs.release } } } ``` ### 5、检查并确认相关权限配置,否则打包出来的APK会没有相关权限 ``` # 项目\android\app\src\profile\AndroidManifest.xml # 项目\android\app\src\main\AndroidManifest.xml # 需注意,相关权限要添加到manifest节点下,而不是application节点 ``` ### 6、打包apk,打包好的apk文件路径为:项目\build\app\outputs\flutter-apk\app.apk ``` flutter build apk # 分平台打包 flutter build apk --split-per-abi ```
上一篇:部署apk到服务器上


下一篇:apk加壳去壳