0

When I generate a new 'Empty Activity' app in Android Studio I get the following dependencies in app/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'
}

If I add

implementation 'com.google.android.gms:play-services-ads:18.1.1'

I get

Dependencies using groupId com.android.support and androidx.* can not be combined but found IdeMavenCoordinates{myGroupId='com.android.support', myArtifactId='support-vector-drawable', myVersion='28.0.0', myPacking='aar', myClassifier='null'} and IdeMavenCoordinates{myGroupId='androidx.loader', myArtifactId='loader', myVersion='1.0.0', myPacking='aar', myClassifier='null'} incompatible dependencies more... (Ctrl+F1)

and

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.

What changes should I make to prevent this conflict?

Alexey Starinsky
  • 3,699
  • 3
  • 21
  • 57

2 Answers2

2

Your error is pretty self explanatory. It says:

Dependencies using groupId com.android.support and androidx.* can not be combined

that means, you're mixing up support and androidx dependencies.

To be more clear, you're using support libraries pretty much everywhere, i.e anything containing com.android.support in your app/build.gradle, but, the latest library for ads uses Androidx dependencies.

You can fix the error by converting your app dependencies to androidx, as the latest play-services-ads library uses Androidx dependencies, or, alternatively, you can use the older version of play-services-ads which used support dependencies (not recommended as support libraries are no longer maintained).

You can find how to migrate to androidx here.

Regarding your another error regarding Manifest merger failed, you can fix it by following the instructions from the answer given here.

Vedprakash Wagh
  • 3,595
  • 3
  • 12
  • 33
1

From what I suspect, the version of play services you are trying to add is updated to work with AndroidX artifacts. You have 2 solutions to your problem:

  1. Downgrade the play services library, however this is not recommended since play store usually requires the latest play service version.
  2. Upgrade your application to androidX artifacts, witch is the way to go in such cases.
Daniel
  • 2,320
  • 1
  • 14
  • 27