36

I updated 'android.support:appcompat-v7' to 28.0.0.

But it brought an error from the build.

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:8:5-23:19 to override.

Then I get this error in my Logcat:

Manifest merger failed

my app.gradle:

  configurations.all {
    resolutionStrategy.force 'com.android.support:design:28.0.0'
    resolutionStrategy.force "com.android.support:support-v4:28.0.0"
    resolutionStrategy.force "com.android.support:support-media-compat:28.0.0"
  }
...
dependencies {
  implementation 'com.android.support:multidex:1.0.1'

  // Our dependencies
  implementation 'com.android.support:appcompat-v7:28.0.0'


  implementation 'com.android.support:appcompat-v7:28.0.0'
}

how do I fix it?

I need your solutions.

Thank you in advance.

hong developer
  • 13,291
  • 4
  • 38
  • 68

13 Answers13

48

Upgrading 'react-native-device-info' to version 2.1.2 fixed the error for me. See github.com/facebook/react-native/issues/25294#issuecomment-503024749

In short: the library used "services-gcm:+" as a dependency, and the latest gcm version caused this problem.

Vipul Prajapati
  • 1,183
  • 9
  • 11
Frank
  • 12,010
  • 8
  • 61
  • 78
13

The root cause is related migration to Androidx, google play service updated to androidX Thanks to MR03web This problem belongs to react-native-device-info? best option is to upgrade react-native-device-info using

yarn upgrade react-native-device-info@2.1.2
cd android && gradlew clean
react-native run-android

or if you don't want to upgrade you should exclude com.google.android.gms from react-native-device-info like this. Thanks

implementation(project(":react-native-device-info"),  {
  exclude group: "com.google.android.gms"
})
implementation "com.google.android.gms:play-services-gcm:16.0.0"
Hussain Sherwani
  • 536
  • 5
  • 22
7

Add the following to your gradle.properties then clean/rebuild

googlePlayServicesVersion=16.1.0
firebaseVersion=17.6.0
Yinka
  • 1,741
  • 4
  • 15
  • 23
6

I found a solution through my search by referring to @MehulSolanki answer.

I add

tools:replace="android:appComponentFactory"
android:appComponentFactory="whateverString"

in my on AndroidManifest.xml

and update com.android.tools.build:gradl:

dependencies {
    classpath 'com.android.tools.build:gradle:3.2.1'
  }

And add this in your gradle.properties file

android.useAndroidX=true
android.enableJetifier=true

ERROR: [TAG] Failed to resolve variable '${animal.sniffer.version}'

ERROR: [TAG] Failed to resolve variable '${junit.version}'

In case of above error

  1. File -> Invalidate Caches / restart
  2. Build -> Clean project

error: package android.support.annotation does not exist error: cannot find symbol class Nullable

In case of above error

Add implementation 'androidx.annotation:annotation:1.1.0'

change import android.support.annotation.Nullable; => androidx.annotation.Nullable;

change import android.support.annotation.NonNull; => androidx.annotation.NonNull;

Compile version and target version should be 28.

hong developer
  • 13,291
  • 4
  • 38
  • 68
  • @HussainSherwani Could you update `classpath 'com.android.tools.build:gradle:3.2.1'` ? – hong developer Jun 18 '19 at 06:35
  • classpath is already updated which is `classpath 'com.android.tools.build:gradle:3.3.1'` – Hussain Sherwani Jun 18 '19 at 06:42
  • @HussainSherwani Add this in your gradle.properties file `android.useAndroidX=true android.enableJetifier=true` – hong developer Jun 18 '19 at 06:44
  • thanks mate for helping but this will not work as due to these line those `libraries` not using `androidx package` will not compile like after adding these lines I am getting issue in `@react-native-community_netinfo` library which is using android package instead of `androidx` – Hussain Sherwani Jun 18 '19 at 06:51
  • @HussainSherwani Did you add a library of real-native-commonity_netinfo? – hong developer Jun 18 '19 at 07:03
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/195105/discussion-between-hussain-sherwani-and-hong-develop). – Hussain Sherwani Jun 18 '19 at 07:05
  • @hongdevelop I have tried your solution. but there is a package android.support.annotation does not exist error: cannot find symbol class Nullable error from the react-native-fast-image library. and I'm not able to edit import in that library file. can you please suggest me how can I do that? – Patel Dhara Jun 18 '19 at 12:30
  • I have same issue. Did you resolve it @PatelDhara – Sinh Phan Dec 26 '20 at 16:30
5

Add 'tools:replace="android:appComponentFactory"' in your AndroidManifest.xml inside <application> tag

Your AndroidManifest.xml

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

    <application
        tools:replace="android:appComponentFactory"
        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">
   </application>

Can Poyrazoğlu
  • 33,241
  • 48
  • 191
  • 389
Mehul Solanki
  • 1,147
  • 11
  • 15
4

Downgrade Google Play service version. In android/app/build.gradle change

compile 'com.google.android.gms:play-services-<service_name>:+'

to

compile 'com.google.android.gms:play-services-<service_name>:16.0.0'

So in my case < sevice_name > was location. But in someone's else case it may be any other Google Play Service (like in list here http://www.androiddocs.com/google/play-services/setup.html).

3

After spending a whole day on this issue. Finally, I have resolved this issue.

I got that error from react-native-device-info and react-native-fast-image library. I just remove that library from package.json file and then install

"react-native-device-info": "^2.1.2", "react-native-fast-image": "^6.0.3" this latest version

I have used below gradle version

classpath 'com.android.tools.build:gradle:3.3.1'

I have used below properties version

distributionUrl=https\://services.gradle.org/distributions/gradle-5.1.1-all.zip

I have used below versions

buildToolsVersion = "28.0.3"
minSdkVersion = 16
compileSdkVersion = 28
targetSdkVersion = 28
supportLibVersion = "28.0.0"
Patel Dhara
  • 858
  • 7
  • 16
2

According to @Frank's answer the library used services-gcm:+ as a dependency, and the latest gcm version caused this problem.

And I had used :react-native-admob in my project. So I just change the following lines in android/app/build.gradle

From:

implementation project(':react-native-admob')

TO :

implementation(project(":react-native-admob"),  {
        exclude group: "com.google.android.gms"
})
implementation "com.google.android.gms:play-services-ads:16.0.0"
shah
  • 1,163
  • 2
  • 19
  • 40
2

This answer should help most people. If it still does not then the way to solve this (which is not that good) is that you open the android project in android studio. That should fetch all the gradle files. On the right side the view should be android.

enter image description here

From here just check each gradle build file for a + sign ahead of google play services or firebase services or any such library. This has also been explained in this answer.

After which you either change it like explained in the answer above. like so.

implementation(project(":react-native-admob"),  {
        exclude group: "com.google.android.gms"
})
implementation "com.google.android.gms:play-services-ads:16.0.0"

Or you provide a variable if the library is using one or as a last resort change it there itself.

The reason I put it here is so that any newbie who is sick of this error which randomly appeared out of nowhere all of a sudden can solve it effectively and not...die. lol.

hispeed
  • 171
  • 1
  • 8
2

I had the same problem, just upgrade react-native-device-info and run the following command

npm upgrade react-native-device-info@latest
react-native run-android
Imran
  • 305
  • 3
  • 13
1

Upgrading react-native-device-info to version 2.1.2 Fix my problem

Felipe Augusto
  • 7,733
  • 10
  • 39
  • 73
1

If you are not using react-native-device-info, but have the same error, its probably another library in your project.

Use this to find the library in question:

cd your-react-native-project/android
./gradlew app:dependencies > deps.txt

Then inspect the deps.txt file for keyword "androidx". Then you can quickly find which native module is using it.

In my case it was react-native-camera, for which solution above was good but not enough so I had to add this to local.properties:

firebaseVersion=17.6.0
googlePlayServicesVersion=16.1.0
googlePlayServicesVisionVersion=16.2.0

EDIT: After these fixes, running ./gradlew app:dependencies > deps.txt and searching for "androidx" returned no results - this is what we are looking for.

After running clean on the project, build worked.

Milan Markovic
  • 1,250
  • 13
  • 18
1

Google play services breaking changes. See Release Notes.

The simple way to resolve this issue is just changing the version of Google play services.

Change all com.google.android.gms:play-services-* dependencies to version 16

NYSamnang
  • 346
  • 2
  • 8