直到有一天,我的项目一直运行良好,因为没有任何原因(我没有改变任何东西),Gradle开始给出这个奇怪的错误:
Program type already present: com.google.android.gms.internal.measurement.zzabo
出现此错误时,我的项目级Gradle如下所示:
buildscript {
repositories {
jcenter()
maven {
url 'https://maven.google.com'
// Alternative URL is 'https://dl.google.com/dl/android/maven2/'
}
maven { url 'https://plugins.gradle.org/m2/'}
maven { url 'https://maven.fabric.io/public' }
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.2'
classpath 'com.google.gms:google-services:4.0.0'
classpath 'io.fabric.tools:gradle:1.25.3'
classpath 'gradle.plugin.com.onesignal:onesignal-gradle-plugin:0.8.1'
}
}
allprojects {
repositories {
jcenter()
maven {
url 'https://dl.bintray.com/sayyam/maven'
}
maven {
url "https://jitpack.io"
}
maven {
url 'https://maven.google.com'
}
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
这是我的应用程序级毕业生:
apply plugin: 'com.android.application'
apply plugin: 'com.onesignal.androidsdk.onesignal-gradle-plugin'
apply plugin: 'io.fabric'
android {
compileSdkVersion 27
buildToolsVersion "27.0.3"
dexOptions {
javaMaxHeapSize "4g"
}
packagingOptions {
exclude 'META-INF/rxjava.properties'
}
defaultConfig {
applicationId "com.example"
deviceCheck
minSdkVersion 17
targetSdkVersion 27
versionCode 8
versionName "1.0"
vectorDrawables.useSupportLibrary = true
multiDexEnabled true
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
}
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'com.google.firebase:firebase-invites:15.0.1'
implementation 'com.google.firebase:firebase-core:15.0.2'
implementation 'com.crashlytics.sdk.android:crashlytics:2.9.2'
implementation 'com.google.android.gms:play-services-maps:15.0.1'
implementation 'com.google.android.gms:play-services-location:15.0.1'
implementation 'com.google.android.gms:play-services-places:15.0.1'
implementation 'com.google.maps.android:android-maps-utils:0.5'
implementation 'com.android.support:support-v13:27.1.1'
implementation 'com.android.support:support-v4:27.1.1'
implementation 'com.android.support:appcompat-v7:27.1.1'
.....other dependencies.....
testImplementation 'junit:junit:4.12'
}
apply plugin: 'com.google.gms.google-services'
我找了找
this
在StackOverflow上应答。这说明这个问题可能与FireBase依赖版本和谷歌服务插件有关。所以我更新了
google-services
插件版本到
4.0.0
和FireBase的最新版本
16.0.0
. 正如人们从Gradle可以预料到的,它给出了另一个错误,似乎与FireBase版本16.0.0有关。
每当我将FireBase版本更改为16.0.0时,显然它也试图自动将Google Play服务依赖项升级为16.0.0。根本不存在!它引发以下渐变错误:
Failed to resolve: com.google.android.gms:play-services-maps:16.0.0
Failed to resolve: com.google.android.gms:play-services-location:16.0.0
Failed to resolve: com.google.android.gms:play-services-places:16.0.0
Failed to resolve: com.google.android.gms:play-services-gcm:16.0.0
Failed to resolve: com.google.android.gms:play-services-base:16.0.0
Failed to resolve: com.google.android.gms:play-services-basement:16.0.0
Failed to resolve: com.google.android.gms:play-services-measurement-base:16.0.0
Failed to resolve: com.google.android.gms:play-services-tasks:16.0.0
Failed to resolve: com.google.android.gms:play-services-stats:16.0.0
Failed to resolve: com.google.android.gms:play-services-ads-identifier:16.0.0
我试图使用解决策略强制使用GMS库的版本,但没有效果。我该怎么办?我做错什么了?
注意:我没有明确更改PlayServicesLibraries的版本,Gradle似乎是因为FireBase才这么做的。
编辑:
这个问题可以通过下面给出的解决方案来解决
this
问题,但仍然不重复,因为在我的例子中,OneSignal插件只是更新
GMS
库版本与否
火碱
版本。所以任何面临这个问题的人都不会搜索
这
问题。