How to Sign Flutter App for Android and iOS
To sign a Flutter app, you must create a signing key and configure your app to use it. For Android, set up a
key.properties file and update build.gradle. For iOS, use Xcode to manage signing certificates and provisioning profiles.Syntax
Signing a Flutter app involves configuring platform-specific files:
- Android: Use
key.propertiesto store key info and updateandroid/app/build.gradleto use the signing config. - iOS: Use Xcode to select a signing certificate and provisioning profile in the project settings.
groovy
android {
signingConfigs {
release {
keyAlias keystoreProperties['keyAlias']
keyPassword keystoreProperties['keyPassword']
storeFile file(keystoreProperties['storeFile'])
storePassword keystoreProperties['storePassword']
}
}
buildTypes {
release {
signingConfig signingConfigs.release
}
}
}Example
This example shows how to sign an Android Flutter app by creating a key.properties file and configuring build.gradle.
groovy
1. Create <code>key.properties</code> in <code>android/</code> folder with content: storePassword=myStorePassword keyPassword=myKeyPassword keyAlias=myKeyAlias storeFile=my-release-key.jks 2. Update <code>android/app/build.gradle</code>: // Load properties Properties keystoreProperties = new Properties() File keystorePropertiesFile = rootProject.file('key.properties') if (keystorePropertiesFile.exists()) { keystoreProperties.load(new FileInputStream(keystorePropertiesFile)) } android { signingConfigs { release { keyAlias keystoreProperties['keyAlias'] keyPassword keystoreProperties['keyPassword'] storeFile file(keystoreProperties['storeFile']) storePassword keystoreProperties['storePassword'] } } buildTypes { release { signingConfig signingConfigs.release minifyEnabled false shrinkResources false } } }
Output
Flutter app builds with release signing using the specified keystore.
Common Pitfalls
Common mistakes when signing Flutter apps include:
- Not creating or referencing the
key.propertiesfile correctly for Android. - Using incorrect passwords or aliases in the signing config.
- For iOS, forgetting to select the correct signing team or provisioning profile in Xcode.
- Not cleaning the build after changing signing configs, causing stale builds.
groovy
Wrong way (missing key.properties):
android {
signingConfigs {
release {
keyAlias 'myKeyAlias'
keyPassword 'wrongPassword'
storeFile file('wrong-path.jks')
storePassword 'wrongStorePassword'
}
}
}
Right way (using key.properties):
Properties keystoreProperties = new Properties()
File keystorePropertiesFile = rootProject.file('key.properties')
if (keystorePropertiesFile.exists()) {
keystoreProperties.load(new FileInputStream(keystorePropertiesFile))
}
android {
signingConfigs {
release {
keyAlias keystoreProperties['keyAlias']
keyPassword keystoreProperties['keyPassword']
storeFile file(keystoreProperties['storeFile'])
storePassword keystoreProperties['storePassword']
}
}
}Quick Reference
Android Signing Steps:
- Create a keystore with
keytool. - Make
key.propertieswith passwords and alias. - Update
build.gradleto use signing config. - Build release APK or AAB with
flutter build apk --release.
iOS Signing Steps:
- Open
ios/Runner.xcworkspacein Xcode. - Set your team and signing certificate in project settings.
- Ensure provisioning profiles are valid.
- Build archive and export for App Store or TestFlight.
Key Takeaways
Always create and reference a
key.properties file for Android signing.Use Xcode to manage iOS signing certificates and provisioning profiles.
Double-check passwords and file paths to avoid build errors.
Clean your build folder after changing signing configurations.
Test your signed app on devices before publishing.