首发于 移动开发

解决Flutter在android端多渠道打包问题

1. 生成签名( 多一个维度的世界:Android端证书生成 )

2. 配置签名 (是否需要配置签名信息根据实际情况而定,理论上与多渠道无关,不感兴趣的同学跳过)

首先,可以在gradle.properties文件定义一些和签名相关的参数,也可以直接写到到配置,这里主要方便统一管理

KEY_ALIAS=flutter_demo_realease
KEY_PASSWORD=flutter
KEYSTORE_PASSWORD=flutter
KEYSTORE_FILE=../release.jks
DEBUG_KEY_ALIAS=flutter_demo_debug
DEBUG_KEY_PASSWORD=flutter_debug
DEBUG_KEYSTORE_PASSWORD=flutter_debug
DEBUG_KEYSTORE_FILE=../debug.jks

然后,配置好签名即可:

signingConfigs{
 debug{
        keyAlias DEBUG_KEY_ALIAS
        keyPassword DEBUG_KEY_PASSWORD
        storePassword DEBUG_KEYSTORE_PASSWORD
        storeFile rootProject.file(DEBUG_KEYSTORE_FILE)
 release{
        keyAlias KEY_ALIAS
        keyPassword KEY_PASSWORD
        storePassword KEYSTORE_PASSWORD
        storeFile rootProject.file(KEYSTORE_FILE)
}

3. 配置环境

buildTypes {
 debug {
        minifyEnabled false
        signingConfig signingConfigs.debug
        ndk {
              abiFilters "armeabi","armeabi-v7a","arm64-v8a", "x86"
 release {
        minifyEnabled true
        zipAlignEnabled true
        shrinkResources true
        signingConfig signingConfigs.release
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        ndk {
             abiFilters "armeabi","armeabi-v7a","arm64-v8a", "x86"
}

4. 配置渠道

flavorDimensions "flutter_demo"
productFlavors {
 dev {
 dimension "flutter_demo"
 applicationId "${defaultConfig.applicationId}.dev"
 manifestPlaceholders = [
 app_name: "flutter_dev",
 app_icon: "@drawable/launch_background"
 production{
 dimension "flutter_demo"
 applicationId "${defaultConfig.applicationId}.production"