95

Yesterday,my app was working fine.

Today, I don't know why, the app didn't compile anymore after I reopened the Android Studio.

The error shown is

Program type already present: com.google.android.gms.internal.measurement.zzwp
Message{kind=ERROR, text=Program type already present: com.google.android.gms.internal.measurement.zzwp, sources=[Unknown source file], tool name=Optional.of(D8)}

I really don't know what's going on, I've searched everything and nothing worked. If someone could help me, I would really appreciate. I change all dependencies and libraries to try to solve it, but nothing worked.

Here is build.gradle Project

buildscript {

    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.1.1'
        classpath 'com.google.gms:google-services:3.2.1'


        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        maven { url 'https://jitpack.io' }
        google()
        jcenter()
    }
}

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

And this is my build.gradle Module:app

apply plugin: 'com.android.application'

android {
    compileSdkVersion 27
    defaultConfig {
        applicationId "com.doctordirectory"
        minSdkVersion 21
        targetSdkVersion 27
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        multiDexEnabled true
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

repositories {
    maven { url "https://jitpack.io" }
}

dependencies {
    implementation fileTree(dir: 'libs')
    implementation 'com.android.support:appcompat-v7:27.1.0'
    implementation 'com.android.support.constraint:constraint-layout:1.1.0'
    implementation 'com.github.PhilJay:MPAndroidChart:v3.0.3'

    implementation ('com.facebook.android:audience-network-sdk:4.28.0',{
        exclude group: 'com.google.android.gms'
    })
    implementation 'com.facebook.android:facebook-login:4.32.0'
    implementation 'com.android.support:multidex:1.0.3'

    implementation 'com.readystatesoftware.sqliteasset:sqliteassethelper:+'

    implementation 'com.android.support:support-v4:27.1.0'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'

    implementation 'com.google.firebase:firebase-core:15.0.0'
    implementation 'com.google.firebase:firebase-database:15.0.0'
    implementation 'com.google.firebase:firebase-crash:15.0.0'
    implementation 'com.google.firebase:firebase-auth:15.0.0'
    implementation 'com.google.firebase:firebase-storage:15.0.0'
    implementation 'com.firebaseui:firebase-ui-database:3.3.1'

    implementation 'com.google.android.gms:play-services-auth:15.0.0'
    implementation 'com.google.android.gms:play-services-plus:15.0.0'
    implementation 'com.google.android.gms:play-services-location:15.0.0'

    implementation 'com.android.support:cardview-v7:27.1.0'
    implementation 'com.android.support:recyclerview-v7:27.1.0'

    implementation 'com.squareup.picasso:picasso:2.5.2'
    implementation 'com.squareup.retrofit2:retrofit:2.3.0'
    implementation 'com.squareup.retrofit2:converter-gson:2.3.0'

    implementation 'com.stepstone.apprating:app-rating:2.2.0'
    implementation 'com.android.support:design:27.1.0'
    implementation 'com.android.support:design:27.1.0'
    implementation 'com.github.lguipeng:BubbleView:1.0.1'

    implementation 'uk.co.chrisjenx:calligraphy:2.3.0'

    implementation 'com.miguelcatalan:materialsearchview:1.4.0'

    implementation 'com.github.MdFarhanRaja:SearchableSpinner:1.9'

    implementation 'com.github.sillebille:dynamic-calendar:1.0.1'

    implementation 'com.google.api-client:google-api-client:1.22.0'
    implementation 'com.google.api-client:google-api-client-android:1.22.0'
    implementation 'com.google.apis:google-api-services-people:v1-rev4-1.22.0'
}

apply plugin: 'com.google.gms.google-services'
Venki WAR
  • 1,997
  • 4
  • 25
  • 38
Caio Araújo
  • 931
  • 1
  • 6
  • 7

14 Answers14

95

Resolved this issue after updating a firebase dependencies to latest one for example com.google.firebase:firebase-core:15.0.0 to com.google.firebase:firebase-core:15.0.2 Get Latest List from here

All other changes made in below list

  dependencies {
        implementation fileTree(dir: 'libs', include: ['*.jar'])
        implementation 'com.android.support:appcompat-v7:27.1.1'
        implementation 'com.android.support:customtabs:27.1.1'
        implementation 'com.android.support.constraint:constraint-layout:1.1.0'
        testImplementation 'junit:junit:4.12'
        androidTestImplementation 'com.android.support.test:runner:1.0.2'
        androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'

        implementation 'com.github.PhilJay:MPAndroidChart:v3.0.3'

        implementation 'com.facebook.android:audience-network-sdk:4.28.0'
        implementation 'com.facebook.android:facebook-login:4.32.0'
        implementation 'com.android.support:multidex:1.0.3'

        implementation 'com.readystatesoftware.sqliteasset:sqliteassethelper:2.0.1'

        implementation 'com.android.support:support-v4:27.1.1'
        testImplementation 'junit:junit:4.12'
        androidTestImplementation 'com.android.support.test:runner:1.0.2'
        androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'

        implementation 'com.google.firebase:firebase-core:15.0.2'
        implementation 'com.google.firebase:firebase-database:15.0.0'
        implementation 'com.google.firebase:firebase-crash:15.0.2'
        implementation 'com.google.firebase:firebase-auth:15.0.0'
        implementation 'com.google.firebase:firebase-storage:15.0.2'
        implementation 'com.firebaseui:firebase-ui-database:3.3.1'

        implementation 'com.google.android.gms:play-services-auth:15.0.0'
        implementation 'com.google.android.gms:play-services-plus:15.0.0'
        implementation 'com.google.android.gms:play-services-location:15.0.0'

        implementation 'com.android.support:cardview-v7:27.1.1'
        implementation 'com.android.support:recyclerview-v7:27.1.1'

        implementation 'com.squareup.picasso:picasso:2.5.2'
        implementation 'com.squareup.retrofit2:retrofit:2.3.0'
        implementation 'com.squareup.retrofit2:converter-gson:2.3.0'

        implementation 'com.stepstone.apprating:app-rating:2.2.0'
        implementation 'com.android.support:design:27.1.1'
        implementation 'com.github.lguipeng:BubbleView:1.0.1'

        implementation 'uk.co.chrisjenx:calligraphy:2.3.0'

        implementation 'com.miguelcatalan:materialsearchview:1.4.0'

        implementation 'com.github.MdFarhanRaja:SearchableSpinner:1.9'

        implementation 'com.github.sillebille:dynamic-calendar:1.0.1'

        implementation 'com.google.api-client:google-api-client:1.22.0'
        implementation 'com.google.api-client:google-api-client-android:1.22.0'
        implementation 'com.google.apis:google-api-services-people:v1-rev4-1.22.0'
    }

2) In top level build.gradle file update from classpath 'com.google.gms:google-services:3.1.1 to classpath 'com.google.gms:google-services:3.2.1

MJM
  • 5,119
  • 5
  • 27
  • 53
  • 5
    This solution works. Firebase is now distributing their packages with independent version numbers, ensure all packages on build.gradle are the latest one. – Tri Nguyen May 03 '18 at 05:18
  • It worked. Thank you really much. I tried to update things, but I had never imagined that firebase changed that. Thank you. – Caio Araújo May 03 '18 at 11:32
  • It's good that you've edited and added second part from my answer, because your answer is accepted ;) – Ragaisis May 03 '18 at 13:40
  • m too having another kind of issue "Program type already present: org.apache.http.io.HttpMessageParser Message{kind=ERROR, text=Program type already present: org.apache.http.io.HttpMessageParser,sources=[Unknown source file], tool name=Optional.of(D8)}," m using latest version of firebase and latest version of support,design libraries, also my project's build.gradle holds classpath 'com.android.tools.build:gradle:3.1.2' classpath 'com.google.gms:google-services:4.0.0', still issue occurs .. – immutable Jun 20 '18 at 16:59
  • @immutable share your gradle file – MJM Jun 21 '18 at 03:21
  • 1
    I've seen over the time that the best solution is to update these dependencies to the latest version that appears ON THEIR SITE, not the latest that appears in the gradle file – Razvan Nov 10 '18 at 09:40
  • Great answer, i was facing issues with google analytics. i visited this page from Google to find out exact version to use, and it worked by updating project properties of my android project > http://developers.google.com/android/guides/setup – RohitAneja May 06 '20 at 17:18
21

I've got this error too and my solution to this problem

1) Update Firbase version to be independent from Google Play services version

implementation "com.google.firebase:firebase-messaging:15.0.2"

You can check latest version here https://firebase.google.com/support/release-notes/android#latest_sdk_versions

2) In top level build.gradle file update google-services from 3.1.1 to 3.2.1

buildscript {
    dependencies {

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

    }
 }
Ragaisis
  • 2,700
  • 1
  • 26
  • 41
12

I just change

implementation 'com.google.firebase:firebase-crash:15.0.0'

to

implementation 'com.google.firebase:firebase-crash:15.0.2'

it works.

Faysal Ahmed
  • 7,501
  • 5
  • 28
  • 50
7

Firebase is the reason they are updating version numbers like they don't care about the developers.

First things first. Update the classpath in project level gradle

dependencies {

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

    }

Next, Whatever the tools you might be using like analytics, dynamic links, and so forth. Use the appropriate versioned dependency.

https://firebase.google.com/support/release-notes/android

In my case, I was using A/B testing through remote config, so I need to update it from

implementation 'com.google.firebase:firebase-config:15.0.0'

to

implementation 'com.google.firebase:firebase-config:15.0.2'

This should work without any glitch. And also, please post this kind of issues to Firebase so that they don't do this kind of changes without a heads-up or without a proper documentation.

Pang
  • 9,564
  • 146
  • 81
  • 122
  • 2
    "Firebase is the reason they are updating version numbers like they don't care about the developers." Nicely said – Raj May 05 '18 at 00:43
6

Update your firebase dependencies.

1. Project level build.gradle

Update google.gms version to latest. Track latest release. At time of answer latest is 4.1.0.

buildscript {
    // ...
    dependencies {
        // ...
        classpath 'com.google.gms:google-services:4.1.0' // google-services plugin
    }
}

allprojects {
    // ...
    repositories {
        // ...
        google() // Google's Maven repository
    }
}

2. App level build.gradle

Update below dependency if you use any. Note that firebase has individual versions for every dependency now.

Use latest Firebase Libraries. At the time of answer latest versions are below.

Firebase Core                com.google.firebase:firebase-core:16.0.3
Ads                          com.google.firebase:firebase-ads:15.0.1
Analytics                    com.google.firebase:firebase-analytics:16.0.3
App Indexing                 com.google.firebase:firebase-appindexing:16.0.1
Authentication               com.google.firebase:firebase-auth:16.0.3
Cloud Firestore              com.google.firebase:firebase-firestore:17.1.0
Cloud Functions              com.google.firebase:firebase-functions:16.1.0
Cloud Messaging              com.google.firebase:firebase-messaging:17.3.2
Cloud Storage   c            om.google.firebase:firebase-storage:16.0.2
Crash Reporting              com.google.firebase:firebase-crash:16.2.0
Crashlytics                  com.crashlytics.sdk.android:crashlytics:2.9.5
Dynamic Links                com.google.firebase:firebase-dynamic-links:16.1.1
Invites                      com.google.firebase:firebase-invites:16.0.3
In-App Messaging             com.google.firebase:firebase-inappmessaging:17.0.1
In-App Messaging Display     com.google.firebase:firebase-inappmessaging-display:17.0.1
ML Kit: Model Interpreter    com.google.firebase:firebase-ml-model-interpreter:16.2.0
ML Kit: Vision               com.google.firebase:firebase-ml-vision:17.0.0
ML Kit: Image Labeling       com.google.firebase:firebase-ml-vision-image-label-model:15.0.0
Performance Monitoring       com.google.firebase:firebase-perf:16.1.0
Realtime Database            com.google.firebase:firebase-database:16.0.2
Remote Config                com.google.firebase:firebase-config:16.0.0

3. Don't forget google plugin

Also don't forget to add apply plugin: 'com.google.gms.google-services' at bottom of app level build.gradle.

Sync and Build...

Khemraj Sharma
  • 57,232
  • 27
  • 203
  • 212
  • 1
    Nice tips about checking latest versions. I prefer to use https://bintray.com/android/android-tools/com.google.gms.google-services to check the latest version of `google-services`. The mvn page is very confusing with its `Central` and `Springs Plugins` sections. – Sébastien Nov 07 '18 at 16:01
5

Remove dependency that contains "com.google.android.gms" and then try to rebuild the project ...you have to do hit n try coz there is some dependency which uses twice there

For example com.android.support:design added twise

MJM
  • 5,119
  • 5
  • 27
  • 53
Arul Harsh
  • 133
  • 9
4

I faced the same problem today. Google comes with the new release on 02 May 2018.

Please go to the link and set the version no according to the doc:

https://firebase.google.com/support/release-notes/android#20180502

for e.g.

Firebase Core com.google.firebase:firebase-core:15.0.2

Sandeep Singh
  • 1,013
  • 1
  • 11
  • 25
4

This happened with me after adding firebase analitycs last vesion, like this

implementation "com.google.firebase:firebase-core:16.0.5"

changing version to 16.0.4 helped

implementation "com.google.firebase:firebase-core:16.0.4"
snersesyan
  • 1,647
  • 17
  • 26
2

For me the problem seemed to be caused by the android build tools

To fix, I had to downgrade these in mu projects top level build.gradle file

-        classpath 'com.android.tools.build:gradle:3.1.0'
+        classpath 'com.android.tools.build:gradle:3.0.1'

I'm aware this is not the best solution, but so far the only thing that worked for me.

EDIT: Alternatively, add android.enableD8=false to your project gradle.properties file

RWIL
  • 8,729
  • 1
  • 28
  • 37
2

Commenting out the following dependency fixed the issue for me:

implementation 'com.google.android.gms:play-services-analytics::16.0.7'
Patrick Goley
  • 5,397
  • 22
  • 42
2
allprojects {
    repositories {
    //start here
    configurations.all {
 resolutionStrategy.eachDependency { DependencyResolveDetails details ->
   def requested = details.requested
       if (requested.group == 'com.google.android.gms') {
          details.useVersion '12.0.1'
       }
       if (requested.group == 'com.google.firebase') {
          details.useVersion '12.0.1'
         }
       }
     }
    //end
     jcenter()
       maven {
         url "https://maven.google.com"
       }
     }
 }
1

Ok, wait a second. I've verified that not all Firebase libraries need that version. The versions are now misaligned. In fact on the official page reports that some are at 15.1.0 instead of 15.0.2;

Maybe see directly here if it can be useful:

https://firebase.google.com/docs/android/setup

AlexPad
  • 10,364
  • 3
  • 38
  • 48
1

I had a similar situation with this error:

Program type already present: com.google.android.gms.internal.*

I was using OneSignal and React native maps at the same time, I excluded gms from both and included it at the upper level.

See the troubleshooting section here: https://github.com/react-native-community/react-native-maps/blob/master/docs/installation.md#troubleshooting

Guy
  • 1,254
  • 17
  • 16
0

If you face other issues that block compilation, try upgrading the Google Services dependency to 3.2.0. For me, at least, 3.2.1 and 3.3.0 were causing issues and 3.2.0 was that one that worked.

najm
  • 834
  • 1
  • 13
  • 32
  • but i thought 3.2.1 is required for crashlytics to build ? – j2emanue May 04 '18 at 07:26
  • @j2emanue I personally am not using Crashlytics so I can't confirm but both 3.2.1 and 3.3.0 were preventing other dependencies from compiling. – najm May 04 '18 at 19:59