1. 打开terminal
2. 输入命令:keytool -genkey -v -keystore C:/20190628/android -keyalg RSA -keysize 2048 -validity 10000 -alias key
注:C:/20190628/android 为key保存路径
3. 填充信息
4. 在android文件夹下创建一个名为key.properties的文件
5. Key.properties文件中添加
storePassword=<password from previous step> //输入上一步创建KEY时输入的 密钥库 密码 keyPassword=<password from previous step> //输入上一步创建KEY时输入的 密钥 密码 keyAlias=key storeFile=C:/20190628/android/file //key.jks的存放路径
6. 在/android/app/build.gradle文件,在android {这一行前面,加入如下代码
def keystorePropertiesFile = rootProject.file("key.properties") def keystoreProperties = new Properties() keystoreProperties.load(new FileInputStream(keystorePropertiesFile))
7. 把如下代码进行替换
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 file(keystoreProperties['storeFile']) storePassword keystoreProperties['storePassword'] } } buildTypes { release { signingConfig signingConfigs.release } }
8. 生成apk,直接在终端输入
flutter build apk
9. Flutter install 安装到虚拟机上
注:大坑!
请将key.properties文件中值后所有字符删除,否则会报错