In the development of some problems encountered, record, I hope to be able to friends some help is mainly android multi-channel related problems as records

Plain packaging command

You can also specify a flutter build apk --debug flutter build apk --release. The difference is that android native packs are slightly smaller, Debug package flutter build apk --flavor oppo --debug release package flutter build apk --flavor oppoCopy the code

Then there is the question of customizing apK names

There was an error with the custom APK name on Flutter 1.9.1+ Hotfix6. I don’t know which version of flutter fixed this issue. The current configuration of my project is

Flutter (Channel Stable, V1.12.13 + Hotfix.8, on Microsoft Windows [Version 10.0.17763.1158], Locale zh-CN) • Flutter version 1.12.13+hotfix.8 at D:\ Flutter • Framework Revision 0b8ABB4724 (3 months ago), Dart Version 2.7.0 [√] Android Toolchen-developforAndroid Devices (Android SDK Version 29.0.2) • Android SDK at D:\ Android_sdk • Android NDK location not configured (optional; usefulforNative profiling support) • Platform Android-29, build-tools 29.0.2 • Java binary at: C: Program Files Android Studio jre bin Java • Java version OpenJDK Runtime Environment (build • All Android licenses accepted. [√] Android Studio (Version 3.6) • Android Studio at C:\Program Files\Android\Android Studio • Flutter Plugin version 45.1.1 • Dart Plugin version 192.7761 • Java Version OpenJDK Runtime Environment (build 1.8.0_212-release-1586-b04)Copy the code

This section describes how to record the customized APK package name based on the preceding configuration. You are advised not to customize the APK package name for the DEBUG VERSION of the APK. Otherwise, you will get the apK package name after running the APP

Gradle build failed to produce an .apk file. It's likely that this file was generated under E:\android_svn\flutter_xxx\build, but the tool couldn'T find it. Gradle build cannot generate. Apk file. The file might have been generated under E: \ android_svn \ flutter_xxx \ build, but the tool could not find it.Copy the code

Although there is also apk file in the output path of the successful run, the tool cannot find app-debug.apk because of the customized package name, so it is recommended to determine the customized package name when variable. buildType.name is release.

Next up is android configuration multi-channel correlation,

If the multi-channel build fails to be configured, the following error is reported:

ERROR: All flavors must now belong to a named flavor dimension. Learn more at https://d.android.com/r/tools/flavorDimensions-missing-error-message.html
Affected Modules: app

Copy the code

Need to add it in Android under app\build.gradle or in defaultConfig

    flavorDimensions "(Dimensions you define)"If you just want them to avoid errors and don't use this property, you can give a default, like flavorDimensions below"default"Add this dimension to your app store configuration like xiaomi {dimension"default"
            manifestPlaceholders = [MTA_CHANNEL_VALUE: Xiaomi App Store]
        }
        huawei {
            dimension "default"
            manifestPlaceholders = [MTA_CHANNEL_VALUE: Huawei App Market]}Copy the code

Android official website – Configuration build variants

Problems after configuring multiple channels

If run without processing, although can generate APK file, but will fail to run, and each run will run all your channels, such as: my product channels are as follows

    productFlavors {
        baidu {
            dimension "default"
            manifestPlaceholders = [MTA_CHANNEL_VALUE: "Baidu Mobile Assistant"]
        }
        xiaomi {
            dimension "default"
            manifestPlaceholders = [MTA_CHANNEL_VALUE: Xiaomi App Store]
        }
        huawei {
            dimension "default"
            manifestPlaceholders = [MTA_CHANNEL_VALUE: Huawei App Market]
        }
        yingyongbao {
            dimension "default"
            manifestPlaceholders = [MTA_CHANNEL_VALUE: Tencent App Treasure]
        }
        _360 {
            dimension "default"
            manifestPlaceholders = [MTA_CHANNEL_VALUE: "360 Mobile Assistant"]
        }
        oppo {
            dimension "default"
            manifestPlaceholders = [MTA_CHANNEL_VALUE: "OPPO App Store"]
        }
        vivo {
            dimension "default"
            manifestPlaceholders = [MTA_CHANNEL_VALUE: VIVO App Store]}}Copy the code

After running, all channel packages will be run, and the apK output generated is app-mium-debug. apk, similar to this, which will be reported

Finished with error: Gradle build failed to produce an .apk file. It's likely that this file was generated under E:\android_svn\flutter_xxx\build, but the tool couldn't find it.
Copy the code

No APK can be found to run,

The solution

Dart method 2: Modify the runtime configuration of flutter run –flavor xiaomi -t lib/main.dart and select your own