问题描述
我正在尝试将 HMS 和 GMS 集成到一个带有风味的单个 android 项目中。实际上它是我正在制作的一个库。遵循 https://forums.developer.huawei.com/forumPortal/en/topic/0201247334527450159 中的集成细节
但是我遇到了 gradle 同步问题。
我的gradle代码如下
顶层 build.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
}
库 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")
}
我收到类似的同步错误
org.gradle.api.plugins.UnkNownPluginException: Plugin with id 'com.google.gms.google-services' not found.
解决方法
好像是你忘记添加了
classpath 'com.google.gms:google-services:4.3.8'
就在classpath 'com.android.tools.build:gradle:3.5.3'
之后