content
- Add splash map (optional)
- Add APP name and snapshot name
- AndroidManifest.xml
- main.dart
- Check and configure build.gradle file
- applicationId
- versionCode & versionName:
- minSdkVersion & targetSdkVersion
- Add APP launch icon
- Add network access
AndroidManifest.xml
add in<uses-permission android:name="android.permission.INTERNET"/>
- Signature APP
- Build a release package
- Released to major Android application markets
Add splash screen
Add startup background image
drawable-v21\launch_background.xml
anddrawable\launch_background.xml
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
+ <item android:drawable="@drawable/splash_screen_background" />
</layer-list>
Set the startup screen to full screen
styles.xml
<style name="LaunchTheme" parent="@android:style/Theme.Light.NoTitleBar">
<item name="android:windowBackground">@drawable/launch_background</item>
+ <item name="android:windowFullscreen">true</item>
</style>
Support Liu Haiping
AndroidManifest.xml
<activity
android:name=".MainActivity"
android:launchMode="singleTop"
android:theme="@style/LaunchTheme"
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
android:hardwareAccelerated="true"
android:windowSoftInputMode="adjustResize">
<!-- 支持刘海屏-->
+ <meta-data android:name="android.notch_support" android:value="true"/>
Set the status bar to transparent color
package org.devio.flutter.bili.flutter_bili_app
+ import android.graphics.Color
+ import android.os.Build
+ import android.os.Bundle
import io.flutter.embedding.android.FlutterActivity
class MainActivity : FlutterActivity() {
+ override fun onCreate(savedInstanceState: Bundle?) {
+ super.onCreate(savedInstanceState)
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
+ val window = activity.window
+ //设置状态栏为透明色,fix 启动时状态栏会灰色闪一下
+ window.statusBarColor = Color.TRANSPARENT
+ }
+ }
}
Signature APP
The keystore is required to build the release package. If you do not have a keystore, you can create it in the following ways:
Create keystore
Mac:
keytool -genkey -v -keystore ~/key.jks -keyalg RSA -keysize 2048 -validity 10000 -alias key
Windows:
keytool -genkey -v -keystore c:\Users\USER_NAME\key.jks -storetype JKS -keyalg RSA -keysize 2048 -validity 10000 -alias key
- -keystore: user-specified storage path
key.jks
Then follow the prompts to enter, and a file will be created in the above path after all the entries are completed . Then copy the file to the android directory under the Flutter project.
Placement keystore
你的flutter应用/android
Create a file in the directory key.properties
and add:
storePassword=<password from previous step>
keyPassword=<password from previous step>
keyAlias=key
storeFile=../key.jks
Configure package signature
你的flutter应用/android/app/build.gradle
Open the file with AS and android
add above the code block:
def keystoreProperties = new Properties()
def keystorePropertiesFile = rootProject.file('key.properties')
if (keystorePropertiesFile.exists()) {
keystoreProperties.load(new FileInputStream(keystorePropertiesFile))
}
android {
...
}
Then in the android
code block add signingConfigs
:
signingConfigs {
release {
keyAlias keystoreProperties['keyAlias']
keyPassword keystoreProperties['keyPassword']
storeFile file(keystoreProperties['storeFile'])
storePassword keystoreProperties['storePassword']
}
}
Finally add the configuration in the buildTypes
code block :release
buildTypes {
release {
signingConfig signingConfigs.release
}
}
Build the release package
Build installation packages for all architectures
./gradlew assembleRelease
The built Release package contains all ABI architectures.
Build a single-architecture installation package
cd <flutter应用的android目录>
flutter build apk --split-per-abi
flutter build
: The command will build the release package by default--split-per-abi
: Indicates building a single schema
Upload app
After the installation package is built, it is released to the major Android application markets. No matter which application market is long-term, the developers who have registered for the platform must first pass the developer certification before uploading the application.
There are detailed tutorials and problems for developer registration and application uploading on major platforms. Let’s share the relatively large domestic application market:
- Huawei: Huawei-Consumer Business Official Website
- Xiaomi: Xiaomi Open Platform
- OPPO: OPPO Open Platform
- vivo: vivo open platform
- Baidu: Baidu Mobile Application Platform
Those in need can follow the official instructions to register and upload the application.
FAQ
Unable to package with code compression enabled
Many students will find that when code compression is enabled (minifyEnabled true), an error is reported when the release package is printed, and the release package cannot be printed, so just upgrade the targetSdkVersion and compileSdkVersion to 28.
Associated issue @ https://github.com/flutter/flutter/issues/26860#issuecomment-469751224
Install the release package and run the crash report that the so package cannot be found
Flutter build apk will build installation packages containing x86_64, arm64-v8a, armeabi-v7a architectures, but if a library depends on the project is inconsistent with the architecture supported by Flutter, there will be a crash that so cannot find
, such as: The XX tripartite library only has the so of armeabi-v7a. When the APP is installed on a mobile phone that supports arm64-v8a, the mobile phone finds that the APP contains the arm64-v8a directory, so it searches for the so of the so-and-so tripartite library in this directory. Error if not found.
The solution is to only armeabi-v7a
use flutter so, so the following configuration needs to be added before the release package:
ndk {
// abiFilters "armeabi-v7a","arm64-v8a","x86_64","x86" //只打包flutter所支持的架构,flutter没有armeabi架构的so,加x86的原因是为了能够兼容模拟器
abiFilters "armeabi-v7a" //release 时只打"armeabi-v7包
}