After running react-native run-android I get the following error, I have no idea what to do from here as I installed everything the standard way using npm i
Error building DependencyGraph:
Error: Naming collision detected: /Users/guerilla/Code/ReactNative/node_modules/react-native/node_modules/fbjs/lib/CSSCore.js collides with /Users/guerilla/Code/ReactNative/node_modules/react/node_modules/fbjs/lib/CSSCore.js
Two ways you can work around that
It seems npm 3 handles duplicate dependencies much better than old versions of npm so delete your node_modules folder, upgrade to npm 3 and the run npm i again, this should solve the problem
Manually install fbjs on the top level, ie add it as a dependency in you package.json file and manually delete all occurences of fbjs in other modules so they all use the same one on the top level
Related
I've been working in the same React Native project for months and recently the Android build has started failing. To my knowledge I haven't changed anything about my development environment and I haven't updated or changed any packages or dependencies that the project uses.
Task :#react-native-community_async-storage:compileDebugJavaWithJavac FAILED
Task :#react-native-community_datetimepicker:compileDebugJavaWithJavac FAILED
Task :#react-native-community_toolbar-android:compileDebugJavaWithJavac FAILED
Task :#sentry_react-native:compileDebugJavaWithJavac FAILED
Task :#react-native-community_netinfo:compileDebugJavaWithJavac FAILED
I've done all of the following that I found from other questions with a similar problem
Synced the project with gradle files in android studio
Ran gradlew clean in the android directory which does succeed, but the build still fails
Checked that android.useAndroidX and android.enableJetifier in the gradle.properties file are both true
Checked that I have implementation "com.facebook.react:react-native:+" in my build.gradle file. I tried changing it from + to the actual version of react native that I'm using but it made no difference.
I'm not an expert mobile developer by any means so I'm hoping that I'm missing something obvious, but any help or suggestions would be greatly appreciated.
I had been struggling with the same issue for weeks. Android build just stopped working in November. Just found the solution here (phew!) https://github.com/facebook/react-native/issues/35210
On November 4th 2022 React Native version 0.71.0-rc0 was published but 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).
See all the detail in the link but the solution for me was to add the configurations.all section below to the android/build.gradle file
allprojects {
repositories {...}
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:0.61.5"
}
}
}
For good measure I then also did the following
$ rm -rf node_modules
$ cd android
$ rm -rf .gradle
$ cd ..
$ npm install
$ react-native run-android
Hope this helps someone else as I was really struggling to fix this one.
Taking over RN project from another developer and trying to make a build for Android, however Gradle keeps giving me this issue:
ERROR: Project with path ':unimodules-core' could not be found in project ':#unimodules_react-native-adapter'.
The only solution I could find regarding this is adding settings.gradle file:
include ':#unimodules_react-native-adapter'
project(':#unimodules_react-native-adapter').projectDir = new File(rootProject.projectDir, '../node_modules/#unimodules/react-native-adapter/android')
but this doesn't work for me.
I have linked the native dependecies
I have tried npm and yarn
Project is using:
"#unimodules/core": "^3.0.2",
"#unimodules/react-native-adapter": "^3.0.0",
Gradle is directing me to the #unimodules/react-native-adapter/android/build.gradle file:
apply from: project(":unimodules-core").file("../unimodules-core.gradle")
Any guidance of what could possible be wrong, would greatly be appreciated
Something that solved this for me was removing: #unimodules/react-native-adapter from dependencies entirely.
I solved my issue by installing react-native-unimodules.
$> yarn add react-native-unimodules
Managed to fix it by deleting project, cloning it again and only running yarn instead of trying npm and yarn.
To resolve this, you can try using npm to:
1- Remove from your package.json
this line:
"#unimodules/core": "^3.0.2",
on "dependencies": { part
2- Install the unimodules-core package:
with npm:
npm install #unimodules/core --save
you can do identical thing with yarn , you can take a look to the official doc:
https://www.npmjs.com/package/#unimodules/core?activeTab=readme
For me, the issue was using expo packages (e.g. "import * as Crypto from 'expo-crypto"). I removed them and the problem went away.
I have a project using dynamic feature module, and I want to run my unit test in feature module via gradle task (for my CI purpose):
./gradlew :feature_product:test
But it always gives me NoClassDefFoundError for tests that have dependencies on classes from the base module:
com.example.android.feature.product.ProductViewTest > on vote change to negative FAILED
java.lang.NoClassDefFoundError: app.BaseView
ProductView class from the feature module extends BaseView from the base module.
Oddly, it succeeds when run in Android Studio, it works fine.
Then I notice something different in the logs, when I run via command line and when I run Android Studio. The first line in the Android Studio is generateDebugSources, something which absent when I run ./gradlew test
Executing tasks: [:lib_ui:generateDebugSources, ...]
How do I fix this? Does Android Studio has different command with the provided command ./gradlew test when I press Ctrl+Shift+R ?
After searching further about this issue, I found it also being reported in the android-test and app-bundle-samples projects and there is also an issue in the issue tracker.
It turns out this issue fixed in the Android Gradle Plugin 4.1.0 as per comment in the issue tracker.
If you don't want to update AGP to 4.1.0 which is still in alpha, adding this to the feature module's build.gradle fixed the issue for me, as per this comment:
testRuntimeOnly(files("$projectDir/../b_app/build/intermediates/app_classes/debug/classes.jar"))
If it is a missing task that you believe is necessary then calling it first like below should do the trick:
./gradlew :lib_ui:generateDebugSources :feature_product:test
I would even go full on and assemble the dependencies if necessary though that might take more time:
./gradlew :lib_ui:assemble :feature_product:assemble :feature_product:test
I recently upgraded to RN 0.20 and I now have the following exception thrown when I try to load my app:
undefined is not an object (evaluating 'screenPhyisicalPixels.width')
<unknown>
index.android.bundle?platform=android& def=true:32950
requireImpl
index.android.bundle?platform=android& def=true:76
_require
index.android.bundle?platform=android& def=true:36
Which apparently causes a JS error the following file:
node_modules/react-native/Libraries/Utilities/Dimensions.js at line 30
For info, I'm not using the Dimensions API in my app.
Any tip on this?
You need to update the string in android/app/build.gradle to
dependencies {
compile "com.facebook.react:react-native:0.20.+"
}
Then just run
npm start
react-native run-android
I had a similar problem when upgrading my project from 0.19 to 0.20.
What did it for me, was running react-native upgrade.
After that, you'll probably have to reinstall your modules with npm install.
edit: and of course rebuild your app after that via react-native run-android.
The best thing to do is to remove node_modules folder. After that run on root directory
watchman watch-del-all
Next step is to run
npm install
Then start packager manually with
react-native start --reset-cache
Thats what helped for me. Good luck!
I'm unclear of what command did what exactly, but I fixed it after the following steps, thanks to a combination of #mr-brown and #matija-grcic answers:
Set "react-native": "^0.20.0", in package.json
Delete node_modules
Run react-native upgrade (updates android/app/build.gradle among others)
Uninstall app on my phone
react-native run-android
I have a Gradle file that runs the tests. It does not build anything. All it has is a unzip task that extracts all jars in a Gradle configuration into a particular directory and then runs the task of type Test. This test task points the testClasses directory to the location where the previous copy task has extracted the configuration into.
My build fails with the error message:
Problems reading data from Binary store
When I run 'gradle dependencies' it does not show any error/warning
When I run the copy task individually, it runs very well fine.
Only when I run everything it fails with error :
> Could not resolve all dependencies for configuration ':testConfig'.$
> Problems reading data from Binary store in /tmp/gradle8793563212642185736.bin (exist: false)$
I see the file /tmp/gradle8793563212642185736.bin does not exist. What could be the reason for this?
I solved upgrading following packages to last version (06/02/2021), so:
project app-level build.gradle file:
com.google.firebase:firebase-analytics:17.2.2
to
com.google.firebase:firebase-analytics:18.0.2
Project-level build.gradle file:
com.google.gms:google-services:4.3.3
to
com.google.gms:google-services:4.3.5
In my case setting org.gradle.parallel=false flag fixes the issue, but it's not a solution for my project, flag increase CI build time from ~15min to ~45min.
Turns out it was just a network problem for me. Gradle just needed to connect to the internet.
It happened with Flutter development in my case. Apparently, it is not an actual issue and there is no magic fix. Cleaning build file with "Flutter clean" and restarting the command line executer window solved the issue.
I was working with version 5.x earlier and then I upgraded to 6.0.1 and it resolved the issue.
this is how you can upgrade
cd android
./gradlew clean
./gradlew wrapper --gradle-version 6.0.1
./gradlew -v # to download the new version
cd ..
flutter clean
flutter run # might take 15 - 20mins for the first time
There are mainly a few steps to solve this problem.
Go to gradle.properties and set org.gradle.parallel=false and sync. Make sure your sync gradle offline option is off
Start the build with this option. If it's a big project setting org.gradle.parallel=false will take a long time.
Cancel the build repeat the steps setting org.gradle.parallel=true.
Also do not turn on offline build
This solution worked in my flutter project. I solved it by making these changes:
In android level build.gradle file, replace classpath 'com.android.tools.build:gradle:3.5.4' with classpath 'com.android.tools.build:gradle:4.0.1' (basically upgrade the version from 3.5.4 to 4.0.1)
In gradle-wrapper.properties file, replace distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.2-all.zip with distributionUrl=https\://services.gradle.org/distributions/gradle-6.1.1-all.zip (upgrade from 5.6.2 to 6.1.1)
and if you have added classpath 'com.google.gms:google-services:4.3.3' to android level build.gradle file, replace that too with classpath 'com.google.gms:google-services:4.3.5' (upgrade from 4.3.3 to 4.3.5)
In my case the writing problem was there was no enough storage to build the app so I needed to restart my Mac and it finished building successfully.
I know am too late but it might help someone in the future so
Start by upgrading Gradle to the latest version.
Binary store issues reported to GitHub are often fixed right away, especially if they include a Minimal, Reproducible Example.
If upgrading didn't work, it can be useful to run the task again with Performance options disabled:
--no-parallel
--no-configure-on-demand
Next please find an existing issue or open a new one so it can be fixed in future versions. These things are all helpful:
Minimal, Reproducible Example
Build Scan
Smallest change that introduced the problem (e.g. worked on 5.5, but not 5.6)
I ended up here after publishing an artifact to mavenLocal().
I tried a lot but in the end what helped me was:
Upgrading gradle from 6.3 to 6.9
./gradlew wrapper --gradle-version 6.9
Hope this saves me half an hour next time this occurs.
Thanks to Cedric's hint, stopping gradle offline mode and make it online, fixed the issue for me