Program type already present: com.google.android.g

2019-01-25 02:51发布

I getting this error. Despite trying all thing I am unable to resolve it. Please help me.

Things that I tried are:

  1. Delete .build, .idea etc then rebuild
  2. Clean and rebuild
  3. Change version of compile library

Thank you

plugins

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'io.fabric'

Android

android {
dexOptions {
    preDexLibraries = false
    javaMaxHeapSize "2g"
}

compileSdkVersion 27
buildToolsVersion '27.0.3'
defaultConfig {
    applicationId "com.funzone.alarmnap"
    minSdkVersion 16
    targetSdkVersion 27
    versionCode 1
    multiDexEnabled true
    versionName "1.1"
    vectorDrawables.useSupportLibrary = true
    testInstrumentationRunner 
    "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}
   }

Greendao Plugin

 apply plugin: 'org.greenrobot.greendao'
 greendao {
   targetGenDir 'src/main/java'
   schemaVersion 2
 }

All libraries:

dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'com.jjoe64:graphview:4.2.1'
implementation "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
implementation 'com.android.support:appcompat-v7:27.1.0'
implementation 'com.facebook.android:audience-network-sdk:4.+'
implementation 'com.facebook.android:facebook-android-sdk:[4,5)'
implementation 'com.facebook.android:notifications:1.0.2'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
implementation 'com.android.support:design:27.1.0'
implementation 'com.android.support:support-v4:27.1.0'
implementation 'com.android.support:support-v13:27.1.0'
implementation 'com.android.support:cardview-v7:27.1.0'
implementation 'com.google.firebase:firebase-messaging:12.0.1'
implementation 'com.google.firebase:firebase-core:12.0.1'
implementation 'com.crashlytics.sdk.android:crashlytics:2.9.1'
implementation 'com.android.support:multidex:1.0.3'
implementation 'org.greenrobot:greendao:3.2.2'
testImplementation 'junit:junit:4.12'
testImplementation "org.robolectric:shadows-multidex:3.0"
testImplementation 'org.robolectric:robolectric:3.4.2'
implementation 'com.android.support:preference-v7:27.1.0'
}




repositories {
mavenCentral()
google()
}

Google plugin

apply plugin: 'com.google.gms.google-services'

12条回答
【Aperson】
2楼-- · 2019-01-25 03:19

I started seeing this after I upgraded to kotlin plugin version : 1.2.41-release-Studio3.1-1.

Upgrading firebase-core and firebase-messaging from 15.0.0 --> 15.0.2. Fixed the problem, database, auth and gms-auth-services are at 15.0.0

查看更多
Fickle 薄情
3楼-- · 2019-01-25 03:20

I fix the same issue in my project - after updating the Kotlin plugin to 1.2.41 (I don't know if it is really related. Edit: apparently this is not related with Kotlin) - with :

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

https://developers.google.com/android/guides/google-services-plugin

Remark: I could stay with the unique 15.0.0 Google Play Services libraries version but not the play-services-tagmanager one and firebase :

implementation "com.google.android.gms:play-services-tagmanager:15.0.2"
implementation "com.google.firebase:firebase-core:15.0.2"

The project is compiling now.

查看更多
等我变得足够好
4楼-- · 2019-01-25 03:22

This is very boring. Google should review these updates better. I tried everything, but my issue was only fixed by returning the version of the Google Play Services APIs:

implementation 'com.google.android.gms:play-services-gcm:11.8.0'

查看更多
对你真心纯属浪费
5楼-- · 2019-01-25 03:23

For me the problem was

dependencies {
       classpath 'com.google.firebase:firebase-plugins:1.1.5'
}

used for Performance Monitoring. Just commented out.

查看更多
贪生不怕死
6楼-- · 2019-01-25 03:26

I fixed the issue using new firebase independent version numbers https://firebase.google.com/support/release-notes/android#latest_sdk_versions

SDK Update - May 2, 2018 -> Firebase Android SDKs now have independent version numbers, allowing for more frequent, flexible updates.

enter image description here

查看更多
时光不老,我们不散
7楼-- · 2019-01-25 03:27

I had the same issue, the thing which is causing this error is 2 versions of same dependency with different services

I changed this:

implementation 'com.google.android.gms:play-services-ads:17.1.0'
implementation 'com.google.android.gms:play-services-analytics:16.0.5'

To:

implementation 'com.google.android.gms:play-services-ads:17.1.1'

these versions are importing same subpackages which is why it is a ambiguity error basically same subpackage is imported from 2 different dependencies (in background)

Have fun coding!!

查看更多
登录 后发表回答