react-native: Android : Unable to build app

EDIT by @kelset:

TL;DR:

  • Google released a new Major version of their Google Play services and Firebase
  • this new version has BREAKING CHANGES (release notes)
  • some third-party libraries used in react-native projects have loose dependencies on said services, most likely in the :+ form in their gradle configuration
  • this is causing Gradle buils to fail because of those BC mentioned above
  • to fix, you need to set the dependency to a precise version instead of the :+
  • you can find out which libraries are “pulling in” this new version by running gradlew app:dependencies and searching the output for androidx (more details here)

Please refer to this comment (and the follow ups) for more details on how to fix - in particular, for debugging, read this comment.


React Native version: 0.58.0 Platform : android

Here are android version: buildToolsVersion = “27.0.3” minSdkVersion = 19 compileSdkVersion = 26 targetSdkVersion = 26 supportLibVersion = “26.1.0”

Building app on android before today is working fine. and suddenly got this issue in android manifest file …\android\app\build\intermediates\manifests\full\debug\AndroidManifest.xml:46: AAPT: No resource identifier found for attribute ‘appComponentFactory’ in package ‘android’

Steps To Reproduce

Describe what you expected to happen:

Snack, code example, or link to a repository:

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Reactions: 31
  • Comments: 65 (3 by maintainers)

Most upvoted comments

hey @nodece thanks for the investigation, that seems to be the root cause!

It seems that google released a new version of their Play Services, and in particular com.google.android.gms:play-services-gcm - so if you are depending on latest (via something like com.google.android.gms:play-services-gcm:+) then you need to change it to instead rely on the previous version, in the example 16.0.0.

So you may have to do something like

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

I’m going to close this, as it seems to be caused by third-party libraries and not react native per-se - if something else pops up please comment ahead!


EDIT: if you are still experiencing the issue, it’s likely one of these two reasons:

  1. you have other libraries (not device-info) that depend on latest, and you need to debug/find out which ones
  2. you need to clean the gradle cache, you can use this: ./gradlew cleanBuildCache & ./gradlew clean from the /android folder

If it’s neither because of these, please provide a repro so that it can be investigated.

update: The root cause is related to androidx, google play service… try upgrade project to androidx

This problem seems to be triggered by the version of react-native-device-info? 2.1.2 constrain play services dependency to pre-AndroidX 16.1.0 react-native-device-info

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

It working for me.

How to solve this without migrating to AndroidX?

update: The root cause is related to androidx, google play service… try upgrade project to androidx

This problem seems to be triggered by the version of react-native-device-info? 2.1.2 constrain play services dependency to pre-AndroidX 16.1.0 react-native-device-info

yarn upgrade react-native-device-info@2.1.2 cd android && gradlew clean react-native run-android It working for me.https://github.com/facebook/react-native/issues/25293#issuecomment-503008149 !

Thanks https://github.com/MR03web that solved my problem!

Without the need to migrate to AndroidX!

react-native-device-info@0.13.0 use com.google.android.gms:play-services-gcm:+ library triggered my problem.

Update app/build.gradle:

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

ENV

React Native version: 0.57.5
Platform : android
buildToolsVersion = "27.0.3"
minSdkVersion = 16
compileSdkVersion = 27
targetSdkVersion = 26
supportLibVersion = "27.1.1"

As the current maintainer of react-native-device-info we did have a loose (‘+’) dependency in our build.gradle, but it also checked if you specified a version in android/build.gradle first. You should ALWAYS specify your versions like that in android/build.gradle so that you are not subject to 3rd party module defaults (which may either be loose (‘+’) or just some incompatible version.

Hope everyone gets their gradle files sorted out and has successful builds today

Nothing seems to work to me. Tried all above and none worked.

This works for me.

Upgrade your project to androidx https://developer.android.com/jetpack/androidx/migrate

And you need to update your dependencies to androidx as well.

Here’s a gist to update all dependencies automatically to androidx https://gist.github.com/janicduplessis/df9b5e3c2b2e23bbae713255bdb99f3c

I guess the problem is google play service and firebase just released https://developers.google.com/android/guides/releases

@kelset I follow the same steps but no success. I still getting same error.

@Otik133040040 Use the previous versions as suggested…I did the following changes:

implementation(project(":react-native-device-info"),  {
    exclude group: "com.google.android.gms"
})
implementation(project(":react-native-push-notification"),  {
    exclude group: "com.google.android.gms"
    exclude group: "com.google.firebase"
})
implementation "com.google.firebase:firebase-messaging:17.0.0"
implementation "com.google.android.gms:play-services-gcm:16.0.0"

Same problem introduced by latest firebase (see https://firebase.google.com/support/release-notes/android#update_-_june_17_2019)

I ended up using previous version as a workaround

implementation "com.google.android.gms:play-services-gcm:16.0.0"
implementation "com.google.firebase:firebase-messaging:17.0.0"

react-native-push-notifications library allows to set these versions in gradle.properties as

googlePlayServicesVersion=16.0.0
firebaseVersion=17.0.0

In other cases you may need exclude from above

com.android.build.api.transform.TransformException: Error while generating the main dex list: Error while merging dex archives: Learn how to resolve the issue at https://developer.android.com/studio/build/dependencies#duplicate_classes. Program type already present: android.support.v4.app.INotificationSideChannel$Stub$Proxy

i am getting same issue

update: The root cause is related to androidx, google play service… try upgrade project to androidx

This problem seems to be triggered by the version of react-native-device-info? 2.1.2 constrain play services dependency to pre-AndroidX 16.1.0 react-native-device-info

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

It working for me.

It working for me after upgrade react-native-device-info to 2.1.2