Android Setup

Keystore setup

keytool -genkey -v -keystore release.keystore -keyalg RSA -keysize 2048 -validity 10000 -alias upload
  • This is required to store local credentials securely and more importantly to sign the app for google play store distribution.

Using secret credentials during build

Following the guide under https://developers.google.com/maps/flutter-package/config#android_1.

  • Add the following to android/build.gradle:
    buildscript {
        dependencies {
            classpath "com.google.android.libraries.mapsplatform.secrets-gradle-plugin:secrets-gradle-plugin:2.0.1"
        }
    }
    
  • Add the following to android/app/build.gradle:
    plugins {
        // ...
        id 'com.google.android.libraries.mapsplatform.secrets-gradle-plugin'
    }
    
  • Add the credentials to android/secrets.properties:
    MAPS_API_KEY=YOUR_API_KEY
    
  • Reference the credentials in android/app/src/main/AndroidManifest.xml:
    <meta-data
        android:name="com.google.android.geo.API_KEY"
        android:value="${MAPS_API_KEY}" />
    

Signing the app

Compared to the flutter template application, a few changes have to be made:

  • Added to android/app/build.gradle:
        signingConfigs {
            release {
                keyAlias = secretProperties['keyAlias']
                keyPassword = secretProperties['keyPassword']
                storeFile = secretProperties['storeFile'] ? file(secretProperties['storeFile']) : null
                storePassword = secretProperties['storePassword']
            }
        }
    
  • Changed the buildTypes to use the release signing config:
        buildTypes {
            release {
                signingConfig signingConfigs.release
            }
        }
    
    This makes use of the secretProperties defined previously:
        secretPropertiesFile.withReader('UTF-8') { reader ->
            secretProperties.load(reader)
        }