Using multi-flavor to compile GMS and HMS packages. But an error is reported when the GMS version is compiled

Viewed 7324

I have an app that has two compilation flavors configured, one that uses HMS and the other that does not. During the compilation of flavors that do not use the HMS, the package name is inconsistent with that in the JSON file. As a result, an error occurs.

Task failed with an exception.
-----------
* What went wrong:
Execution failed for task ':app:processAppgalleryconnectLatestDebugAGCPlugin'.
> ERROR: Failed to verify AGConnect-Config '/client/package_name', expected: 'com.dise.appge.hms', but was: 'com.dise.appge.gms'

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
==============================================================================

So how to solve this problem when different flavors use different package names?

2 Answers

Respective plugins can be applied in productFlavors block, there's no need to compare anything:

flavorDimensions "vendor"
productFlavors {
    google {
        dimension "vendor"
        apply plugin: "com.google.gms.google-services"
        apply plugin: "com.google.firebase.crashlytics"
        applicationIdSuffix ".gms"
    }
    huawei {
        dimension "vendor"
        apply plugin: "com.huawei.agconnect"
        applicationIdSuffix ".hms"
    }
}

You can configure it in build.gradle of the application. For example, if two flavors, HMS and GMS, you can try to add the following code:

if (getGradle().getStartParameter().getTaskNames().toString().contains("HMS")) {
    apply plugin: 'com.huawei.agconnect'
}

That is, the AGC plug-in is not added during GMS compilation to avoid the problem of inconsistent package names in the JSON file.

Related