react-native: [HAS WORKAROUND] Android build fails since 0.71.0-rc.0 tag added
WORKAROUND
Issue #35210 now has the best description and current best-known fix for the issue
we are working hard to keep that issue up to date as we learn new things
go to the issue and get the workaround: #35210
Original issue report follows:
Description
Builds started failing couple hours ago.
* What went wrong:
Execution failed for task ':app:mergeReleaseNativeLibs'.
> A failure occurred while executing com.android.build.gradle.internal.tasks.MergeNativeLibsTask$MergeNativeLibsTaskWorkAction
> 2 files found with path 'lib/arm64-v8a/libfbjni.so' from inputs:
- [redacted]/.gradle/caches/transforms-3/2952ab139faaa4b08a71276c5fc46221/transformed/jetified-react-native-0.71.0-rc.0-release/jni/arm64-v8a/libfbjni.so
- [redacted]/.gradle/caches/transforms-3/d1c59095249a1169bea435013b70e0a9/transformed/jetified-fbjni-0.3.0/jni/arm64-v8a/libfbjni.so
If you are using jniLibs and CMake IMPORTED targets, see
https://developer.android.com/r/tools/jniLibs-vs-imported-targets
Version
0.68.3
Output of npx react-native info
info Fetching system and libraries information… System: OS: macOS 13.0 CPU: (20) arm64 Apple M1 Ultra Memory: 2.37 GB / 64.00 GB Shell: 5.8.1 - /bin/zsh Binaries: Node: 16.15.1 - ~/Library/Caches/fnm_multishells/89099_1667585876627/bin/node Yarn: 1.22.19 - /opt/homebrew/bin/yarn npm: 8.11.0 - ~/Library/Caches/fnm_multishells/89099_1667585876627/bin/npm Watchman: 2022.10.31.00 - /opt/homebrew/bin/watchman Managers: CocoaPods: Not Found SDKs: iOS SDK: Platforms: DriverKit 22.1, iOS 16.1, macOS 13.0, tvOS 16.1, watchOS 9.1 Android SDK: Not Found IDEs: Android Studio: 2021.3 AI-213.7172.25.2113.9014738 Xcode: 14.1/14B47b - /usr/bin/xcodebuild Languages: Java: 11.0.16.1 - /usr/bin/javac npmPackages: @react-native-community/cli: Not Found react: 17.0.2 => 17.0.2 react-native: 0.68.3 => 0.68.3 react-native-macos: Not Found npmGlobalPackages: react-native: Not Found
Steps to reproduce
npx react-native run-android
Snack, code example, screenshot, or link to a repository
N/A
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Reactions: 54
- Comments: 79 (34 by maintainers)
Links to this issue
Commits related to this issue
- android: Ensure we use the local Maven repo to get react-native This fixes #35204. It ensures that for getting the Android binary dependencies provided by React Native, the build always looks only i... — committed to gnprice/react-native by gnprice 2 years ago
- android: Fix build to get react-native only from local Maven repo This fixes a build failure which started happening today due to an operational mistake in React Native release management: https://... — committed to gnprice/zulip-mobile by gnprice 2 years ago
This is happening because all the templates reference the React Native dependency by range, like
implementation 'com.facebook.react:react-native:+'
. Usually this dependency gets resolved from the local Maven repo in./node_modules/react-native/android
but since it has been published to Maven Central it’s now grabbing the very latest RC.You can resolve this problem by forcing the React Native dependency to the version you expect with something like this
implementation 'com.facebook.react:react-native:0.68.2!!'
in your app’s Gradle file. The!!
is shorthand for restricting Gradle from upgrading if your project or its transitive dependencies depend on a newer version.AFAIK Maven Central is immutable and the published dependency can’t removed so this might be the only solution.
@andrejborstnik interesting! I can see how that can work, but it may cause problems in some CI platforms like bitrise where I think the files are readonly…so be careful
@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 in your
android/buld.gradle
fileI also want to emphasize that being react-native “release person” is a nearly zero-thanks job and takes quite a bit of time. The person doing this is a volunteer that just recently started training for it to increase the pool of people that can release (I think the current pool size is literally 2, so this would make 3 people that can do it). That is all to say that even in gigantic communities like react-native, vital things sometimes fall down to just a couple people and everyone is doing it with the good of the community at heart.
If you’ve even been a release engineer you know this is a nightmare, so everyone please take a breath and try to balance the irritation of this build break with gratitude that react-native will keep moving along, and hey, maybe without the
+
dependencies for 0.71 if it can be removed somehow.Happy Friday? 😆
Ah, this is an even better fix – thanks @inckie !
Here’s what it looks like explicitly, in
android/build.gradle
(edit: or to view as a diff, see the PR I just sent to apply this fix to the template app):That replaces the following which is already there in the template app:
The
exclusiveContent
expresses exactly what we want here:node_modules/react-native/
.With that snippet in place, there’s no need for
excludeGroup
on any individualmavenCentral
calls, and no need forresolutionStrategy
specifying the React Native version.@prolok we are currently furiously iterating on a few variants.
You might try this in your
android/build.gradle
(top level) file, in theallprojects
block, it has reported success even with reanimated etc mixed in, also has reported success with expo now (fix in progress there, they are listening closely)@bkasten-rbi maven is immutable. The damage is done, there is no undoing it 😢 (link from jaredh https://central.sonatype.org/faq/can-i-change-a-component/#question)
I can confirm that setting the following works:
I’m doing some more testing but would appreciate any other confirmations. Thanks for the information @jaredh
ref: https://docs.gradle.org/current/dsl/org.gradle.api.artifacts.ResolutionStrategy.html
At least in our
build.gradle
this is already defined and it did not make a difference.We have a pretty complicated build, however, with many moving parts so maybe there’s something else going on for my team. The
resolutionStrategy
approach has just passed on CI so at least I can confirm it works for us 😅@bkasten-rbi absolutely not the
right solutionsolution we hope for, that back-versions need to fix this locally, but I am a deeply pragmatic person, and it is Friday, already after business hours in Europe (where many of the release folks live) so I’m casting about for any workaround as this is clearly a Very Big Deal.I’m not even sure what the root cause is yet, just trying to mention the gradle adjustements I’m aware of that might unblock people if they are stuck
@mikehardy I appreciate the advice. I’m just a little concerned that a rc release was able to suddenly break several projects CI builds. Is it truly the right solution that consumers need to fix this locally?
I can confirm this worked! I was trying by adding it to android/app/build.gradle but now that I tried at android/build.gradle it finally worked! Thank you
Hey everyone! 👋
I’m happy to hear the workarounds (one for really old / <= 6.1 gradle, one for current gradle) are working. We are 99% certain now that we have solutions that should work for all cases.
Going forward please only comment if you have a failure case - something that is not handled by either of the workarounds on #35210 so the comments are focused and the notifications are only generated for things that really need attention.
Thanks!
I have left all the other workaround attempts up as each of them can fix the build for people under certain circumstances
but the best known fix is now at #35210 courtesy of @inckie and @gnprice and @cortinico - you should use that if possible
This worked on all my projects. Tks!
I have updated the guidance at the top of the issue, this last version appears to be the “most reported success” solution. Any experimental results that contradict that are welcome - we hope it works for everyone though.
Since discussions are happening in Discord, let me throw my 2 cents out there:
+
? Is there a better way for templates to use the version expected from NodeJS?I added the workaround in the main description so it is the first thing everyone sees, and added that we have a workaround in the title, hopefully no offense @markholland but this is going to get hit all weekend long maybe for longer and I want people to see the workaround immediately to waste as little of people’s time as possible.
@afturner based on my lookup just now to cross-check that the artifact really does exist on maven central this appears to be the root cause:
+
rangeThus I think either workaround - pinning the version in the dep or setting it via resolution strategy are fully functional
We’re also seeing this error and is breaking all of our CI/CD pipelines
Finally this work for me.
Really thanks for all of you for providing the workarounds!
This worked for me. V: 0.64.1
It can be suppressed on repository configuration level for all projects.
In theory react native should be always forced to be only imported from local m2, setting it to includeGroup “com.facebook.react” instead, but its not so easy to limit that
https://docs.gradle.org/current/userguide/declaring_repositories.html#declaring_content_exclusively_found_in_one_repository
Update: yes, exclusive content also works unless someone needs one of few other artifacts in same group.
I have tried this already, the app can be built successfully but crashed once it is just launched.
Here the packaginOptions I added
And below are my logs:
@mikehardy thank you so much for your help!!! it worksss 😃
Hi , To resolve the issue this method worked for me , hope this will help you guys too!! step 1 : In package.json or node_modules inside copy the version of react native that you have step 2 : In the project , android/app/build.gradle the existing would be like this
**com.facebook.react:react-native:+**
Change this to**com.facebook.react:react-native:<react version>!!**
step 3 : Run the below command cd android & ./gradlew cleanstep 4 : Run this command react-native run-android
Add this fix to your android -> build.gradle file as follows:
What this fix will do is apply an
exclusiveContent
resolution rule that will force the resolution of React Native Android library, to use the one insidenode_modules
Ref: Fix and updates on Android build failures happening since Nov 4th 2022 #35210
android { packagingOptions { pickFirst ‘lib/arm64-v8a/libc++_shared.so’ pickFirst ‘lib/arm64-v8a/libfbjni.so’ pickFirst ‘lib/armeabi-v7a/libc++_shared.so’ pickFirst ‘lib/armeabi-v7a/libfbjni.so’ pickFirst ‘lib/x86/libc++_shared.so’ pickFirst ‘lib/x86/libfbjni.so’ pickFirst ‘lib/x86_64/libc++_shared.so’ pickFirst ‘lib/x86_64/libfbjni.so’ } …//other code }
above code in android/app/build.gradle fixed my problem
I am using react native version 0.69.5
Update: I was able to make the build but it is crashing the app and looking for the solution. if it worked I will update here.
Another update :
Below code worked perfectly for me.
Add this to your android/build.gradle,
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 { force “com.facebook.react:react-native:” + REACT_NATIVE_VERSION } }
The file you should be looking at is
android/build.gradle
This works well for simple projects. However, as several people pointed out above, it might not work when the React Native app has dependencies that include native modules with a dependency on
kotlin-stdlib
(andmavenCentral
inrepositories
). Errors such as the following will be printed to console:My guess is that’s because
react-native:0.71.0-rc.0
contains a compile dependency onkotlin-stdlib-jdk8:1.6.10
: https://search.maven.org/artifact/com.facebook.react/react-native/0.71.0-rc.0/pomOne solution without forcing anything is to fix up the problematic dependencies (subprojects) like so:
Over time, as those dependencies will get fixed in newer versions, entries can be removed from the list piece by piece.
I know this is rare case. If people has patch to the java files, their patch never be able to be applied
Want to add what I tried with @mikehardy 's workaround, but I found the other modules still using 0.71.0-rc.0, and that made my app crash as the app is running with version 0.66.4
and the error is coming from react-native-document-picker:
@jesboat that cannot work though, as the + would then resolve that, but it would only be the right version for people on that exact version.
resolutionStrategy as defined at the top of this issue appears to be the current best solution based on Discord discussion. It is not great because now you have the version hard-coded in there, but it should work without needing patches in bunches of modules.
Apparently 0.71 will fix all this either way
There may be a gradle stanza you can author to force your app level repo excludes to all sub-projects, but resolutionStrategy will do to get people moving, it seems
Here is another possible solution, perhaps the best possible solution (from @cortinico on discord), in your
android/buld.gradle
https://github.com/facebook/react-native/blob/3e75c0b3baa265a7b5431cd2d304389f9a3faa44/template/android/build.gradle#L43-L49
That will stop the new version from resolving, and revert back to local node_modules resolution of react-native
Should the suggested
resolutionStrategy
workaround fix all possible manifestations of this issue? The only thing that has worked for me so far is directly patching my dependencies(react-native-auth0
)build.gradle
Using RN 67~ or something, our build has been reporting the new RC tag…
I’m seeing that a lot of libs declare their dependency (?) in RN as
api 'com.facebook.react:react-native:+'
, so somehow that dep ended up going to all apps everywhere, but I’m not being able to track where that original package is being declareddoes that have anything related to the changes in the package json here?
It is true the Discord is not generally accessible - I only mentioned it to note for interested parties here (where the work should take place and likely will) that there had been notice
It could be, I have no authority to do so - the people that do are on that Discord though and I’ve seen as of this typing some recognition from them that they’ve seen this, so hopefully there will be a valid workaround (perhaps a tag removal) soon.
It may be that some artifact was published somewhere and simply removing the tag will not help, as mentioned just above there has not been a clearly identified root cause of exactly why old versions of react-native would be affected by / include transitive dependencies of the new version yet. So it’s all speculation in the absence of a correct technical analysis.