【问题标题】:Using multi-flavor to compile GMS and HMS packages. But an error is reported when the GMS version is compiled使用多风格编译 GMS 和 HMS 包。但是GMS版本编译的时候报错
【发布时间】:2021-10-25 10:55:45
【问题描述】:

我有一个应用程序配置了两种编译风格,一种使用 HMS,另一种不使用。编译不使用HMS的flavor时,包名与json文件不一致。结果出现错误。

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.
==============================================================================

那么当不同风味使用不同的包名时如何解决这个问题呢?

【问题讨论】:

    标签: android json firebase package huawei-mobile-services


    【解决方案1】:

    您可以在应用程序的 build.gradle 中配置它。比如HMS和GMS两种口味,可以尝试添加如下代码:

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

    即GMS编译时不添加AGC插件,避免JSON文件中包名不一致的问题。

    【讨论】:

    • 感谢您的解决方案,它为我节省了很多时间:)
    【解决方案2】:

    productFlavors区块中可以应用各个插件,无需比较:

    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的回复,在我的项目中,由于未来会添加其他口味,我结合了你和shirley的解决方案,使用:if (getGradle().getStartParameter().getTaskNames().toString().contains("HMS")) { apply plugin: 'com.huawei.agconnect' } else { apply plugin: "com.google.gms.google-services" } 现在很好用!
    猜你喜欢
    • 2021-11-21
    • 2020-05-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多