74 lines
2.4 KiB
Markdown
74 lines
2.4 KiB
Markdown
## Android Setup
|
|
|
|
### Keystore setup
|
|
```bash
|
|
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](https://developers.google.com/maps/flutter-package/config#android_1).
|
|
- Add the following to `android/build.gradle`:
|
|
```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`:
|
|
```gradle
|
|
plugins {
|
|
// ...
|
|
id 'com.google.android.libraries.mapsplatform.secrets-gradle-plugin'
|
|
}
|
|
```
|
|
- Add the credentials to `android/secrets.properties`:
|
|
```properties
|
|
MAPS_API_KEY=YOUR_API_KEY
|
|
```
|
|
- Reference the credentials in `android/app/src/main/AndroidManifest.xml`:
|
|
```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`:
|
|
```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:
|
|
```gradle
|
|
buildTypes {
|
|
release {
|
|
signingConfig signingConfigs.release
|
|
}
|
|
}
|
|
```
|
|
This makes use of the `secretProperties` defined previously:
|
|
```gradle
|
|
secretPropertiesFile.withReader('UTF-8') { reader ->
|
|
secretProperties.load(reader)
|
|
}
|
|
```
|
|
|
|
|
|
### Using the credentials in CI
|
|
- Add the secret files to the repository secrets (e.g. `ANDROID_SECRETS_PROPERTIES`).
|
|
|
|
- temporarily write them back to files during the CI execution:
|
|
```bash
|
|
echo {{ secrets.ANDROID_SECRETS }} >> android/secrets.properties
|
|
```
|