React Native Android: screenPhysicalPixels.width is undefined - android

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

Related

React Native Android build failing with 'compileDebugJavaWithJavac' on several packages

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.

An unhandled exception occurred: Project target does not exist

I have a problem when I write:
ionic cordova prepare androidŲŒ
Knowing that this is happening with every new project I create.
Please help.
The problem is caused by required builders that are missing from the angular.json file. To install those builders, run:
ng add #ionic/cordova-builders
You should get an output similar to this:
After that, go ahead and run your build.
Ionic CLI v6.19.0 has been released with this fix:
npm install -g #ionic/cli#latest
bug report on GitHub:
https://github.com/ionic-team/ionic-framework/issues/24940#issuecomment-1068016921

Project with path ':unimodules-core' could not be found in project ':#unimodules_react-native-adapter'

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.

React Native Android error in com.facebook.react.bridge.NoSuchKeyException

I'm getting an error caught by Crashlytics and it's happening to almost 45% of the users but it doesn't seem to happen when the user is using the app but when it's in the background.
The stacktrace shown on Crashlytics is:
Fatal Exception: com.facebook.react.bridge.NoSuchKeyException ReadableNativeMap.java:124
lineNumber
I have no clue what can be causing this issue, if it's a Javascript error or a native library error
This is a problem caused by the stacktrace-parser library which is used internally by react native. Basically, release 0.1.4 works fine while releases 0.1.5 and 0.1.6 causes the lineNumber error.
Do the following to fix this:
If you are using yarn add the following to your package.json:
"resolutions": {
"stacktrace-parser": "0.1.4"
},
if you are using npm add the following to your package.json:
"dependencies": {
...
"stacktrace-parser": "0.1.4"
Remove the yarn.lock (or package-lock.json) file and the node_modules directory.
Install the packages yarn install (or npm install)
Rebuild your release build.
I hope this helps others until the library gets fixed.
My solution was to remove every console.error in my project.
https://github.com/facebook/react-native/issues/24382
Make sure "backgroundColor" value is never null or undefined. In my case that was the reason.
It ended up being an issue with some native library that was causing the crash. Simply upgrading it solved the problem

react-native Error building DependencyGraph

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

Categories

Resources