0

Iv have an immediate conflict on an empty project once I implement gplay services.

On the latest android studio on mac, i create a simple activity app: mainactivity:

package semy.apps.myapplication;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }
}

then once i add implementation 'com.google.android.gms:play-services-ads:18.1.1' on build.gradle

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.android.gms:play-services-ads:18.1.1'

}

i get

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.

i try to add those tags on manifest to no avail, still doesnt work

inrob
  • 4,969
  • 11
  • 38
  • 51

1 Answers1

0

A quick solution to your problem could be to add the following 3 lines in your AndroidMannifest.xml

    xmlns:tools="http://schemas.android.com/tools"
    tools:replace="android:appComponentFactory"
    android:appComponentFactory="@string/app_name"

So, after adding the above 3 lines your AndroidMannifest.xml should look like,

AndroidMannifest.xml

    <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    ...
    <!--Add the following 3 lines-->
    <application
        xmlns:tools="http://schemas.android.com/tools"
        tools:replace="android:appComponentFactory"
        android:appComponentFactory="@string/app_name"

        ...

        >

        <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>

EDIT: Update your dependencies to the latest version as play-services-ads is using androidx version of support library and you are using the traditional one.

build.gradle (Module: app)

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'androidx.appcompat:appcompat:1.0.2'
    implementation 'androidx.constraintlayout:constraintlayout: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.android.gms:play-services-ads:18.2.0'
}

I hope it will fix your build error. Let me know if it works?

Roaim
  • 2,298
  • 2
  • 11
  • 23
  • thanks but i get a bunch of Duplicate class android.support.v4.app.INotificationSideChannel found in modules classes.jar (androidx.core:core:1.0.0) and classes.jar (com.android.support:support-compat:28.0.0) Duplicate class android.support.v4.app.INotificationSideChannel$Stub found in modules classes.jar (androidx.core:core:1.0.0) and classes.jar (com.android.support:support-compat:28.0.0) Duplicate class android.support.v4.app.INotificationSideChannel$Stub$Proxy found in modules classes.jar (androidx.core:core:1.0.0) and classes.jar (com.android.support:support-compat:28.0.0) – inrob Sep 06 '19 at 23:06
  • I have updated my answer. Can you try updating the dependencies to my suggested versions and see if it fixes? – Roaim Sep 06 '19 at 23:21
  • 1
    @inrob were you able to fix this issue? if so can you please let us know, what was the real reason and how did you fix it? – Roaim Sep 10 '19 at 23:29
  • Thank you I wasnt home and not available to reply but you you solver my problem – inrob Sep 12 '19 at 19:42
  • 1
    It's my pleasure :) – Roaim Sep 12 '19 at 20:51