React-Native - react-native-update-gradle - Error - android

i had an error with my React-Native Project for Android.
My first error was the following:
I added the "react-native-location" Library. After i run the Command "react-native link", the error "compileOnly" was thrown.
So my first try was, upadate NPM and Node.JS.
But it wasn´t the right solution for my Problem.
After that, i had google the Error and i want to update grandle with "react-native-update-gradle". My main Problem now is, when i run the "react-native link" command, i get the following error:
C:\Computer\Apps\Projects\XXX>react-native link
Scanning folders for symlinks in C:\Computer\Apps\Projects\XXX\node_modules (70ms)
rnpm-install info Platform 'ios' module react-native-orientation is already linked
rnpm-install info Platform 'android' module react-native-orientation is already linked
internal/validators.js:125
throw new ERR_INVALID_ARG_TYPE(name, 'string', value);
^
TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string. Received type undefined
at validateString (internal/validators.js:125:11)
at Object.join (path.js:427:7)
at getSDKPath (C:\Computer\Apps\Projects\XXX\node_modules\react-native-update-gradle\index.js:13:12)
at getPTPath (C:\Computer\Apps\Projects\XXX\node_modules\react-native-update-gradle\index.js:17:20)
at Object.activateADB (C:\Computer\Apps\Projects\XXX\node_modules\react-native-update-gradle\index.js:5:42)
at Object.<anonymous> (C:\Computer\Apps\Projects\XXX\node_modules\react-native-update-gradle\cli.js:101:6)
at Module._compile (internal/modules/cjs/loader.js:734:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:745:10)
at Module.load (internal/modules/cjs/loader.js:626:32)
at tryModuleLoad (internal/modules/cjs/loader.js:566:12)
C:\Computer\Apps\Projects\XXX\node_modules\react-native\local-cli\core\makeCommand.js:27
throw new Error(`Error occurred during executing "${command}" command`);
^
Error: Error occurred during executing "node ./node_modules/react-native-update-gradle/cli.js" command
at ChildProcess.prelink (C:/Computer/Apps/Projects/XXX/node_modules/react-native/local-cli/core/makeCommand.js:27:15)
at ChildProcess.emit (events.js:197:13)
at maybeClose (internal/child_process.js:978:16)
at Process.ChildProcess._handle.onexit (internal/child_process.js:265:5)
I tried to fix the Error, but the error is still there.
I had the following Environments
Window 10
React-Native 0.55.4
React-Native-Cli 2.0.1
NodeJS v11.9.0
npm 4.6.0
android/build.gradle
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.2.1'
}
}
allprojects {
repositories {
mavenLocal()
jcenter()
maven {
// All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
url "$rootDir/../node_modules/react-native/android"
}
maven {
url 'https://maven.google.com'
}
}
}
ext {
compileSdkVersion = 28
targetSdkVersion = 28
buildToolsVersion = "28.0.3"
supportLibVersion = "28.1.1"
playServicesVersion = "15.0.1"
}
package.json
{
"name": "XXX",
"version": "1.0.1",
"private": true,
"scripts": {
"start": "node node_modules/react-native/local-cli/cli.js start",
"test": "jest",
"run-android": "react-native run-android"
},
"dependencies": {
"react": "16.3.1",
"react-native": "0.55.4",
"react-native-image-slider": "^2.0.3",
"react-native-image-zoom-viewer": "^2.2.25",
"react-native-orientation": "^3.1.3",
"react-native-pinch-zoom-view": "^0.1.6",
"react-native-responsive-image": "^2.3.1",
"react-native-router-flux": "^4.0.0-beta.28",
"react-native-scrolltotop": "0.0.6",
"react-native-slideshow": "^1.0.1",
"react-native-swipe-gestures": "^1.0.2",
"react-native-update-gradle": "^1.1.0",
"react-native-vector-icons": "^4.6.0",
"react-native-zoom-view": "^1.0.2"
},
"devDependencies": {
"babel-jest": "22.4.3",
"babel-preset-react-native": "4.0.0",
"jest": "22.4.3",
"react-test-renderer": "16.3.1"
},
"jest": {
"preset": "react-native"
}
}
If you need more information to help me, please tell me that.
Thanks for your help.
Best Regards

Hi Sebastian ! After you run the command react-native link, you have to run the command react-native run-android or react-native run-ios. So that the library you have installed adjusts to your react native settings. This is work for me, after I installed the library or package. hope this helps.

Related

React Native (Android) - Failed to transform hermes-debug.aar

I am working on an old React Native app and want to upgrade RN version from version ^0.64.2 to 0.70.1. After using command npx react-native upgrade, there are changes in number version of dependencies. I also edit build.gradle in andriod\app folder as instructed in this document:
project.ext.react = [
enableHermes: true // clean and rebuild if changing
]
...
dependencies {
...
if (enableHermes) {
def hermesPath = "../../node_modules/hermes-engine/android/";
debugImplementation files(hermesPath + "hermes-debug.aar")
releaseImplementation files(hermesPath + "hermes-release.aar")
} else {
implementation jscFlavor
}
...
}
After that, I run command ./gradlew clean in android folder and run npx react-native run-android. Then this error shows up:
BUILD FAILED in 9s
error Failed to install the app. Make sure you have the Android development environment set up: https://reactnative.dev/docs/environment-setup.
Error: Command failed: gradlew.bat app:installDebug -PreactNativeDevServerPort=8081
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:checkDebugAarMetadata'.
> Could not resolve all files for configuration ':app:debugRuntimeClasspath'.
> Failed to transform hermes-debug.aar to match attributes {artifactType=android-aar-metadata}.
> Execution failed for JetifyTransform: D:\{ProjectFolder}\node_modules\hermes-engine\android\hermes-debug.aar.
> Transform's input file does not exist: D:\{ProjectFolder}\node_modules\hermes-engine\android\hermes-debug.aar. (See https://issuetracker.google.com/issues/158753935)
After taking a while, I also found out that there is no hermes-engine folder inside node_modules folder but still have no clue what to do.
Here is my package.json:
{
"name": "MyApp",
"version": "1.0.0",
"private": true,
"scripts": {
"android": "react-native run-android",
"ios": "react-native run-ios",
"start": "react-native start",
"test": "jest",
"lint": "eslint ."
},
"dependencies": {
"#notifee/react-native": "^3.0.4",
"#react-native-async-storage/async-storage": "^1.17.10",
"#react-native-community/art": "^1.2.0",
"#react-native-community/datetimepicker": "^3.5.2",
"#react-native-firebase/app": "^12.9.0",
"#react-native-firebase/messaging": "^12.9.0",
"#react-navigation/material-top-tabs": "^6.2.1",
"#react-navigation/native": "^6.0.1",
"#react-navigation/stack": "^6.2.1",
"axios": "^0.24.0",
"fbjs": "^3.0.4",
"jest": "^26.6.3",
"jwt-decode": "^3.1.2",
"moment": "^2.29.3",
"moment-timezone": "^0.5.34",
"prop-types": "^15.8.1",
"react": "18.1.0",
"react-native": "0.70.1",
"react-native-biometrics": "^2.1.4",
"react-native-camera": "^3.35.0",
"react-native-chart-kit": "^6.12.0",
"react-native-elements": "^2.0.4",
"react-native-file-viewer": "^2.1.1",
"react-native-fs": "^2.20.0",
"react-native-gesture-handler": "^1.10.3",
"react-native-image-crop-picker": "^0.32.2",
"react-native-modal": "^11.5.6",
"react-native-pager-view": "^5.4.24",
"react-native-pdf": "^6.2.0",
"react-native-picker-select": "^8.0.0",
"react-native-pie-chart": "^2.0.2",
"react-native-render-html": "^6.3.4",
"react-native-safe-area-context": "^3.0.2",
"react-native-screens": "^3.13.1",
"react-native-simple-toast": "^1.1.2",
"react-native-svg": "^12.1.1",
"react-native-swipe-list-view": "^3.2.9",
"react-native-tab-view": "^3.1.1",
"react-native-vector-icons": "^7.0.0",
"react-navigation": "^4.4.0",
"react-query": "^3.34.2",
"react-redux": "^7.2.0",
"redux": "^4.0.5",
"redux-devtools-extension": "^2.13.8",
"redux-thunk": "^2.3.0",
"toggle-switch-react-native": "^3.3.0"
},
"devDependencies": {
"#react-native-community/eslint-config": "^2.0.0",
"babel-plugin-root-import": "^6.5.0",
"eslint": "^7.14.0",
"react-test-renderer": "^17.0.1"
},
"jest": {
"preset": "react-native"
}
}
Update: The error still occur after I edited package.json and use npm install to add hermes-engine. Here are the errors:
npm WARN config global `--global`, `--local` are deprecated. Use `--location=global` instead.
npm ERR! code ERESOLVE
npm ERR! ERESOLVE could not resolve
npm ERR!
npm ERR! While resolving: react-query#3.34.2
npm ERR! Found: react#18.1.0
npm ERR! node_modules/react
npm ERR! react#"18.1.0" from the root project
npm ERR! peer react#"*" from #jsamr/react-native-li#2.3.1
npm ERR! node_modules/#jsamr/react-native-li
npm ERR! #jsamr/react-native-li#"^2.3.0" from react-native-render-html#6.3.4
npm ERR! node_modules/react-native-render-html
npm ERR! react-native-render-html#"^6.3.4" from the root project
npm ERR! 27 more (#react-native-community/art, ...)
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! peer react#"^16.8.0 || ^17.0.0" from react-query#3.34.2
npm ERR! node_modules/react-query
npm ERR! react-query#"^3.34.2" from the root project
npm ERR!
npm ERR! Conflicting peer dependency: react#17.0.2
npm ERR! node_modules/react
npm ERR! peer react#"^16.8.0 || ^17.0.0" from react-query#3.34.2
npm ERR! node_modules/react-query
npm ERR! react-query#"^3.34.2" from the root project
npm ERR!
npm ERR! Fix the upstream dependency conflict, or retry
npm ERR! this command with --force, or --legacy-peer-deps
npm ERR! to accept an incorrect (and potentially broken) dependency resolution.
I'm also upgrading RN version to 0.70.1, from 0.69.x you have some changes to do in app/build.gradle about hermes.
...
if (enableHermes) {
implementation("com.facebook.react:hermes-engine:+") {
exclude group: 'com.facebook.fbjni'
}
} else {
implementation jscFlavor
}
...
Source: Bundled Hermes Documentation
Try to add this to your package.json and npm install again with --legacy-peer-deps option:
"dependencies": {
"hermes-engine": "^0.11.0",
},
I went through the same error and followed the solution suggested by #fernando-garcía, but to my case it was not enough.
Indeed, I was getting the error:
TypeError: Cannot read property 'isBatchingLegacy' of undefined, js engine: hermes
The problem is definitely due to hermes, but I had to tune some other things to properly update my react-native application and let it work with react-native 0.70.0.
Here the steps I had to do to properly update my React-Native application in order to solve the problem:
Add the following snippets in android/app/build.gradle:
dependencies {
...
if (enableHermes) {
//noinspection GradleDynamicVersion
implementation("com.facebook.react:hermes-engine:+") {
exclude group:'com.facebook.fbjni'
}
}
}
if (isNewArchitectureEnabled()) {
// If new architecture is enabled, we let you build RN from source
// Otherwise we fallback to a prebuilt .aar bundled in the NPM package.
// This will be applied to all the imported transtitive dependency.
configurations.all {
resolutionStrategy.dependencySubstitution {
substitute(module("com.facebook.react:react-native"))
.using(project(":ReactAndroid"))
.because("On New Architecture we're building React Native from source")
substitute(module("com.facebook.react:hermes-engine"))
.using(project(":ReactAndroid:hermes-engine"))
.because("On New Architecture we're building Hermes from source")
}
}
}
add the following inside android/settings.gradle:
if (settings.hasProperty("newArchEnabled") && settings.newArchEnabled == "true") {
include(":ReactAndroid")
project(":ReactAndroid").projectDir = file('../node_modules/react-native/ReactAndroid')
include(":ReactAndroid:hermes-engine")
project(":ReactAndroid:hermes-engine").projectDir = file('../node_modules/react-native/ReactAndroid/hermes-engine')
}
update the react dependency inside your package.json (I had 17.0.2 and I had to update to 18.1.10):
dependencies {
...
"react": "18.1.0"
}
I am also interested about this issue, the same thing is happening for me, I already checked the Upgrade Helper, and I am upgrading from 0.68.5 to 0.70.1.
I still haven't turned on the NEW_ARCHITECTURE flag.
Installing hermes-engine package seems like not a good solution, since the upgrade steps doesn't mention that it should be done.

REACT NATIVE Could not find com.google.firebase:firebase-iid:. New update from iid broke the project

Some info first: this is not my workstation, this notebook is owned by the company i work on, i do have some access.
Some things are weird with the enviroment, but we can work, I`m not the only one having problems with the enviroment, but i dont think this is related to env, but with the latest iid update.
The way i have to start the project is by two terminals where
the usage of sudo su is to prevent some bugs within our enviroment
1 > [sudo su] yarn react-native start
2 > [sudo su] yarn android:android:debug
which results in this error:
* What went wrong:
Could not determine the dependencies of task ':app:mergeDebugAssets'.
> Could not resolve all task dependencies for configuration ':app:debugRuntimeClasspath'.
> Could not find com.google.firebase:firebase-iid:.
Required by:
project :app > project :#react-native-firebase_iid
**import info :#react-native-firebase_iid received an update as of yesterday july/07/2020
so before that all was working
follows the package.json file
"dependencies": {
"#react-native-community/async-storage": "^1.6.1",
"#react-native-community/netinfo": "^5.6.2",
"#react-native-firebase/analytics": "^6.1.0",
"#react-native-firebase/app": "^6.1.0", DOWNGRADING DID NOT HELP ( version bellow )
"#react-native-firebase/iid": "^6.3.4", DOWNGRADING DID NOT HELP ( version bellow )
"axios": "^0.19.0",
"native-base": "^2.13.1",
"prop-types": "^15.7.2",
"react": "16.8.6",
"react-native": "^0.60.4",
"react-native-barcode-builder": "^1.0.5",
"react-native-config": "^0.12.0",
"react-native-dialog": "^5.6.0",
"react-native-elements": "^1.2.0",
"react-native-flip-card": "^3.5.5",
"react-native-geolocation-service": "^3.1.0",
"react-native-gesture-handler": "^1.3.0",
"react-native-image-picker": "^1.1.0",
"react-native-keychain": "^3.1.3",
"react-native-map-link": "^2.5.1",
"react-native-maps": "^0.25.0",
"react-native-masked-text": "^1.13.0",
"react-native-screens": "^2.3.0",
"react-native-splash-screen": "^3.2.0",
"react-native-touch-id": "^4.4.1",
"react-native-vector-icons": "^6.6.0",
"react-navigation": "^3.11.1",
"uninstall": "0.0.0"
},
yarn list --pattern "#react-native-firebase" results in
yarn list v1.22.4
├─ #react-native-firebase/analytics#6.7.2
├─ #react-native-firebase/app-types#6.7.1
├─ #react-native-firebase/app#6.7.1
└─ #react-native-firebase/iid#6.7.1
Done in 0.49s.
Following another questions similar to this problem gave me these options
rm -rf node_modules/
rm -rf yarn.lock
./gradlew clean
yarn react-native link react-native-firebase
yarn react-native start --reset-cache
tryng to sync the android project on android studio
IOS also having problems
following the iid instalation to react native from firebase
none worked, sadly
yarn react-native link react-native-firebase results in
$ /home/raiadrogasil.com/kamoraes/Workspace/ProjetosRd/univers-app-react/node_modules/.bin/react-native link react-native-firebase
warn The following packages use deprecated "rnpm" config that will stop working from next release:
- react-native-maps: https://npmjs.com/package/react-native-maps
Please notify their maintainers about it. You can find more details at https://github.com/react-native-community/cli/blob/master/docs/configuration.md#migration-guide.
error Unknown dependency. Make sure that the package you are trying to link is already installed in your "node_modules" and present in your "package.json" dependencies. Run CLI with --verbose flag for more details.
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.```
settings.gradle
rootProject.name = 'universAppReact'
include ':react-native-touch-id'
project(':react-native-touch-id').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-touch-id/android')
include ':react-native-gesture-handler'
project(':react-native-gesture-handler').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-gesture-handler/android')
apply from: file("../node_modules/#react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesSettingsGradle(settings)
include ':#react-native-firebase_app'
project(':#react-native-firebase_app').projectDir = new File(rootProject.projectDir, './../node_modules/#react-native-firebase/app/android')
include ':app'
build.gradle
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
ext {
buildToolsVersion = "28.0.3"
minSdkVersion = 16
compileSdkVersion = 28
targetSdkVersion = 28
supportLibVersion = "28.0.0"
}
repositories {
google()
jcenter()
}
dependencies {
classpath("com.android.tools.build:gradle:3.4.1")
classpath 'com.google.gms:google-services:4.3.1'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
mavenLocal()
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()
}
}
the project stopped working after we tried a new clone, of the project ro resolve some issues.
please if there are needed any more info, do tell me.
Try to play with version of package. In my case i cleared the up arrow before the version and it worked. Don't worry after all i revert changes and all good.
"#react-native-firebase/iid": "6.3.4", DOWNGRADING DID NOT HELP ( version bellow )
"#react-native-firebase/iid": "^6.3.4", DOWNGRADING DID NOT HELP ( version bellow )

Apps keeps stopping after linking realm to react native

Anyone facing the problem on the latest realm (2.25.0) with react native (0.59.0)?
There's no problem with when I link the realm to react-native. However, when I ran the 'react-native run-android' on a real device (currently I'm testing on two devices, Oneplus 5 - Android Pie & Oppo F1s - Android Lollipop), the bundling successful, but the apps never get started. I unlinked the realm from react-native, it returns me 'Missing Realm Constructor...' (which is in my expectation).
It does works on emulator without any problem, it only runs into a problem on real devices.
Below is my package.json
{
"name": "testing",
"version": "0.0.1",
"private": true,
"scripts": {
"start": "node node_modules/react-native/local-cli/cli.js start",
"test": "jest"
},
"dependencies": {
"react": "16.8.3",
"react-native": "0.59.0",
"realm": "^2.25.0"
},
"devDependencies": {
"#babel/core": "^7.3.4",
"#babel/runtime": "^7.3.4",
"babel-jest": "^24.5.0",
"jest": "^24.5.0",
"metro-react-native-babel-preset": "^0.53.0",
"react-test-renderer": "16.8.3"
},
"jest": {
"preset": "react-native"
}
}
Steps to reproduce:
react-native init testing
npm install --save realm
react-native link realm
react-native run-android
Does anyone have an idea on this issue?
Appreciate for your help.
try this:
go to build.gradle then
android {
...
defaultConfig {
...
and add this
ndk {
abiFilters 'armeabi-v7a', 'x86'
}
to default config. it must look like this :
defaultConfig {
...
ndk {
abiFilters 'armeabi-v7a', 'x86'
}
}

Warning after installing react-navigation in a react native project

I'm new to React Native. I'm learning navigation, so I started with a brand new react native project and followed the steps on the React Navigation website (react navigation doc) :
1) npm install --save react-navigation
2) npm install --save react-native-gesture-handler (not using expo)
3) react-native link react-native-gesture-handler
4) Modify the MainActivity.java as the website says for Android
Then, when I run the command react-native run-android, I see the app in my phone as expected but the following message appears:
Configure project :app
WARNING: Configuration 'compile' is obsolete and has been replaced with 'implementation' and 'api'.
It will be removed at the end of 2018. For more information see: http://d.android.com/r/tools/update-dependency-configurations.html
Task :react-native-gesture-handler:compileDebugJavaWithJavac
Note: /home/ana/code/react native/seeCompileError/node_modules/react-native-gesture-handler/android/src/main/java/com/swmansion/gesturehandler/react/RNGestureHandlerButtonViewManager.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: Some input files use unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
I'm on Linux Mint 19 running the code on my physical Android phone.
My build.gradle file:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
ext {
buildToolsVersion = "27.0.3"
minSdkVersion = 16
compileSdkVersion = 27
targetSdkVersion = 26
supportLibVersion = "27.1.1"
}
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.4'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
mavenLocal()
google()
jcenter()
maven {
// All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
url "$rootDir/../node_modules/react-native/android"
}
}
}
task wrapper(type: Wrapper) {
gradleVersion = '4.4'
distributionUrl = distributionUrl.replace("bin", "all")
}
My package.json file:
{
"name": "seeCompileError",
"version": "0.0.1",
"private": true,
"scripts": {
"start": "node node_modules/react-native/local-cli/cli.js start",
"test": "jest"
},
"dependencies": {
"jwt-decode": "^2.2.0",
"react": "16.6.3",
"react-native": "0.57.8",
"react-native-gesture-handler": "^1.0.12",
"react-navigation": "^3.0.9",
"react-redux": "^6.0.0",
"redux": "^4.0.1",
"redux-persist": "^5.10.0",
"redux-thunk": "^2.3.0"
},
"devDependencies": {
"babel-jest": "23.6.0",
"jest": "23.6.0",
"metro-react-native-babel-preset": "0.51.1",
"react-test-renderer": "16.6.3"
},
"jest": {
"preset": "react-native"
}
}
I would appreciate any hint or help, thank you.
Compile vs Implementation
When you use react-native link it adds the dependency to your build.gradle file; depending on how the dependency has been setup it adds it with compile or implementation. It's easy for you to fix, you can just manually change it to implementation
So in your build.gradle(Module: app) you can change
compile project(':react-native-gesture-handler')
to
implementation project(':react-native-gesture-handler')
You can read more about the differences between Compile and Implementation here: What's the difference between implementation and compile in Gradle?
react-native-gesture-handler
If react-native-gesture-handler is using or overriding deprecated APIs you could flag an issue on their repo, or fix it yourself by making a pull request.
Deprecated apis could be removed without warning making the dependency unusable/unstable. The deprecated apis could also have flaws in them, hence the reason they are deprecated, and these may cause you issues in the future.
But as you are require to use react-native-gesture-handler when using react-navigation you are a bit limited in what you can do.
As I have already said there are several options: flag the issue, fix it yourself with a pull-request, don't use it react-navigation until react-native-gesture-handler is fixed, or you can use it.

How to enable stacktrace react-native run-android command?

I'm running a react native project via the react-native run-android. But during the build it fails stating that :react-native-device-info:processReleaseResources FAILED. Which doesn't give much info, so I tried running with react-native run-android --stacktrace as suggested but that isn't a recognized command.
How can you enable stacktrace / verbose logging with react-native run-android command?
This is the detail of the error which is too short to figure out at build:
:react-native-device-info:processReleaseResources FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':react-native-device-info:processReleaseResources'.
> com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command 'C:\Users\Brian\AppData\Local\Android\sdk\build-tools\23.0.1\aapt.exe'' finished with non-zero exit value 1
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
BUILD FAILED
Total time: -12.542 secs
Package.json for reference:
{
"name": "StarterKit",
"version": "1.0.0",
"private": true,
"scripts": {
"start": "node node_modules/react-native/local-cli/cli.js start",
"test": "jest"
},
"jest": {
"preset": "react-native",
"setupFiles": [
"<rootDir>/jest.setup.js"
],
"transformIgnorePatterns": [
"node_modules/(?!react-native|tcomb-form-native|apsl-react-native-button,react-native-device-info|react-clone-referenced-element)"
],
"collectCoverage": true,
"verbose": true
},
"dependencies": {
"html-entities": "^1.2.0",
"jwt-decode": "^2.1.0",
"qs": "^6.3.0",
"react": "15.4.2",
"react-addons-shallow-compare": "^15.4.2",
"react-native": "^0.40.0",
"react-native-device-info": "^0.9.6",
"react-native-elements": "^0.9.2",
"react-native-google-analytics-bridge": "git+https://github.com/mcnamee/react-native-google-analytics-bridge.git",
"react-native-router-flux": "^3.37.0",
"react-native-side-menu": "^0.20.1",
"react-native-tab-view": "0.0.48",
"react-native-vector-icons": "^4.0.0",
"react-redux": "^5.0.1",
"redux": "^3.6.0",
"redux-logger": "^2.7.0",
"redux-thunk": "^2.1.0",
"striptags": "^2.1.1",
"tcomb-form-native": "^0.6.1"
},
"devDependencies": {
"babel-core": "^6.17.0",
"babel-eslint": "^7.1.0",
"babel-jest": "18.0.0",
"babel-preset-es2015": "^6.18.0",
"babel-preset-react-native": "1.9.1",
"babel-register": "^6.16.3",
"eslint": "^3.9.1",
"eslint-config-airbnb": "^14.0.0",
"eslint-plugin-import": "^2.2.0",
"eslint-plugin-jsx-a11y": "^3.0.2",
"eslint-plugin-react": "^6.4.1",
"invariant": "^2.2.2",
"jest": "18.1.0",
"jest-react-native": "^18.0.0",
"react-test-renderer": "15.4.2"
}
}
build.gradle file:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.1.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
mavenLocal()
jcenter()
maven {
// All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
url "$rootDir/../node_modules/react-native/android"
}
}
}
#EricHua23's answer is basically correct, except that instead of running ./gradlew assembleDebug --stacktrace, you should run ./gradlew.bat installDebug --stacktrace, as this is the command that's actually run by react-native run-android. (and some of the errors you'd want to get the stack-trace for only occur in the installing/late-build portion, rather than the assembly portion)
Also, make sure you run it in the android folder. (so run cd android in the console before running the gradlew command)
Try to build react-native-device-info separately with ./gradlew assembleDebug and make sure react-native-device-info is all right. I have the same problems because of my network which is blocked and can not reach jcenter.
By the way, --stacktrace should be add as gradle parameters, I doubt react-native does not pass it to gradle.
If running on Windows run following command in your project's root directory:
1. cd android
2. gradlew.bat installDebug --stacktrace
I use package.json file like this, for shortcut to shell commands, in my ViroMedia Sample App:
{
"name": "ViroSample",
"version": "0.0.1",
"private": true,
"scripts": {
"start": "node node_modules/react-native/local-cli/cli.js start",
"android": "react-native run-android --variant arrelease",
"and_bundle": "react-native bundle --platform android --dev false --entry-file index.js --bundle-output android/app/src/main/assets/index.android.bundle --assets-dest android/app/src/main/res",
"ios": "react-native run-ios",
"gradle_build": "cd android && ./gradlew --stacktrace --info assembleRelease -x bundleArReleaseJsAndAssets",
"gradle_install": "cd android && ./gradlew installArDebug --stacktrace --info",
"test": "jest"
},
"dependencies": {
"axios": "^0.19.0",
"expo": "^35.0.0",
"react": "16.8.3",
"react-native": "^0.61.5",
"react-viro": "2.15.0"
},
"devDependencies": {
"#babel/core": "^7.5.5",
"#babel/runtime": "^7.5.5",
"babel-jest": "^24.8.0",
"jest": "^24.8.0",
"metro-react-native-babel-preset": "^0.55.0",
"react-test-renderer": "16.8.3"
},
"jest": {
"preset": "react-native"
}
}
I issue the following command from my project root directory (iMac bash shell):
yarn gradle_install
Please see the script block above for other shell commands.
Note: in windows this is gradlew.bat.
Happy Coding :-)
From mac this will work
1. cd android
2. ./gradlew installDebug --stacktrace
Give a try to react-native start
This shows errors verbosely.

Categories

Resources