Deploy Flutter apps to the Play Store with Fastlane
Fastlane is the recommended tool to deploy Flutter apps to Google's Play Store and Apple's App Store. This article will cover how to do it for the Play Store.
Install and set up
Follow instructions at https://docs.fastlane.tools/getting-started/android/setup/. The install and sign in process is straightforward. Then you have to tweak the Fastlane
config file to enable deploying to the store. My config looked like so:
desc "Deploy a new version to the Google Play"
lane :deploy do
gradle(task: "clean assembleRelease")
upload_to_play_store(
track: 'internal',
apk: '../build/app/outputs/apk/release/app-release.apk'
)
end
However, when I first tried to deploy with it, it failed telling me the APK was signed with the debug key.
To fix this, you can set this up in Android Studio. However when you do so, it'll save the passwords in clear.
Setting up the signing keys without putting the passwords in clear.
In order not to commit the gradle files with passwords in it, I created a key file that's not committed to the repository. Then in build.grade
, I wrote:
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
def keystoreProperties = new Properties()
def keystorePropertiesFile = rootProject.file('../../key.properties')
if (keystorePropertiesFile.exists()) {
keystoreProperties.load(new FileInputStream(keystorePropertiesFile))
}
android {
compileSdkVersion 28
...
signingConfigs {
release {
keyAlias keystoreProperties['keyAlias']
keyPassword keystoreProperties['keyPassword']
storeFile file(keystoreProperties['storeFile'])
storePassword keystoreProperties['storePassword']
}
}
buildTypes {
release {
signingConfig signingConfigs.release
}
}
}
The relevant lines are the ones related to keystoreProperties, signingConfigs and the release build type.
The structure of key.properties
is as follows:
storePassword=...
keyPassword=...
keyAlias=...
storeFile=path_to_file.jks