layout | title | permalink |
---|---|---|
page |
Preparing an Android App for Release |
/android-release/ |
During the typical development cycle, you'll test an app using flutter run
at the
command line, the Run and Debug toolbar buttons in IntelliJ, or both. By default,
Flutter builds a debug version of your app.
When you're ready to prepare a release version for Android, for example to publish to the Google Play Store, follow the steps on this page.
- TOC Placeholder {:toc}
Review the default App Manifest file AndroidManifest.xml
located
in <app dir>/android/app/src/main/
and verify the values are correct,
especially:
-
application
: Edit theapplication
tag to reflect the final name of the app. -
uses-permission
: Remove theandroid.permission.INTERNET
permission if your application code does not need Internet access. The standard template includes this tag to enable communication between Flutter tools and a running app.
Review the default [Gradle build file][gradlebuild] file build.gradle
located in <app dir>/android/app/
and verify the values are correct, especially:
-
defaultConfig
:-
applicationId
: Specify the final, unique (Application Id)appid -
versionCode
&versionName
: Specify the interall app version number, and the version number display string. Consult the version information guidance in the versions documenation for details. -
minSdkVersion
&targetSdkVersion
: Specify the minimum API level, and the API level on which the app is designed to run. Consult the API level section in the versions documetation for details.
-
When a new Flutter app is created, it has a default Launcher icon. To customize this icon you might want to check out the Flutter Launcher Icons package.
Alternatively, if you want to do it manually, here's how:
-
Review the Android Launcher Icons guidelines for icon design.
-
In the
<app dir>/android/app/src/main/res/
directory, place your icon files in folders named using Configuration Qualifiers. The defaultmipmap-
folders demonstrate the correct naming convention. -
In
AndroidManifest.xml
, update theapplication
tag'sandroid:icon
attribute to reference icons from the previous step (e.g.<application android:icon="@mipmap/ic_launcher" ...
). -
To verify the icon has been replaced, run your app using
flutter run
and inspect the app icon in the Launcher.
If you have an existing keystore, skip to the next step. If not, create one
by running the following at the command line:
keytool -genkey -v -keystore ~/key.jks -keyalg RSA -keysize 2048 -validity 10000 -alias key
Note: Keep this file private; do not check it into public source control.
Note: keytool
may not be in your path. It is part of the Java JDK, which is installed as
part of Android Studio. For the concrete path, run flutter doctor -v
and see the path printed
after 'Java binary at:', and then use that fully qualified path replacing java
with keytool
.
Create a file named <app dir>/android/key.properties
that contains a
reference to your keystore:
storePassword=<password from previous step>
keyPassword=<password from previous step>
keyAlias=key
storeFile=<location of the key store file, e.g. /Users/<user name>/key.jks>
Note: Keep this file private; do not check it into public source control.
Configure signing for your app by editing the <app dir>/android/app/build.gradle
file.
- Replace:
android {
with the keystore information from your properties file:
def keystorePropertiesFile = rootProject.file("key.properties")
def keystoreProperties = new Properties()
keystoreProperties.load(new FileInputStream(keystorePropertiesFile))
android {
- Replace:
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.debug
}
}
with:
signingConfigs {
release {
keyAlias keystoreProperties['keyAlias']
keyPassword keystoreProperties['keyPassword']
storeFile file(keystoreProperties['storeFile'])
storePassword keystoreProperties['storePassword']
}
}
buildTypes {
release {
signingConfig signingConfigs.release
}
}
Release builds of your app will now be signed automatically.
By default, Flutter does not obfuscate or minify the Android host. If you intend to use third-party Java or Android libraries, you may want to reduce the size of the APK or protect that code from reverse engineering.
For information on obfuscating Dart code, see Obfuscating Dart Code in the Flutter wiki.
Create /android/app/proguard-rules.pro
file and add rules listed below.
#Flutter Wrapper
-keep class io.flutter.app.** { *; }
-keep class io.flutter.plugin.** { *; }
-keep class io.flutter.util.** { *; }
-keep class io.flutter.view.** { *; }
-keep class io.flutter.** { *; }
-keep class io.flutter.plugins.** { *; }
The configuration above only protects Flutter engine libraries. Any additional libraries (for example, Firebase) require their own rules to be added.
Open /android/app/build.gradle
file and locate buildTypes
definition.
Inside release
configuration set minifiyEnabled
and useProguard
flags
to true. You have to also point ProGuard to the file you have created in step 1.
android {
...
buildTypes {
release {
signingConfig signingConfigs.debug
minifyEnabled true
useProguard true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
Note: Obfuscation and minification can considerably extend compile time of the Android application.
This section describes how to build a release APK. If you completed the signing steps in the previous section, the release APK will be signed.
Using the command line:
cd <app dir>
(replace<app dir>
with your application's directory).- Run
flutter build apk
(flutter build
defaults to--release
).
The release APK for your app is created at <app dir>/build/app/outputs/apk/app-release.apk
.
Follow these steps to install the APK built in the previous step on a connected Android device.
Using the command line:
- Connect your Android device to your computer with a USB cable.
cd <app dir>
where<app dir>
is your application directory.- Run
flutter install
.
For detailed instructions on publishing the release version of an app to the Google Play Store, see the Google Play publishing documentation.