【问题标题】:Issue with integrating HMS & GMS in android library在 android 库中集成 HMS 和 GMS 的问题
【发布时间】:2021-07-20 06:21:11
【问题描述】:

我正在尝试将 HMS 和 GMS 集成到具有风味的单个 android 项目中。实际上它是我正在制作的库。遵循来自 https://forums.developer.huawei.com/forumPortal/en/topic/0201247334527450159 的集成细节

但我遇到了 gradle 同步问题。

我的gradle代码如下

顶层构建.gradle

// 顶级构建文件,您可以在其中添加所有子项目/模块通用的配置选项。

buildscript {
    repositories {

        google()

        mavenCentral()
        if (getGradle().getStartParameter().getTaskNames().toString().toLowerCase().contains("hms")) {

            maven { url 'https://developer.huawei.com/repo/' }
        }

        maven { url "https://jcenter.bintray.com" }
    }

}

allprojects {
    repositories {
        if (getGradle().getStartParameter().getTaskNames().toString().toLowerCase().contains("hms")) {
            maven { url 'https://developer.huawei.com/repo/' }
            println("huawei mavenurl code.......")
        }
        jcenter { url "https://jcenter.bintray.com/" }
        maven { url "https://jitpack.io" }
        mavenLocal()
        google()
        mavenCentral()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

库构建.gradle

    buildscript {
    repositories {
        google()
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.5.3'    }
}
apply plugin:'com.android.library'
apply plugin: 'maven'
if (getGradle().getStartParameter().getTaskNames().toString().toLowerCase().contains("hms")) {

    apply plugin: 'com.huawei.agconnect'
}else{
    apply plugin: 'com.google.gms.google-services'
}

android {

    buildToolsVersion "30.0.2"

    defaultConfig {
        compileSdkVersion 30
        minSdkVersion 21
        useLibrary 'org.apache.http.legacy'
        targetSdkVersion 30
        versionCode 1
        versionName "1.0"
        multiDexEnabled true
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
        consumerProguardFiles "consumer-rules.pro"
    }

    publishNonDefault true
    flavorDimensions "osflavour"
    productFlavors {
        hmsVersion {
            dimension "osflavour"
            project.buildscript.classpath 'com.android.tools.build:gradle:3.5.3'
            project.buildscript.classpath 'com.huawei.agconnect:agcp:1.4.1.300'
        }
        ghVersion {
            dimension "osflavour"
            project.buildscript.classpath 'com.android.tools.build:gradle:3.5.3'
            project.buildscript.classpath 'com.google.gms:google-services:4.3.3'   
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
}

dependencies {
    hmsVersionImplementation 'androidx.localbroadcastmanager:localbroadcastmanager:1.1.0-alpha01'   
    hmsVersionImplementation 'androidx.multidex:multidex:2.0.1'
    hmsVersionImplementation 'com.huawei.hms:hianalytics:4.0.3.300'
    hmsVersionImplementation 'com.huawei.hms:location:5.1.0.303'
    hmsVersionImplementation 'com.huawei.agconnect:agconnect-core:1.3.1.300'
    hmsVersionImplementation 'com.huawei.hms:awareness:1.0.5.300'
    hmsVersionImplementation(platform("com.squareup.okhttp3:okhttp-bom:4.9.0"))
    hmsVersionImplementation('com.squareup.okhttp3:okhttp')
    hmsVersionImplementation("com.squareup.okhttp3:logging-interceptor")
    hmsVersionImplementation 'com.google.code.gson:gson:2.8.7'
    hmsVersionImplementation 'androidx.appcompat:appcompat:1.3.0'
  
    ghVersionImplementation 'androidx.localbroadcastmanager:localbroadcastmanager:1.1.0-alpha01'

    ghVersionImplementation 'androidx.multidex:multidex:2.0.1'

    ghVersionImplementation 'com.google.code.gson:gson:2.8.7'
    ghVersionImplementation 'androidx.appcompat:appcompat:1.3.0'
    //ghVersionImplementation 'com.google.android.material:material:1.3.0'
    testImplementation 'junit:junit:4.+'
    ghVersionImplementation 'com.google.firebase:firebase-analytics:19.0.0'

    androidTestImplementation 'androidx.test.ext:junit:1.1.3'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
    ghVersionImplementation 'com.google.android.gms:play-services-awareness:18.0.2'
    ghVersionImplementation 'com.google.android.gms:play-services-location:18.0.0'
    ghVersionImplementation(platform("com.squareup.okhttp3:okhttp-bom:4.9.0"))
    ghVersionImplementation('com.squareup.okhttp3:okhttp')
    ghVersionImplementation("com.squareup.okhttp3:logging-interceptor")
}

我收到类似的同步错误

org.gradle.api.plugins.UnknownPluginException: Plugin with id 'com.google.gms.google-services' not found.

【问题讨论】:

  • 我还要在flutter项目中添加agconnect文件、华为插件代码等

标签: android google-play-services android-library huawei-mobile-services


【解决方案1】:

好像是你忘记加了

classpath 'com.google.gms:google-services:4.3.8'

就在classpath 'com.android.tools.build:gradle:3.5.3'之后

【讨论】:

  • 它在风味部分中
猜你喜欢
  • 2020-05-15
  • 2021-11-21
  • 1970-01-01
  • 1970-01-01
  • 2014-11-01
  • 1970-01-01
  • 1970-01-01
  • 2017-03-03
相关资源
最近更新 更多