0

I'm new to android studio and I'm trying to learn firebase and implement a google sign in to my dummy app.

I went ahead and followed google's documentation for including certain lines in the build.gradle files

in project/gradle I added classpath 'com.google.gms:google-services:4.3.3'

and in app/gradle I checked for apply plugin: 'com.android.application' and apply plugin: 'com.google.gms.google-services'

since it was already there, I added: implementation 'com.google.firebase:firebase-analytics:17.2.2'

I synced my project and when I tried to run the app I get the following error:

Manifest merger failed : Attribute application@appComponentFactory value=(android.support.v4.app.CoreComponentFactory) from [com.android.support:support-compat:28.0.0] AndroidManifest.xml:22:18-91
    is also present at [androidx.core:core:1.0.0] AndroidManifest.xml:22:18-86 value=(androidx.core.app.CoreComponentFactory).
    Suggestion: add 'tools:replace="android:appComponentFactory"' to <application> element at AndroidManifest.xml:5:5-19:19 to override.

Please tell me what I'm doing wrong? I'm using android studio on Windows 10

EDIT: here's my manifest xml file as suggested by the user

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.MyName.TestApp">

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

My app gradle file

apply plugin: 'com.android.application'

android {
    compileSdkVersion 28
    defaultConfig {
        applicationId "com.MyName.TestApp"
        minSdkVersion 23
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:28.0.0'
    implementation 'com.android.support.constraint:constraint-layout:1.1.3'
    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-analytics:17.2.3'
}

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

package gradle file

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    repositories {
        google()
        jcenter()

    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.3.1'
        classpath 'com.google.gms:google-services:4.3.3'


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

allprojects {
    repositories {
        google()
        jcenter()

    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}
Shashank Setty
  • 138
  • 1
  • 9
  • Your issue is in your AndroidManifest.xml, the error says to add `tools:replace="android:appComponentFactory"` in your Manifest's application tag, this happens because of duplicacy try adding your Manifest also so that someone can assist even better – Rakshit Nawani Mar 17 '20 at 06:52
  • https://stackoverflow.com/questions/55217992/manifest-merger-failed-attribute-applicationappcomponentfactory-androidx check this one – Avinash Ajay Pandey Mar 17 '20 at 06:54

1 Answers1

2

If you want to use Analytics version 17.2.2 then you need to upgrade androidx. From the docs:

The updated libraries will not work unless you make the following changes in your app:

  1. Upgrade com.android.tools.build:gradle to v3.2.1 or later.
  2. Upgrade compileSdkVersion to 28 or later.
  3. Update your app to use Jetpack (AndroidX); follow the instructions in Migrating to AndroidX.

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

Peter Haddad
  • 78,874
  • 25
  • 140
  • 134