9

I am getting this error whenever I try to run a program in Android Studio 3.1.2.

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

My gradle Module app :

buildscript {
repositories {
    google()
    jcenter()

    maven {
        url "https://maven.google.com" // Google's Maven repository
    }
}
dependencies {
    classpath 'com.android.tools.build:gradle:3.1.2'
    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 {
    google()
    jcenter()

    maven {
        url "https://maven.google.com"
    }
    maven {
        url "https://maven.fabric.io/public"
    }
}

}

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

}

This is my Gradle Module app

apply plugin: 'com.android.application'

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

compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_8
    targetCompatibility JavaVersion.VERSION_1_8
}

}

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
//noinspection GradleCompatible
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation'com.android.support:design: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'enter code here



// FirebaseUI for Firebase Auth
implementation 'com.firebaseui:firebase-ui-auth:3.3.1'
implementation 'com.google.firebase:firebase-auth:15.0.0'
//Firebase RealTime Database
implementation 'com.google.firebase:firebase-database:15.0.0'
// FirebaseUI for Cloud Storage
implementation 'com.firebaseui:firebase-ui-storage:3.3.1'
implementation 'com.google.firebase:firebase-storage:15.0.0'

//circleimageView
implementation 'de.hdodenhof:circleimageview:2.1.0'

//Libreria utilizada para medir dimension de layout de chat cuando cambia de tamaño
implementation 'net.the4thdimension:android-utils:2.0.4'

//To scale every screen sizes , sp
implementation 'com.intuit.sdp:sdp-android:1.0.5'

//authenticacion para formato de numero de telefono
implementation 'com.googlecode.libphonenumber:libphonenumber:8.4.2'
implementation 'com.weiwangcn.betterspinner:library-material:1.1.0'
implementation 'com.amitshekhar.android:android-networking:1.0.0'

//Volley
implementation 'com.android.volley:volley:1.0.+'
implementation 'org.apache.commons:commons-lang3:3.6'

}

apply plugin: 'com.google.gms.google-services'
Liliana J
  • 549
  • 1
  • 5
  • 13
  • check this also: https://stackoverflow.com/questions/50182756/multiple-dex-files-define-lcom-google-android-gms-internal-measurement-zzabn/50183239 – Peter Haddad May 07 '18 at 06:29

6 Answers6

7

If the issues persists after updating the google play gradle plugin version to latest version, search for the given file in the entire project using the Android Studio File Search and look for the searches with the same package name. The issue was that the file with the same package and file name was present in two different jars (In my case, one jar was of old google analytics services jar which had been manually downloaded and added as a library in the project). Please check image for clarity. We have to resolve this conflict (I had removed my old jar as it was no longer needed) and the project would build.

2

Firebase Android SDKs now have independent version numbers, allowing for more frequent, flexible updates.

Update the google play gradle plugin version to latest version, currently 3.3.0.

classpath 'com.google.gms:google-services:3.3.0'
Gabriele Mariotti
  • 320,139
  • 94
  • 887
  • 841
  • 2
    Finally I solved the issue, created new project, followed the suggesteds that here done. I have to say that our projects that were already running , when appears this kind of spontaneous errors with google updates, this is really annoying.!!! – Liliana J May 15 '18 at 09:32
  • Hi @LilianaJ if this or any answer has solved your question please consider [accepting it](https://meta.stackexchange.com/q/5234/179419) by clicking the check-mark. This indicates to the wider community that you've found a solution and gives some reputation to both the answerer and yourself. There is no obligation to do this. – Gabriele Mariotti May 16 '18 at 07:02
2

I did the change that here sugessted to me, but the issue is happening still!!.

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

 dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
//noinspection GradleCompatible
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support:design:27.1.1'
implementation 'com.android.support.constraint:constraint-layout:1.1.0'
implementation 'com.google.firebase:firebase-messaging:15.0.2'
implementation 'com.google.firebase:firebase-invites:15.0.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'
 compile 'com.google.firebase:firebase-core:15.0.2'
// FirebaseUI for Firebase Auth

implementation 'com.google.firebase:firebase-auth:15.1.0'
//Firebase RealTime Database
implementation 'com.google.firebase:firebase-database:15.0.1'
// FirebaseUI for Cloud Storage

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

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

//circleimageView
implementation 'de.hdodenhof:circleimageview:2.1.0'

//Libreria utilizada para medir dimension de layout de chat cuando cambia de tamaño
implementation 'net.the4thdimension:android-utils:2.0.4'

//To scale every screen sizes , sp
implementation 'com.intuit.sdp:sdp-android:1.0.5'

//authenticacion para formato de numero de telefono
implementation 'com.googlecode.libphonenumber:libphonenumber:8.4.2'
implementation 'com.weiwangcn.betterspinner:library-material:1.1.0'
implementation 'com.amitshekhar.android:android-networking:1.0.0'

//Volley
implementation 'com.android.volley:volley:1.0.+'
implementation 'org.apache.commons:commons-lang3:3.6'

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

Liliana J
  • 549
  • 1
  • 5
  • 13
  • Hey did you solve this? – Arka Prava Basu Jun 05 '18 at 10:41
  • The way to solve this was to open new project, don't work with the latest version of android neither firebase, I mean sdkversion 26. – Liliana J Jun 06 '18 at 06:38
  • 5
    Hey we solved this for our case! Turns out our project had a legacy google analytics jar which had `com.google.android.gms.common.util.VisibleForTesting` and it conflicted with the one in firebase-common – Arka Prava Basu Jun 06 '18 at 06:56
1

Please change the following lines of code:

implementation 'com.google.firebase:firebase-auth:15.0.0'
implementation 'com.google.firebase:firebase-storage:15.0.0'

to

implementation 'com.google.firebase:firebase-auth:15.1.0'
implementation 'com.google.firebase:firebase-storage:15.0.2'

More informations here.

And

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

to

classpath 'com.google.gms:google-services:3.3.0'
Alex Mamo
  • 130,605
  • 17
  • 163
  • 193
0

I solved this issue by removing unused jar or comment this line if you are not usig any jar
implementation fileTree(dir: 'libs', include: ['*.jar'])

Diptendu Das
  • 3,990
  • 7
  • 22
  • 38
-1

VisibleForTesting.java is a class inside Support Annotations library which is causing the issue, If you have imported multiple versions of this mentioned library you'll face the D8 complain which you have mentioned, If your project has multi modules try to use api, implmentation instead of compile in your gradle.builds, and try to use only one version of the mentioned library, This is what worked for me!

Rez
  • 4,501
  • 1
  • 30
  • 27