Step 1 Create a keystore (if you have already created it, please skip it)
- Windows+R, cmd to open the terminal and run:
keytool -genkey -v -keystore my-release-key.keystore -alias my-key-alias -keyalg RSA -keysize 2048 -validity 10000
- Enter necessary information
- In the user directory
C:\Users\用户名目录\my-release-key.keystore
, a signature is generated
Step 2 Copy the signed certificate to the android/app directory
Step 3 Reference the keystore in the application
Create a named <app dir>/android/key.properties
file, which contains a reference to a key database:
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>
//示例:
storePassword=000000
keyPassword=000000
keyAlias=my-key-alias
storeFile=my-release-key.keystore
Step 4 Configure signature in gradle
By editing the <app dir>/android/app/build.gradle
configuration file signatures for your application:
- Add in front of android{}:
def keystorePropertiesFile = rootProject.file("key.properties")
def keystoreProperties = new Properties()
keystoreProperties.load(new FileInputStream(keystorePropertiesFile))
- Add in front of buildTypes {:
signingConfigs {
release {
keyAlias keystoreProperties['keyAlias']
keyPassword keystoreProperties['keyPassword']
storeFile file(keystoreProperties['storeFile'])
storePassword keystoreProperties['storePassword']
}
}
buildTypes {
release {
signingConfig signingConfigs.release
}
}
Step 6 Modify the App name and icon
Modify application name
Open the <app dir>/android/app/src/main/
AndroidManifest.xml file, locate the application node editing application label android:label
, change the name of the application.
Modify app icon
- Use Hbuilder tool to quickly generate application icons;
- In the
<app dir>/android/app/src/main/res/
catalog, the icon file into the file using the configuration qualifiers named folder. The icon generated by yourself, according to the standardized name and size, overwrite Flutter's default icon.
Step 5 Build a release APK
- Open the terminal in the project root directory (or directly in the terminal of the editor), run
flutter build apk
Step 6 install apk
- Install on the emulator
运行
flutter install
- Install on real machine
flutter_tets\build\app\outputs\apk\release
You can see the apk in the project directory. After copying it to the phone, install it normally.
Step on the pit
After the real machine is released, the network request cannot be sent. When Android applications need to make network requests, they need to register network permissions in AndroidManifest.
- 1
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
- 2 Add a sentence to application in AndroidManifest
android:usesCleartextTraffic="true"