Flutter给Android应用签名

给Google Play交了25美元保护费,琢磨着把博客的App上架,上架的前提就是给应用签名。如下:

$ keytool -genkey -v -keystore ~/key.jks -keyalg RSA -keysize 2048 -validity 10000 -alias androidKey

记得妥善保管这个key

这个步骤里会要你填密码什么的,记住它们,下面还要用。

然后进到app源码目录编辑 android/key.properties 保存以下内容:

storePassword=<你刚才填写的密码>
keyPassword=<你刚才填写的密码>
keyAlias=androidKey
storeFile=<密钥的绝对路径>

记得把这个文件加到 .gitignore 里:echo 'android/key.properties' >> .gitignore

然后编辑 android/app/build.gradle,把 android { 替换成:

def keystoreProperties = new Properties()
def keystorePropertiesFile = rootProject.file('key.properties')
if (keystorePropertiesFile.exists()) {
    keystoreProperties.load(new FileInputStream(keystorePropertiesFile))
}

android {

   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
       }
   }

最后,记得要替换一下应用的图标,我用 这个库 一键替换了。


我上传到Google Play之后,Google Play提示我 “You uploaded an APK or Android App Bundle that was signed in debug mode. You need to sign your APK or Android App Bundle in release mode”,说我上传了一个debug模式签名的apk,我需要以release 模式重新打包,问题是我就是使用 flutter build apk 打包生成的呀,这就很奇怪了。最后解决方案是执行 flutter clean, 估计是因为此前我就在真机上安装过打包好的应用,而flutter为了加快打包速度缓存了一些什么。


参考资料:


更多文章
  • 任务队列怎么写?python rq源码阅读与分析
  • XMonad 配置教程
  • Haskell简明教程(三):Haskell语法
  • Haskell简明教程(二):从命令式语言进行抽象
  • Haskell简明教程(一):从递归说起
  • 2017年必装的VIM插件推荐
  • TCP/IP简明教程 - 从零构建TCP/IP协议(二)连接,断开与拥塞控制
  • TCP/IP简明教程 - 从零构建TCP/IP协议(这次叫PCT协议)
  • Lua Manual 阅读笔记
  • Golang Map 源码阅读与分析
  • MySQL 零碎知识 - MySQL必知必会
  • Golang slice 源码阅读与分析
  • 经典好书推荐(2017)
  • Golang log库 源码阅读与分析
  • 毕业后一年