Configuring your Flutter project for Android involves setting up essential properties and features to ensure your app runs smoothly on Android devices. This guide covers crucial steps including updating the package name, setting version information, configuring app icons, permissions, and more.
Navigate to the Android Directory
Open Android Studio and navigate to the android
directory of your Flutter project:
cd path/to/your/flutter/project/android
Open the Project
File
-> Open
.android
directory and click OK
or Open
.Update AndroidManifest.xml
android/app/src/main/AndroidManifest.xml
.package
attribute in the manifest
tag and update it to the new package name:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.new.package.name">
Update build.gradle
android/app/build.gradle
.applicationId
in the defaultConfig
block:
defaultConfig {
applicationId "com.new.package.name"
...
}
Rename Package Directories
android/app/src/main/java/com/old/package/name/
.com
directory and select Refactor
-> Rename
.Update MainActivity.java
or MainActivity.kt
android/app/src/main/java/com/new/package/name/MainActivity.java
and update the package statement at the top.MainActivity.kt
.Update build.gradle
android/app/build.gradle
.versionCode
and versionName
in the defaultConfig
block:
defaultConfig {
versionCode 1
versionName "1.0"
...
}
versionCode
is an integer used for internal versioning.versionName
is a string representing the release version displayed to users.Open Asset Studio
File
-> New
-> Image Asset
.Set App Icons
Launcher Icons (Adaptive and Legacy)
for app icons.Next
and Finish
to generate and replace existing icons in the res
directory.Open AndroidManifest.xml
android/app/src/main/AndroidManifest.xml
.Add Required Permissions
Add permissions for features your app requires, such as:
<uses-permission android:name="android.permission.CAMERA"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.INTERNET"/>
Ensure permissions are listed under the manifest
tag.
Generate a Keystore
keytool -genkey -v -keystore my-release-key.jks -keyalg RSA -keysize 2048 -validity 10000 -alias my-key-alias
Configure Signing in build.gradle
android/app/build.gradle
.android
block:
signingConfigs {
release {
keyAlias 'my-key-alias'
keyPassword 'my-key-password'
storeFile file('my-release-key.jks')
storePassword 'my-store-password'
}
}
buildTypes {
release {
signingConfig signingConfigs.release
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
Select an Emulator or Device
Build and Run
Run
button (▶) or select Run
-> Run 'main.dart'
to build and run your app on the selected device or emulator.