FlutterFlow | Build and release an Android app on Google Play Store

organicnz

Tarlan Isaev ๐Ÿ“

Posted on May 3, 2022

FlutterFlow | Build and release an Android app on Google Play Store

Geez I was facing an issue all day long with signing my android app today, but finally overcame the pain lol :)

*Preparation before the flight :) *

Before signing my app I increased "compileSdkVersion 30", "minSdkVersion 23", "targetSdkVersion 30". Also added "signingConfigs" a few "def" properties and change "signingConfigs" to "release" mode in "build.grudle" file.

Here's the complete "build.grudle" file:

// Beginning | sorry the code snippet isn't properly displayed for some reason. Pls copy as it's.
def localProperties = new Properties()
def localPropertiesFile = rootProject.file('local.properties')
if (localPropertiesFile.exists()) {
localPropertiesFile.withReader('UTF-8') { reader ->
localProperties.load(reader)
}
}

def flutterRoot = localProperties.getProperty('flutter.sdk')
if (flutterRoot == null) {
throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")
}

def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
if (flutterVersionCode == null) {
flutterVersionCode = '1'
}

def flutterVersionName = localProperties.getProperty('flutter.versionName')
if (flutterVersionName == null) {
flutterVersionName = '1.0'
}

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
apply plugin: 'com.google.gms.google-services' // Google Services plugin

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

android {
compileSdkVersion 30
ndkVersion '23.1.7779620'
sourceSets {
main.java.srcDirs += 'src/main/kotlin'
}
lintOptions {
disable 'InvalidPackage'
}
defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "com.flutterflow.foodshare"
minSdkVersion 23
targetSdkVersion 30
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
ndk {
debugSymbolLevel 'FULL'
}
}
signingConfigs {
release {
keyAlias keystoreProperties['keyAlias']
keyPassword keystoreProperties['keyPassword']
storeFile keystoreProperties['storeFile'] ? file(keystoreProperties['storeFile']) : null
storePassword keystoreProperties['storePassword']
}
}
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.release
}
}
}
flutter {
source '../..'
}
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'io.card:android-sdk:5.+'
}
// End

Created file "key.properties" with these properties where storePassword and keyPassword are your later generated password for key. You'll put them on the terminal.

storePassword=your_password
keyPassword=your_password
keyAlias=upload
storeFile=/Users/organic/Development/foodshare-flutter/android/app/upload-keystore.jks

Image description

Image description

Signing the app

Before building the app we must sign it by the key, however I got this error initially:

Java Algorithm HmacPBESHA256 not available

How did I solve it? Instead of the default command on Mac/Linux, I used the following command and it helped after a few hours of the struggle:

/Users/organic/Library/Java/JavaVirtualMachines/openjdk-16.0.1/Contents/Home/bin/keytool -genkey -v -keystore android/app/upload-keystore.jks -keyalg RSA -keysize 2048 -validity 10000 -alias upload -storetype JKS

That command creates and stores key's stores the upload-keystore.jks file in your home directory. If you want to store it elsewhere, change the argument you pass to the -keystore parameter. However, keep the keystore file private; donโ€™t check it into public source control!

If I've understood it correctly the Openjdk v11 doesn't allow to issue JKS keys and it's only available from the version Openjdk v12. In my case I've used Openjdk v16 installed by Homebrew.

Make sure you you've selected the right JDK (Java Development Kit) home path. In my case it locates in the directory below:

/Users/organic/Library/Java/JavaVirtualMachines/openjdk-16.0.1/Contents/Home

Image description

Creation of the lightweight bundle.

Congrats, our key is generated and we're ready to build appbundle release ๐Ÿ™‚

Use this following command on your app folder:

flutter build appbundle --release --build-name=foodshare-1.0.0 --build-number=2

Just wait until it's finally baked and you'll see the complete file "app-release.aab" by path "../your-app/build/app/outputs/bundle/release/app-release.aab".

Image description

Production release time.

Drop your app bundle there to upload and send it for moderation ๐Ÿ™‚

Image description

Now it looks complete I hope ahah

Pls let me know if something is wrong here :)
Thank you everyone :)

*UPD: *

*1. If you reset your repository to HEAD commit: *

sudo git reset --hard HEAD

You should copy key and properties files each time "upload-keystore.jks" to the "../your-flutterflow-project/android/app/upload-keystore.jks" directory and "key.properties" to "../your-flutterflow-project/android/key.properties" directory in case to be able to create the app builds.

2.Reseting the upload key through Google Play Developer Support.

Open a ticket on Google Play Developer Support and they will help ti reset the upload key for your app, com.flutterflow.yourapp. The new upload key will be used to sign APKs that you upload to Play.

Google recommend that you adjust your planning to include a buffer period of 48 hours from when the upload key has been reset before you can use the new upload key. You can learn more about using app signing by Google Play here.

Hereโ€™s how to generate and register a new upload key:

  1. Follow the instructions in the Android Studio Help Center to generate a new key. It must be different from any previous keys. Alternatively, you can use the following command line to generate a new key:

keytool -genkeypair -alias upload -keyalg RSA -keysize 2048 -validity 9125 -keystore keystore.jks

This key must be a 2048 bit RSA key and have 25-year validity.

  1. Export the certificate for that key to PEM format:

keytool -export -rfc -alias upload -file upload_certificate.pem -keystore keystore.jks

  1. Reply to the open ticket email and attach the upload_certificate.pem file.
๐Ÿ’– ๐Ÿ’ช ๐Ÿ™… ๐Ÿšฉ
organicnz
Tarlan Isaev ๐Ÿ“

Posted on May 3, 2022

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related

ยฉ TheLazy.dev

About