react-native: [FIXED] Android build failures `No matching variant of com.facebook.react:react-native:0.71.0-rc.0 was found.`
Description
Hey all, I’d like to share an update on a series of build failures React Native & Expo users have been experiencing when building Android apps starting from November 4th 2022.
We’d like to apologize for the disruption this caused to your developer workflows. The React team is fully committed to delivering a smooth developer experience, and we take this type of issues extremely seriously.
📢 Patches for >= 0.63
We have prepared releases for all the main versions of react-native with an hotfix:
🛳 0.70.5: https://github.com/facebook/react-native/releases/tag/v0.70.5 🛳️ 0.69.7: https://github.com/facebook/react-native/releases/tag/v0.69.7 🛳 0.68.5: https://github.com/facebook/react-native/releases/tag/v0.68.5 🛳️ 0.67.5: https://github.com/facebook/react-native/releases/tag/v0.67.5 🛳️ 0.66.5: https://github.com/facebook/react-native/releases/tag/v0.66.5 🛳️ 0.65.3: https://github.com/facebook/react-native/releases/tag/v0.65.3 🛳️ 0.64.4: https://github.com/facebook/react-native/releases/tag/v0.64.4 🛳️ 0.63.5: https://github.com/facebook/react-native/releases/tag/v0.63.5
By updating to these patch versions, your Android build should start working again.
To do so, in your package.json
change react-native
’s version to the relevant new patch (ex. if you are on 0.64.3, change to 0.64.4) and run yarn install
. No other changes should be necessary, but you might want to clean your android artifacts with a cd android && ./gradlew clean
before trying to re-run your Android app.
Fix for older react-native (< 0.63)
The fix above only works on gradle 6.2 and higher. Older react-native used older gradle.
You may determine your gradle version by looking in your /android/gradle/wrapper/gradle-wrapper.properties
file.
If you are on an older version of react-native (for example 0.63 or earlier) that uses gradle version 6.1 or below, you must use a different workaround as gradle 6.1 does not support exclusiveContent
.
Add this in the allprojects
area of your android/buld.gradle
file.
def REACT_NATIVE_VERSION = new File(['node', '--print',"JSON.parse(require('fs').readFileSync(require.resolve('react-native/package.json'), 'utf-8')).version"].execute(null, rootDir).text.trim())
allprojects {
configurations.all {
resolutionStrategy {
// Remove this override in 0.65+, as a proper fix is included in react-native itself.
force "com.facebook.react:react-native:" + REACT_NATIVE_VERSION
}
}
Instead of using exclusiveContent
, the hotfix must force the version of React Native. The recommended hotfix shells out to node
to read your current version of react-native. If you hard code the version of react-native, when you upgrade your project in the future, your build will fail if you forget to remove this hotfix.
Note that this fix is fragile as the location of your package.json could be different if you are in a monorepo, and node might not be available if you use a node package manager like nvm.
Thank you @mikehardy for finding and providing this fix in your comment.
Technical Details
The issue
On November 4th 2022 we published the React Native version 0.71.0-rc0
, the first release candidate for the 71
release series, on several public repositories. Specifically, this version was also published on Maven Central as we’re updating our artifacts distribution strategy (technical details are explained below).
This event resulted in build failures for Android on several users as they ended up downloading the wrong React Native version (0.71.0-rc0
instead of the version they were using in their project, say 0.68.0
).
The build error looks something like this:
Error: Command failed: gradlew.bat app:installDebug -PreactNativeDevServerPort=8081
FAILURE: Build failed with an exception.
* What went wrong:
A problem occurred configuring root project 'My Project'.
Could not determine the dependencies of null.
Could not resolve all task dependencies for configuration ':classpath'.
> Could not resolve com.facebook.react:react-native:+.
Required by:
project :
> No matching variant of com.facebook.react:react-native:0.71.0-rc.0 was found.
The consumer was configured to find a runtime of a library compatible with Java 11,
packaged as a jar, and its dependencies declared externally, as well
as attribute 'org.gradle.plugin.api-version' with value '7.3.3' but:
Sadly, due to how older projects of React Native were created in the past, we couldn’t simply re-publish older versions, and we’re asking users to update their template using the fix suggested below.
Why this happened
Historically, the React Native template provided build.gradle
files that contain a dependency on the React Native Android library as follows: implementation("com.facebook.react:react-native:+")
.
Specifically, the +
part of this dependency declaration is causing Gradle to pick the highest version among all the declared repositories (often referred as Gradle Dynamic versions). Till React Native version 0.70
, we were shipping a Maven Repository inside the NPM package (inside the ./android
folder). Starting from 0.71
, we moved such folder and uploaded it to Maven Central.
Using Gradle Dynamic versions (i.e. a +
dependency) is considered an antipattern (see the various warnings and notes on this page), specifically as it can lead to scenarios like this one and generally exposes users to less-reproducible builds. This is exactly what happened in this scenario, as builds started failing without any changes to user projects.
In 0.71
we cleaned up the new app template and removed all the +
dependencies (see here) and we moved the template to use the React Native Gradle Plugin, which will allow us to prevent scenarios like this from happening in the future.
Sadly, users on older versions, say 0.66.0
, were still using a +
version. This caused their build to query all the repositories for the highest available versions of the React Native. While the node_modules/react-native/android
folder contained a valid 0.66.0
version, Gradle honoured the +
version and fetched version 0.71.0-rc0
from Maven Central as it’s higher from the semantic versioning ordering.
The resolutionStrategy
block in the fix is forcing the version of com.facebook.react:react-native
to all the projects to the one provided by the version of React Native you’re effectively using.
Who is affected?
All the React Native users on versions till 0.66.x
are affected.
React Native users on versions from 0.67
till 0.70
could be affected, based on which third-party library they’re using.
We verified that empty projects created on versions from 0.67
till 0.70
are not affected.
However, some of your dependencies might end up causing a wrong resolution of the React Native Android library, resulting in build failures.
For instance, we verified that a project on React Native 0.68.4
works well with Reanimated 2.12.0
but fails with Reanimated 2.10.0
.
We also worked with Expo to make sure that users on eas build
received the aforementioned fix, so those users should not be affected.
Why React Native Android was published on Maven Central?
As mentioned, this was done as part of the implementation of the RFC #580.
The summary of that RFC is to allow us to overcome the limitation of NPM in terms of package size. Moving to Maven Central will allow us to reduce the build time for our users and distribute more granular artifacts which will end up benefitting the overall developer experience. We’ll be able to share information on this in the near future.
In the initial Github Issue, several users suggest to remove the publishing from Maven Central or re-publish older artifacts to overcome the build failure without requesting a fix.
This is sadly not an option as:
- Maven Central is an immutable artifacts storage and doesn’t allow deletion.
- The publishing on
0.71.0-rc0
was effectively correct. We believe this episode is essentially a “mis-configuration” in user projects, and we believe the better solution is to distribute this fix to our users.
How could this have been prevented
We were already aware of the risk of having Gradle dynamic dependencies, so since React Native 0.67
we introduced an exclude
rule on the Maven Central dependency inside the default template (see here for more context):
mavenCentral {
content {
excludeGroup("com.facebook.react")
}
}
React Native used to be published on Maven Central till version 0.20.1
(published in 2016). We had users in the past accidentally fetching older versions of React from Maven Central, causing their build to fail.
This exclude
directive assured that you won’t ever download React Native from Maven Central. However, third party libraries could declare repositories inside their repositories{}
block which might not contain the exclude
directive, resulting in potentially broken dependency resolution.
React Native version 0.71.0
will ship with an updated template that relies on React Native Gradle Plugin. This new integration will allow us to protect us against future distributed build failures like this one, by allowing to re-distribute updated build logic across the whole ecosystem if needed (this should protect us also against similar outages like the JCenter outage happened last year).
I’d like to thank everyone for your patience and understanding and I’d like to call out some members our our community, specifically @mikehardy, @Titozzz, @brentvatne, @inckie and all the other folks involved in the initial investigation and fix for this issue.
We’ll follow up with more updates in the future if needed.
Nicola On behalf of the React team
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Reactions: 913
- Comments: 220 (12 by maintainers)
Links to this issue
- gradle - Android app won't build -- The minCompileSdk (31) specified in a dependency's androidx.work:work-runtime:2.7.0-beta01 - Stack Overflow
- PSA: If you're getting weird linking issues, double check that you weren't affected by a faulty deployment of the react-native library that broke old versions (even if you haven't changed the version in package.json)
- I'm trying to fix an error because I'm not able to build my app
- react-native-0.71.0-rc.0-debug.aar issue
- Issue with failing react native Android build
- Convert a large app from React Native to Flutter
Commits related to this issue
- Add RN fix for build errors. https://github.com/facebook/react-native/issues/35210 — committed to microdotblog/microblog-react by vincentritter 2 years ago
- fix: Workaround for Build Failures https://github.com/facebook/react-native/issues/35210 — committed to LNReader/lnreader by rajarsheechatterjee 2 years ago
- build: add hotfix for RN maven repo https://github.com/facebook/react-native/issues/35210 — committed to 6d7a/quito by deleted user 2 years ago
- Fix RN update caused Android build error Spent whole fucking 2 days to figure this out https://github.com/facebook/react-native/issues/35210 — committed to tooot-app/app by xmflsct 2 years ago
- Fix Android build failures https://github.com/facebook/react-native/issues/35210 — committed to stxapps/justnote-client by 0xc22b 2 years ago
- Fix Android build failures https://github.com/facebook/react-native/issues/35210 — committed to stxapps/brace-client by 0xc22b 2 years ago
- [ISSUE] React Native Patch from 4th November 2022 https://github.com/facebook/react-native/issues/35210 — committed to StudyBox-EIP/front-mobile by Nathan-Moignard 2 years ago
- fix android build.gradle according to issue(https://github.com/facebook/react-native/issues/35210) — committed to ssivenkov/GeoTrack by ssivenkov 2 years ago
- Fix Android build (https://github.com/facebook/react-native/issues/35210) — committed to BrightID/BrightID by TripleSpeeder 2 years ago
- Fix Android build (https://github.com/facebook/react-native/issues/35210) — committed to BrightID/BrightID by TripleSpeeder 2 years ago
- :bug: Fix react-native upstream 0.71.0-rc.0 issue - https://github.com/facebook/react-native/issues/35210 — committed to wouterds/react-native-tv-example by wouterds 2 years ago
- :bug: Fix react-native upstream 0.71.0-rc.0 issue - https://github.com/facebook/react-native/issues/35210 — committed to wouterds/react-native-tv-example by wouterds 2 years ago
- :bug: Fix react-native upstream 0.71.0-rc.0 issue - https://github.com/facebook/react-native/issues/35210 — committed to wouterds/react-native-tv-example by wouterds 2 years ago
- feat: 🎸 react-native@0.70.5 https://github.com/facebook/react-native/issues/35210 — committed to 24jieqi/react-native-lidong-template by onlyling 2 years ago
- update RN for Android build https://github.com/facebook/react-native/issues/35210 * v0.63.4 -> v0.63.5 * v0.67.2 -> v0.67.5 — committed to nayuta-ueno/rn-ldk by nayuta-ueno 2 years ago
- test: fix android build error by upgrading react-native to v0.69.7 ref: https://github.com/facebook/react-native/issues/35210 — committed to gmsgowtham/react-native-marked by gmsgowtham 2 years ago
- build(react): bump React Native to 0.66.5 (#30) ## Summary Fix to honor the 0.66.x Android Gradle dependency now that React Native has deferred Maven repo to remote instead of local. ## Referenc... — committed to csantarin/android-startup-perf-app by csantarin 2 years ago
- Implement temporary fix for React Native build failure starting 11/04/22 - https://github.com/facebook/react-native/issues/35210#issue-1436785719 has the details. — committed to steve1316/genshin-inventory-scanner-android by steve1316 2 years ago
- - Fixed build issue start happening on 4th Nov, 2022 ( https://github.com/facebook/react-native/issues/35210) - `startPosition` bug fix. Give this value if FE passes it. - Fixed bridge issue for `setL... — committed to kaltura/kaltura-player-rn by GouravSna 2 years ago
@JodiRaina that likely indicates your gradle plugin or gradle is too old to use this advice - it appears gradle 6.1 and older does not have the exclusiveContent / include filter in the preferred solution.
If you cannot upgrade gradle (and react-native…), you might try one of the fallback workarounds for old react-native using very old gradle plugin / gradle, specifically this one, which was the best-known solution if exclusiveContent is not available / until the exclusiveContent idea occurred
https://github.com/facebook/react-native/issues/35204#issuecomment-1304281740
@brentvatne @ Expo proposes this as a refinement to avoid the hard coded version, it is the same as the previous best-known solution but now with dynamic version powers, otherwise same idea - you put this in the allprojects area of your
android/buld.gradle
fileNote that the exclusiveContent idea is a cleaner solution, but of course only if your gradle supports it
Hey everyone 👋 ! We know the fix works in almost all cases. We have one failure case where your gradle is 6.1 or lower, with a separate workaround as described above.
There is no need to report success here as it will just clutter up the thread and hide real problems, if any.
If you have a case that does not work, then it is worth commenting and pursuing.
Thanks!
try this bro : build.gradle
then remove node modules, npm install, run gradlew clean in android directory, and run apps
We yesterday faced with this issue too
fixed easy:
in android/app/build.gradle
replace
implementation “com.facebook.react:react-native:+”
to
implementation (“com.facebook.react:react-native”) version { strictly “0.69.3” }
NB: Use exact RN version from you project’s package.json instead of “0.69.3” This fix force Gradle to use exact version of RN instead of 0.70.x for the all modules in project
Hello All,
React Native Version : 0.63.0
Firstly I got
.gradle/caches/transforms-2/files-2.1/fbb7a340b18cb1ab123bd8116e2b4a16/core-1.7.0/res/values/values.xml:105:5-114:25: AAPT: error: resource android:attr/lStar not found.
I tried the below solution as recommended by @anhkieet
Add this in the allprojects area of your android/buld.gradle file.
def REACT_NATIVE_VERSION = new File([‘node’, ‘–print’,“JSON.parse(require(‘fs’).readFileSync(require.resolve(‘react-native/package.json’), ‘utf-8’)).version”].execute(null, rootDir).text.trim())
allprojects { configurations.all { resolutionStrategy { // Remove this override in 0.65+, as a proper fix is included in react-native itself. force “com.facebook.react:react-native:” + REACT_NATIVE_VERSION } }
Then got the below issue : Cause: react_dbl48axvbt6e0k1c9t3iq8qv8$_run_closure4$_closure6$_closure10$_closure18
Then deleted global .gradle file from system and restarted android studio through invalidate cache and restart and it worked finally.
Thank you @anhkieet
ANYONE WITH VERSION 0.63.0 CAN TRY THE ABOVE SOLUTION 😃
This solution worked for me Added this project build.gradle, in allProjects at the end
Thank you for making me waste 2 fucking days
see Fix for older react-native (< 0.63) section
try to write this. kotlinVersion = “1.6.0”
Hope this Method 1 will help in android build issue: https://stackoverflow.com/a/74334163/6786766
It’s working for me
Replace this in
android/build.gradle
fileAfter using the fix,The error dissapeared but when I build a release App, the build’s succesful but it keeps crashing as soon as it is getting installed. Is there a solution for that please ?
Thank you for sharing the update, it helped me to resolve the latest building errors😀
hope this help
Solution Reference
Anyone still having issues with DSO not being loaded (if using hermes), try this:
Change:
to:
for example, for mine I used:
Hi, I am facing an issue, while generating a build. .
gradle/caches/transforms-2/files-2.1/e4fbec57f89d7c92a4c08621897ece3f/core-1.7.0/res/values/values.xml:105:5-114:25: AAPT: error: resource android:attr/lStar not found.
@kildip
I had same problem - try to bump this lib version
I fixed it! with added this on (android/build.gradle) -
** exclusiveContent { filter { includeGroup “com.facebook.react” } forRepository { maven { url “$rootDir/…/node_modules/react-native/android” } } }** this code under allProject{ repositories { …here…}}
and updated gradle version on (android/gradle/wrapper/gradle-wrapper.properties) distributionUrl=https://services.gradle.org/distributions/gradle-7.5.1-all.zip
Hey, I’m having some issues when upgrading from react-native v0.64.1 -> v0.64.4. This is the error message I am getting when trying to create a build or running ./gradlew clean in the android directory. Gradle version 7.0.2. Any help is appreciated.
@tukaAlalami
Has anyone here who are having this build failed issue tried to build signed bundle/apk for android? Because the solutions here react-native/issues/35210 and (expo/expo@02fb0a9), it makes the build for android successful on emulator and on real device. But my signed bundle/apk is crashing as soon as it’s downloaded and opened. I’m on RN 0.66 and I’ve tried gradle 6.9.0, 7.0.1 and 7.2.1 and my signed bundle is still crashing with no error messages shown.
@Aleksefo thanks for pointing it out, it’s not intended. It’s probably a side effect of the pipeline generating the diff - the only change you should have to handle is the bump of the version. I’ll look into manually patching the rn-diff-purge repo that feeds the data to upgrade-helper to remove that unwanted change.
After upgrade react-native from 0.63.2 to 0.63.5, things are OK in Android but can not run in IOS.
Error:
Terminating app due to uncaught exception ‘NSInternalInconsistencyException’, reason: ‘Could not load NIB in bundle: ‘NSBundle </Users/lavinhquang/Library/Developer/CoreSimulator/Devices/A94B947B-CCB8-4075-A854-DE1F05B8E3DC/data/Containers/Bundle/Application/BA8FA348-126C-4E93-A0B5-847595703053/D4UPatient.app> (loaded)’ with name ‘LaunchScreen’’
I find a way to solve this build problem and no need to update to the hotfix RN version. I test the RN 0.64.2 is ok
just add these lines into the android/build.gradle file. note don`t delete other content for allproject in build.gradle
`allprojects {
}`
updated from 0.66.2 to 0.66.5, still facing the same issue
Duplicate class com.facebook.hermes.BuildConfig found in modules jetified-hermes-debug-runtime (hermes-debug.aar) and jetified-hermes-release-runtime (hermes-release.aar)
Made it work without upgrading react-native version and by adding this in build.gradle, this works (hermes enabled or not, along with flipper too)
final snippet looks like this
gradle clean and rebuild after this fix.
For a project using react 17.0.2 and react-native 0.66 this fixed the build but our app kept crashing upon launch. Upgrading our gradle version from 7.4.1 to 7.5 in gradle-wrapper.properties fixed the issue.
After applying the patch the build succeeds but the app crashes on startup.
Here are some logs:
Does it happen to anyone else? I’m on 0.69.5.
My react-native version is 0.66.2 , same problem. I change package.json. “react-native”: “0.66.2”, to “react-native”: “0.66.5”, solve this problem.
Please follow this link Hope it will work.
Jesus, 24 active working hours troubleshooting this. THANK GOD I FOUND THIS POST. THIS IS SOLVED NOW!!!
For old react-native versions on gradle 6.1 and below you need a different workaround:
@yuvital-render please take a look at https://github.com/facebook/react-native/issues/35210#issuecomment-1304536693
Thanks @cortinico everything is working fine. So once our projects updated to RN 0.71+ we must remove this workaround, right?
Thanks Alot RN team Finally my project is working i use this code
Prior to 4 November it was working fine and now when I am trying to build it by running yarn android but it is showing me. I tried the patch also 0.66.3 => 0.66.5 I cleaned the gradle Removed the node_modules
But I am getting this error everytime
I have tried solution from My React Native was working fine upto 4 November but now throwing an exception while Running yarn android but no luck. Any help will be appreciated.
I have “react-native”: “^0.66.3”, “react-native-webrtc”: “^1.94.1”
I tried below solution as well
Facing the same issue. updating from
0.64.2
to0.64.4
and running./gradlew clean
yields this errorgradlew version = 7.0.2
This did not work for me (got other errors instead) with “react-native”: “0.66.4”, But what worked was this
After upgrading from 0.68.0 to 0.68.5 I am now getting similar transform errors for react-native firbase dependencies when using react-native run-android. build sucessful gradle 7.3.3
Example here: `Execution failed for task ‘:app:mergeDebugAssets’.
buildscript { ext { buildToolsVersion = “31.0.0” minSdkVersion = 21 compileSdkVersion = 31 targetSdkVersion = 31 ndkVersion = “21.4.7075529” useMapLibre = true useCustomMapbox = false
/// repositories { google() mavenCentral() jcenter()
}
allprojects {
App is getting crashed as soon as it is getting installed
This is probably obvious, but after implementing the patch and running
./gradlew clean
, I needed to delete my node_modules folder and runnpm install
again - that got it working for me.I’m running Expo Bare and prior to removing the node_modules folder, I was getting errors in the expo packages that seemed like they were looking for the previous RN version I was on (68.2) before upgrading to the patch (68.5).
getting error after updating patch from 0.66.4 to 0.66.5. Now whenever I make a build, I get error in different libraries/ modules like
Error: Unable to resolve module ./arrayWithHoles.js from D:\stylon\node_modules\@babel\runtime\helpers\slicedToArray.js:
error: Error: While trying to resolve module
react-isfrom file
D:\stylon\node_modules\prop-types\index.js` sometime in 3rd party libs, stating they don’t exist while they do@BhanaviShukla I faced same issue after version increasing and resolved by ./gradlew clean
which version of React-native-svg you are using trying to upgrade to latest version
i have the same error Execution failed for task ‘:react-native-navigation:compileReactNative63DebugKotlin’. after i upgrade from react native .0.67.2 to 0.67.5 any help ?
finally, it worked for me!
I have a question when I updated react native version from 0.66.4 to 0.66.5 in development env and AOS build success, Is it okay use code push to 0.66.4 version production ? I’m afraid it’s going to conflict.
@jforaker I agree with @pascale-m and would personally suggest using NPM.
I have upgraded my RN version to
0.68.5
, but keep getting the following issue:is there a specific need to use yarn? or would npm be equivalent?
Applying the allProjects force solution worked for us, preventing the need to merge the hotfix and release our react-native fork. it’s a combination of some of the solutions above as we also ran into the Hermes issue on release builds. Thanks to @Nesh108 and others 🙇
@davidjonesdialexa Nope, thats directly in the react.gradle file - includes in the new patch version (0.63.5) which is recommended to update from 0.63.4 if I understood it corectly 😃 But after install this React version cannot be found 😦(
@baierjak did you accidentally type a “+” in your package.json?
I just want to point out some people might be getting this error instead of the one you guys have reported in the instructions. Manifest merger failed : uses-sdk:minSdkVersion 19 cannot be smaller than version 21 declared in library [com.facebook.react:react-native:0.71.0-rc.0]
This too will be fixed by upgrading to your respective react-native patch.
Worked for 0.66.4 -> 0.66.5
In your package.json change react-native version to 0.64.4 and run yarn install
@ivanhoe-dev Hey. I saw your comment and I had similar error while building android this whole day. As you mentioned to follow the instruction for the hotfix, I have downloaded the zip (version 0.66.5) which included bunch of files. I have no idea how to fix my project with the official zip. Could you share how to do it~? Thanks a lot.
@gabpaet that’s unrelated, it appears you need to bump your minCompileSdk to 33 for unrelated reasons. Note this also transitively implies a bump of JDK to 11
I faced this issue on Saturday. FYI, I used rn v0.67.4. When I tried to run android on my local machine, it was failed. the error message indicated on
@react-native-async-storage/@async-storage
. I did clean my project gradle was no luck. However, on my Jenkins pipeline this issue did not occur. So, I concluded there is global caches somewhere in my machine. After googling it i found thisrm -rf $HOME/.gradle/caches
. Solved the issue 🎉Do not post “me too” comments
This issue affects nearly everyone and github issues do not handle enormous numbers of comments well.
If you post metoo comments (or even "thank you"s) you are actively making it harder on your fellow developers to fix their builds by making it harder for them to find the relevant information.
If it works for you please share the solution with developers you know or retweet https://twitter.com/reactnative/status/1589296764678705155 - that will have a positive impact for other developers
It appears there may be a problem related to people not using hermes, though this has not been confirmed.
It is still our understanding that if applied correctly, we have these choices for a fix:
1- for the actual 0.71.0-rc.0 version you do not need a workaround 2- for “current” (react-native 0.64+ or 0.65, using gradle 6.2 or higher as determined in your gradle wrapper) - adding the exclusive repository definition described all the way at the top in the main description above works 3- for “old” (react-native 0.63 or lower, using gradle 6.1 or lower) - pinning the version via this workaround works https://github.com/facebook/react-native/issues/35210#issuecomment-1304536693
Hi, after applying the fix the build in eas works correctly, but when running the application in production in android it crashes at startup. Does it happen to anyone else? any solution?