-2

I have added

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

to project level gradle file inside buildscript/dependencies.

I have also added

  compile 'com.google.firebase:firebase-core:16.0.1'

to app level gradle file inside dependencies

I have also added the google-services.json file to app folder.

I have also added apply plugin: 'com.google.gms.google-services' to the top of app gradle file. (Tutorial says bottom, but I have also fabric's at the top, I don't think it's a problem, I have also tested at the bottom with same result)

When I try to run the project, I got this error:

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

Manifest merger failed : Attribute meta-data#android.support.VERSION@value value=(26.0.2) from [com.android.support:recyclerview-v7:26.0.2] AndroidManifest.xml:25:13-35 is also present at [com.android.support:support-v4:26.1.0] AndroidManifest.xml:28:13-35 value=(26.1.0). Suggestion: add 'tools:replace="android:value"' to element at AndroidManifest.xml:23:9-25:38 to override.

Why could this be? I have changed nothing else, just added Firebase as official sources described.

I don't want to use tools:replace in my manifest, it has led me to many bugs in the past. It feels like a half solution or a quick fix.

E D I T:

Project level gradle file:

buildscript {

    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.0.0'

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

        classpath 'com.google.gms:google-services:4.0.0'
    }
}



allprojects {
    repositories {
        google()
        jcenter()

        flatDir {
            dirs 'libs'
        }
    }
}

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

App level gradle file:

apply plugin: 'com.android.application'
apply plugin: 'io.fabric'
apply plugin: 'com.google.gms.google-services'


android {
    compileSdkVersion 26
    defaultConfig {

        minSdkVersion 19
        targetSdkVersion 26

        vectorDrawables.useSupportLibrary = true
    }


    buildTypes {
        release {
            debuggable false

            shrinkResources false
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
        debug {
            debuggable true

            shrinkResources false
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }

    // Specifies a flavor dimensions. Must have at least one.
    flavorDimensions "myFlavorDimension"

    productFlavors {

        beta {
            applicationId "hu.adamvarhegyi.myproject.beta"
            versionCode 12
            versionName '1.0.94 beta'
        }

        //Release
        standard {
            applicationId "hu.adamvarhegyi.myproject"
            versionCode 12
            versionName '1.0.94'
        }
    }





    applicationVariants.all { variant ->
        variant.outputs.all { output ->
            def project = "my_project"
            def SEP = "_"
            def buildType = variant.variantData.variantConfiguration.buildType.name
            def versionName = variant.versionName
            def versionCode = "(v_" + variant.versionCode + ")"
            def date = new Date();
            def formattedDate = date.format('yyyy-MM-dd-HH-mm')

            def newApkName = project + SEP + buildType + SEP + versionName + SEP + versionCode + SEP + formattedDate + ".apk"

            outputFileName = new File(newApkName)
        }
    }


}


buildscript {
    repositories {
        maven { url 'https://maven.fabric.io/public' }
    }

    dependencies {
        // These docs use an open ended version so that our plugin
        // can be updated quickly in response to Android tooling updates

        // We recommend changing it to the latest version from our changelog:
        // https://docs.fabric.io/android/changelog.html#fabric-gradle-plugin
        classpath 'io.fabric.tools:gradle:1.+'
    }
}



repositories {
    mavenCentral()
    maven { url 'https://maven.fabric.io/public' }
    maven { url "https://maven.google.com" }
    maven { url "https://jitpack.io" }
}




dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])

    compile('com.crashlytics.sdk.android:crashlytics:2.9.4@aar') {
        transitive = true;
    }

    compile project(':gameanalytics')
    compile 'com.google.android.gms:play-services-basement:8.4.0'
    compile 'com.google.android.gms:play-services-ads:8.4.0'

    compile('com.android.support:appcompat-v7:26.0.2')


    compile('com.android.support:recyclerview-v7:26.0.2')
    compile 'com.android.support:gridlayout-v7:26.0.2'

    compile('com.makeramen:roundedimageview:2.2.1')
    compile('de.hdodenhof:circleimageview:2.1.0')
    compile 'com.squareup.okio:okio:1.13.0'
    compile 'com.squareup.okhttp:okhttp:2.5.0'
    implementation 'com.github.javiersantos:PiracyChecker:1.2.3'

    compile 'com.google.firebase:firebase-core:16.0.1'

    compile(name: 'my_project_engine', ext: 'aar')


}
Adam Varhegyi
  • 11,307
  • 33
  • 124
  • 222
  • 1
    did you add this line at the bottom of gradle module? apply plugin: 'com.google.gms.google-services' – Tara Jul 19 '18 at 09:25
  • Can you share build.gradle for project and module level – adityakamble49 Jul 19 '18 at 09:29
  • @WaleedAsim It's on the top but it doesn't matter, I have also tried at the bottom, see my edit please, I have provided the gradle files – Adam Varhegyi Jul 19 '18 at 09:35
  • @adityakamble49 Sure I have added them with an edit – Adam Varhegyi Jul 19 '18 at 09:36
  • Possible duplicate of [Android: Getting "Manifest merger failed" error after updating to a new version of gradle](https://stackoverflow.com/questions/43280871/android-getting-manifest-merger-failed-error-after-updating-to-a-new-version) – Selvin Jul 19 '18 at 09:47

1 Answers1

0

You are using different versions for Android Support Libraries causing this conflict in Manifests of different versions of Support libraries

It can be also because any of your dependency using different version of support library as its dependency.

Manifest merger failed : Attribute meta-data#android.support.VERSION@value value=(26.0.2) from [com.android.support:recyclerview-v7:26.0.2] AndroidManifest.xml:25:13-35 is also present at [com.android.support:support-v4:26.1.0] AndroidManifest.xml:28:13-35 value=(26.1.0). Suggestion: add 'tools:replace="android:value"' to element at AndroidManifest.xml:23:9-25:38 to override.

You have to use same Android Support Library version for all the libraries

You can maintain that manually or add following script to project level build.gradle

This will force all versions of Android Support library to use same version So you won't have to maintain it manually

allprojects {

    // Force all of the primary support libraries to use the same version.
    configurations.all {
        resolutionStrategy {
            eachDependency { details ->
                if (details.requested.group == 'com.android.support') {
                    details.useVersion versions.supportLibrary
                }
            }
        }
    }
}

Edit 1

Here how you can manage it with more reliable way

dependencies.gradle

buildscript {

    ext.versions = [
            // Basic
            'supportLibrary'       : '26.1.0',
    ]

    allprojects {

        // Force all of the primary support libraries to use the same version.
        configurations.all {
            resolutionStrategy {
                eachDependency { details ->
                    if (details.requested.group == 'com.android.support') {
                        details.useVersion versions.supportLibrary
                    }
                }
            }
        }
    }
}

project level build.gradle

buildscript {
    . . .
}

apply from: 'dependencies.gradle'

module level build.gradle

dependencies {

    ...

    implementation "com.android.support:appcompat-v7:${versions.supportLibrary}"
    implementation "com.android.support:design:${versions.supportLibrary}"
    implementation "com.android.support:support-vector-drawable:${versions.supportLibrary}"

    ...
}

This is how you can easily manage all Android Support library versions

adityakamble49
  • 1,971
  • 18
  • 27
  • Are you using latest gradle plugin available for your android studio? BTW check updated Edit 1 section of post. Let me know if it works – adityakamble49 Jul 19 '18 at 10:41