18

Error:Execution failed for task ':app:preDebugBuild'.

Android dependency 'com.google.android.gms:play-services-ads' has different version for the compile (11.8.0) and runtime (11.0.4) classpath. You should manually set the same version via DependencyResolution

My project gradle:

buildscript {
    repositories {
        jcenter()
        google()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.0.1'
        classpath 'com.google.gms:google-services:3.0.0'
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        jcenter()
        google()
    }
}

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

My module gradle:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 25
    buildToolsVersion '26.0.2'
    defaultConfig {
        applicationId 'com.bezets.cityappar'
        minSdkVersion 16
        targetSdkVersion 25
        versionCode 4
        versionName '1.3.0'
        multiDexEnabled true
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    dexOptions {
        javaMaxHeapSize "2g"
    }
    packagingOptions {
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/LICENSE.txt'
        exclude 'META-INF/LICENSE-FIREBASE.txt'
    }
    productFlavors {
    }

    lintOptions {
        disable 'InvalidPackage'
        abortOnError false
    }
}

repositories {
    mavenCentral()
}

dependencies {
    implementation 'com.google.android.gms:play-services-ads:11.8.0'
    implementation 'com.google.firebase:firebase-messaging:11.8.0'
    compile fileTree(include: ['*.jar'], dir: 'libs')
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    compile 'com.android.support:appcompat-v7:25.3.1'
    compile 'com.android.support:design:25.3.1'
    compile 'com.android.support.constraint:constraint-layout:1.0.2'
    compile 'com.android.support:recyclerview-v7:25.3.1'
    compile 'com.android.support:cardview-v7:25.3.1'
    compile 'com.android.support:palette-v7:25.3.1'
    compile 'com.jakewharton:butterknife:7.0.1'
    compile files('libs/volley.jar')
    compile 'com.android.support:multidex:1.0.1'
    compile 'com.google.firebase:firebase-core:11.0.4'
    compile 'com.google.firebase:firebase-database:11.0.4'
    compile 'com.google.firebase:firebase-storage:11.0.4'
    compile 'com.google.android.gms:play-services-auth:11.0.4'
    compile 'com.google.android.gms:play-services-maps:11.0.4'
    compile 'com.google.android.gms:play-services-location:11.0.4'
    compile 'com.google.maps.android:android-maps-utils:0.4'
    compile 'com.google.firebase:firebase-auth:11.0.4'
    compile 'com.google.firebase:firebase-crash:11.0.4'
    compile 'com.google.firebase:firebase-ads:11.0.4'
    compile 'com.squareup.retrofit:retrofit:1.9.0'
    compile 'com.squareup.okhttp:okhttp:2.3.0'
    compile 'com.squareup:otto:1.3.6'
    compile 'com.github.bumptech.glide:glide:3.7.0'
    compile 'uk.co.chrisjenx:calligraphy:2.2.0'
    compile 'com.nineoldandroids:library:2.4.0'
    compile 'com.github.paolorotolo:appintro:3.3.0'
    compile 'com.facebook.android:facebook-android-sdk:[4,5)'
    testCompile 'junit:junit:4.12'
}



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

How can I fix it error?

Karim Mohammed
  • 211
  • 1
  • 2
  • 6

3 Answers3

12

My error is similar with yours, solved with these way. Error is shown below :

Android dependency 'com.google.android.gms:play-services-tasks' has different version for thecompile (11.4.2) and runtime (15.0.1) classpath. You should manually set the same version via DependencyResolution

Then in file : android/build.gradle , I add this script :

    allprojects {
       ...

       configurations.all {
           resolutionStrategy.force "com.google.android.gms:play-services- 
           tasks:15.0.1"
        }

    }
tjungChaniago
  • 196
  • 1
  • 9
1

Please see this answer You can solve it in one of two ways: Define a resolution strategy or include the offending version in your dependencies. Hope this helps!

Nelson
  • 41
  • 4
0

Set all Google/Firebase dependency to Same version 11.8.0

Nikunj
  • 3,937
  • 19
  • 33
  • Error:Execution failed for task ':app:preDebugBuild'. > Android dependency 'com.google.firebase:firebase-messaging:11.8.0' is set to compileOnly/provided which is not supported – Karim Mohammed Mar 15 '18 at 09:48
  • All com.android.support libraries must use the exact same version specification (mixing versions can lead to runtime crashes). Found versions 27.0.2, 25.3.1. Examples include com.android.support:animated-vector-drawable:27.0.2 and com.android.support:design:25.3.1 more... (Ctrl+F1) – Karim Mohammed Mar 15 '18 at 09:52
  • Add... compile 'com.android.support:animated-vector-drawable:25.3.1' – Nikunj Mar 15 '18 at 10:03
  • still have Error:Execution failed for task ':app:preDebugBuild'. > Android dependency 'com.google.firebase:firebase-messaging:11.8.0' is set to compileOnly/provided which is not supported – Karim Mohammed Mar 15 '18 at 10:11