Closed markholland closed 1 year ago
Hey all, Thanks for investigating and fixing this issue. I've posted a short summary and suggested @inckie fix as the recommended one which is verified as working in this other post:
There you can find also a technical explanation on why this happened.
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 }
Having the same error, could someone specify where in build.gradle to add this code?
The file you should be looking at is android/build.gradle
allprojects {
repositories {
- mavenCentral()
+ mavenCentral { content { excludeGroup 'com.facebook.react' } }
}
}
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
(and mavenCentral
in repositories
). Errors such as the following will be printed to console:
> Task :react-native-webview:compileDebugKotlin FAILED
e: Incompatible classes were found in dependencies. Remove them from the classpath or use '-Xskip-metadata-version-check' to suppress errors
e: ~/.gradle/caches/transforms-3/123/transformed/jetified-kotlin-stdlib-common-1.6.10.jar!/META-INF/kotlin-stdlib-common.kotlin_module: Module was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.6.0, expected version is 1.1.15.
My guess is that's because react-native:0.71.0-rc.0
contains a compile dependency on kotlin-stdlib-jdk8:1.6.10
: https://search.maven.org/artifact/com.facebook.react/react-native/0.71.0-rc.0/pom
One solution without forcing anything is to fix up the problematic dependencies (subprojects) like so:
subprojects {
if (it.name in [
'react-native-pager-view',
'react-native-screens',
'react-native-webview',
]) {
it.evaluate()
it.repositories.each { repo ->
if (repo.name == 'MavenRepo') {
repo.content { excludeGroup 'com.facebook.react' }
}
}
}
}
Over time, as those dependencies will get fixed in newer versions, entries can be removed from the list piece by piece.
Having the same error, could someone specify where in build.gradle to add this code?
The file is your android/build.gradle
file.
Please also refer to the suggested fix in #35210
@friederbluemle what you're suggesting is sadly not correct. Please refer to the linked issue #35210
Having the same error, could someone specify where in build.gradle to add this code?
The file is your android/build.gradle
file.
Please also refer to the suggested fix in #35210
@friederbluemle what you're suggesting is sadly not correct. Please refer to the linked issue #35210
@cortinico - Why are you saying this is not correct (what specifically)?
Faced similar issue just now. But applied the @markholland solution, and it worked.
RN version: 0.66.4
Just a few hours ago, when installing the app on android, I noticed react-native-0.71.0-rc-debug.tar.gz
getting downloaded automatically. After it happening, the app was no longer building, and threw :app:mergeDebugNativeLibs
error after 98% completion.
But before this was downloaded, app had been building successfully.
still having this issue even after writing the workaround....been stuck since more than 3 hours
Here is the way how i fixed this issue :-
1st go to android/build.gradle
//2nd find allprojects ,then add below def line exact above of the allprojects { ... } section staring
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 {
//3rd go inside allprojects { ... } ,then add below configurations.all { ... } , at this top section inside allprojects { ... }
//this section only start
configurations.all {
resolutionStrategy {
force "com.facebook.react:react-native:" + REACT_NATIVE_VERSION
}
}
//this section only end
// keep all below default codes as it is
repositories {
....
}
}
Same here. I used to think that I downloaded the wrong package. ~~~~ Solved my problem with the following code
allprojects {
configurations.all {
resolutionStrategy {
force 'com.facebook.react:react-native:<your version>'
}
}
repositories {
// ...
}
}
Thanks god!
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 } }
@gnprice thanks for the solution :) This solution worked absolutely fine with me.
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
Hey everyone! :wave:
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 was suddenly seeing hermes-engine
at this new tag too. I'm not sure whether it's something I did (I'm troubleshooting a segfault so adding and removing packages) but was surprised to see 0.71.0-rc.0
in the stack trace since I'm using React Native 0.70.4.
Turns out I had the original workaround (force "com.facebook.react:react-native:" + REACT_NATIVE_VERSION
) and not the new exclusiveContent
workaround set up, so that may have been why.
I was seeing hermes-engine-0.71.0-rc.0-debug.aar
even though my RN is 0.70.4. I thought it was worth mentioning just in case, and because I hadn't seen that file name come up in the discussions.
* What went wrong:
Execution failed for task ':app:checkDevDebugAarMetadata'.
> Could not resolve all files for configuration ':app:devDebugRuntimeClasspath'.
> Failed to transform hermes-engine-0.71.0-rc.0-debug.aar (com.facebook.react:hermes-engine:0.71.0-rc.0) to match attributes {artifactType=android-aar-metadata, com.android.build.api.attributes.BuildTypeAttr=debug, org.gradle.category=library, org.gradle.dependency.bundling=external, org.gradle.libraryelements=aar, org.gradle.status=release, org.gradle.usage=java-runtime}.
> Execution failed for JetifyTransform: /Users/elliott/.gradle/caches/modules-2/files-2.1/com.facebook.react/hermes-engine/0.71.0-rc.0/249b5158005e2c14312b9099185f65d1f08ccf1d/hermes-engine-0.71.0-rc.0-debug.aar.
> Java heap space
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?
Add this fix to your android -> build.gradle file as follows:
buildscript {
// ...
}
allprojects {
repositories {
exclusiveContent {
filter {
includeGroup "com.facebook.react"
}
forRepository {
maven {
url "$rootDir/../node_modules/react-native/android"
}
}
}
// ...
}
}
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 inside node_modules
Ref: Fix and updates on Android build failures happening since Nov 4th 2022 #35210
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 clean
step 4 : Run this command react-native run-android
I'm trying to apply the fix but i'm getting this error: Caused by: org.gradle.internal.resolve.ModuleVersionNotFoundException: Could not find any matches for com.facebook.react:react-native:+ as no versions of com.facebook.react:react-native are available. Required by: project :app project :app > project :react-native-community_slider
@anveshbabu that is a more brittle version of the recommendation for people on old react-native as it hardcodes the react-native version, we do not recommend it. @mariaeduardaes something about the application of the workaround is incorrect but you have not provided enough details to help (specifically, no version information of anything is included, nor do you mention which workaround you are attempting https://stackoverflow.com/help/how-to-ask) - I suggest if no versions are available, then the workaround may not be in the correct place in your build.gradle
There is information there that explains what you need to do, based on what react-native version you are using.
Go to that issue and read it, please.
@mikehardy hey, sorry for the poor information.. i tried to apply the first fix mentioned #35210, i'm using "react-native": "=0.64.1", my android -> build.gradlew looks like:
` buildscript {
ext {
buildToolsVersion = "29.0.3"
minSdkVersion = 21
compileSdkVersion = 29
targetSdkVersion = 29
ndkVersion = "20.1.5948944"
}
repositories {
google()
jcenter()
}
dependencies {
classpath("com.android.tools.build:gradle:4.1.0")
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects { repositories { exclusiveContent { // We get React Native's Android binaries exclusively through npm, // from a local Maven repo inside node_modules/react-native/. // (The use of exclusiveContent prevents looking elsewhere like Maven Central // and potentially getting a wrong version.) filter { includeGroup "com.facebook.react" } forRepository { maven { url "$rootDir/../node_modules/react-native/android" } } } mavenCentral() maven { // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm url("$rootDir/../../../node_modules/react-native/android") } maven { // Android JSC is installed from npm url("$rootDir/../../../node_modules/jsc-android/dist") }
google()
jcenter()
maven { url 'https://www.jitpack.io' }
}
} `
and i had this error:
Caused by: org.gradle.internal.resolve.ModuleVersionNotFoundException: Could not find any matches for com.facebook.react:react-native:+ as no versions of com.facebook.react:react-native are available. Required by: project :app project :app > project :react-native-community_slider
Hope that's enought information, thank you so much for your help!
@mariaeduardaes sounds like the "old gradle" case explained here in that issue?
The fix for older (< 0.63, maybe 64) react-native 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 older react-native (for example 0.63 or earlier) that uses gradle version 6.1 or below, you must use a different workaround, detailed here: https://github.com/facebook/react-native/issues/35210#issuecomment-1304536693
@mikehardy in that file looks like my gradlew version 6.7
distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists distributionUrl=https\://services.gradle.org/distributions/gradle-6.7-all.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists
anyway i tried to apply that fix but it didn't work as well, you think is better for me to keep trying with the fix for older gradle?
🤔 I am not sure. your version is new enough to support the preferred exclusive content filter. Your error message consistently indicates that gradle cannot find any react-native which is different then any of the other errors people have seen, it is unique + unexpected as an error. I think the preferred exclusive content filter is the one to try, but why the error where it cannot find any version at all?
It looks like you may be in a monorepo and your paths do not quite match up, for the repository definition. I would make sure that the workaround path and your repository definition path are both exactly equal:
url("$rootDir/../../../node_modules/react-native/android")
(note the number of ../
chunks)
@mikehardy thank you so much for your help!!! it worksss :)
Okay - I will update the issue in 35210 to include an asterisk for monorepos so future people will know to be careful with paths. Thanks for confirming. Going to hide these comments after updating the description, to try to keep the thread really really clean for everyone that is going to need this Monday morning...
There is information there that explains what you need to do, based on what react-native version you are using.
We are working hard to keep that issue up to date as we learn new things
Go to that issue and read it, please
The issue has now been fully addressed, please refer to https://github.com/facebook/react-native/issues/35210#issuecomment-1310170361 for details
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.
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