Issue with integrating HMS & GMS in android library

Viewed 352

I am trying with integrating HMS and GMS in a single android project with flavours .Actually its a library which I am making.Followed the integration detail from https://forums.developer.huawei.com/forumPortal/en/topic/0201247334527450159

But I am getting gradle sync issues .

My gradle codes are as follows

Toplevel build.gradle

// Top-level build file where you can add configuration options common to all sub-projects/modules.

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
}

Library build.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")
}

I am getting sync error like

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

Seems to be you've forget to add

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

just after classpath 'com.android.tools.build:gradle:3.5.3'

Related