5

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?

zhangxaochen
  • 32,744
  • 15
  • 77
  • 108
ooWYXNoo
  • 59
  • 1
  • 4

2 Answers2

4

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"
    }
}
Martin Zeitler
  • 1
  • 19
  • 155
  • 216
  • Thanks for the reply Martin, in my project, as other flavors will be added in the future, I combined yours and shirley's solution, use: ```if (getGradle().getStartParameter().getTaskNames().toString().contains("HMS")) { apply plugin: 'com.huawei.agconnect' } else { apply plugin: "com.google.gms.google-services" } ```It works great now! – ooWYXNoo Aug 26 '21 at 01:56
3

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.

Martin Zeitler
  • 1
  • 19
  • 155
  • 216
zhangxaochen
  • 32,744
  • 15
  • 77
  • 108