Flutter 多渠道打包(Android)

熟悉Android多渠道的同学们知道,多渠道设置方法大概这样的:
在build.gradle 里 加上如下代码:

android{
...
productFlavors{
        tencent{
            manifestPlaceholders = [TD_CHANNEL_ID:"tencent"]
        }
        huawei{
            manifestPlaceholders = [TD_CHANNEL_ID:"huawei"]
        }
    }
...
}

然后gradle 同步会报错,


image.png

接下来加上这句:

defaultConfig{
···
flavorDimensions "versionCode"
}

打包命令:
flutter build apk
报错:

The Gradle project does not define a task suitable for the requested build.
The android/app/build.gradle file defines product flavors: huawei, tencent
You must specify a --flavor option to select one of them.
Gradle build aborted.

应该使用这个命令打包:
flutter build apk --flavor tencent

如果在Android Studio里 运行报错的话:

The Gradle project does not define a task suitable for the requested build.
The android/app/build.gradle file defines product flavors: huawei, tencent
You must specify a --flavor option to select one of them.
Finished with error: Gradle build aborted.

需要设置一下:


image.png

选择Edit Configurations:

image.png

即可正常运行。

你可能感兴趣的:(Flutter 多渠道打包(Android))