57

I am using React native 0.52.0 and react-native-cli 2.0.1 on my Windows PC for android development. Despite all the changes i have made. When I run react-native run-android, it builds successfully but when I run it, I get the default react native screen.

The result when I run react-native run-android- enter image description here

The app I get-

enter image description here

index.js

import { AppRegistry } from 'react-native';
import App from './App';

AppRegistry.registerComponent('albums', () => App);

app.js

import React from 'react'
import ReactNative, { Text } from 'react-native'

export default const App = () => {
  return (
    <Text>Hello World</Text>
  )
}

When i ran react-native init albums, it was just an index.js file that was created, there was no index.android.js or index.ios.js file What am I doing wrong?

  • [How to create a Minimal, Complete, and Verifiable example](https://stackoverflow.com/help/mcve) – Nissim R Jan 17 '18 at 15:11
  • I think you need to study it. https://stackoverflow.com/questions/36933287/how-to-enable-live-reload-in-react-native-on-android/42571633 – Muhammad Ali Mar 07 '19 at 16:36

24 Answers24

61

Assuming that you are in the right folder, try to do this:

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/

if you have index.android.js, do this instead:

react-native bundle --platform android --dev false --entry-file index.android.js --bundle-output android/app/src/main/assets/index.android.bundle --assets-dest android/app/src/main/res/

Then just execute react-native run-android.

SmoggeR_js
  • 2,950
  • 4
  • 22
  • 52
  • I did as you said, this is the error message i got FAILURE: Build failed with an exception. * What went wrong: A problem occurred configuring root project 'albums'. > Could not resolve all files for configuration ':classpath'. > Could not find com.android.tools.build:gradle:3.0.1. Searched in the following locations: https://jcenter.bintray.com/com/android/tools/build/gradle/3.0.1/gradle -3.0.1.pom https://jcenter.bintray.com/com/android/tools/build/gradle/3.0.1/gradle -3.0.1.jar Required by: project : – Jonathan Utsu Undelikwo Jan 17 '18 at 23:19
  • After running, the first line of code you said, my Build is failing – Jonathan Utsu Undelikwo Jan 17 '18 at 23:39
  • Ensure that the paths are in the command are the same as you have in the project. – SmoggeR_js Jan 18 '18 at 08:16
  • No, you shouldn't. – SmoggeR_js Jan 17 '19 at 11:25
  • It seems I must use from `sudo ` in ubuntu – Saeed Jun 12 '19 at 07:08
  • It's strange that you should to use sudo but, I own a react native project that don't let me modify Android Manifest unless I would open with sudo mode and I still don't know why xD – SmoggeR_js Jun 12 '19 at 07:24
  • 4
    In my case, it needs to run everytime. Anyone has solution? – Bhavesh Hirpara Aug 26 '19 at 07:44
  • Why is this necessary? – d512 Apr 26 '22 at 19:36
  • Any permanent solution for this? If anyone has found one. please let me know. It would be very much appreciated – Hashir Saeed Oct 03 '22 at 20:14
36

SOLUTION

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

OUTPUT will be :

`c:\Users\lenger\Desktop\webrowser>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
Scanning folders for symlinks in c:\Users\lenger\Desktop\webrowser\node_modules (43ms)
Scanning folders for symlinks in c:\Users\lenger\Desktop\webrowser\node_modules (38ms)
Loading dependency graph, done.
bundle: start
bundle: finish
bundle: Writing bundle output to: android/app/src/main/assets/index.android.bundle
bundle: Done writing bundle output

and after

Run react-native run-android again, you will find your modification work.

https://lengerrong.blogspot.am/2018/01/react-native-run-android-do-not.html

ravibagul91
  • 20,072
  • 5
  • 36
  • 59
Rob
  • 886
  • 9
  • 16
5

This worked for me. Step 1)

rm -rf /usr/local/var/run/watchman && brew uninstall watchman && brew install watchman

Step2)

react-native start
Nick
  • 138,499
  • 22
  • 57
  • 95
user2436649
  • 51
  • 2
  • 2
  • I got the error message after first command. [watchman] while computing sockname: failed to create /usr/local/var/run/watchman/USERNAME-state: No such file or directory – s_signal Oct 18 '22 at 17:12
  • I got the answer from the link. https://github.com/facebook/watchman/issues/760 \n sudo mkdir -p /usr/local/var/run/watchman \n sudo chmod 2777 /usr/local/var/run/watchman – s_signal Oct 18 '22 at 23:41
5

Open package.json file and update this code.

"scripts": {
"android": "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 && react-native run-android",
"ios": "react-native run-ios"
},

Assuming that you are in the right folder, try to do this:

Run this command only it will automatically both commands.

npm run android

Er Pkumar soni
  • 152
  • 1
  • 7
4

in your terminal window go to your project folder and than try this command

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/
Ankit Sharma
  • 251
  • 2
  • 9
4

This comment on github fixed my problem.

@neonsec Cool, it do works !

and I find a reason why this happened

https://github.com/facebook/watchman/blob/4b98623e8fde17588f27494f3ae8f084b9b227d3/QueryableView.cpp#L48

it looks like when a .git/index.lock or a .hg/wlock file exist, watchman will do nothing

Solution: DELETE .git/index.lock file

## root app dir
rm -f .git/index.lock

otherlink: https://github.com/facebook/watchman/blob/4b98623e8fde17588f27494f3ae8f084b9b227d3/QueryableView.cpp#L48

MernXL
  • 316
  • 2
  • 6
3

You are probably updating the wrong file and not calling it in the AppRegistry class.

Check (or post) your full index.android.js and make sure that the file that it is invoking and importing is the one you are actually modifying.

sebastianf182
  • 9,844
  • 3
  • 34
  • 66
3

Run the script:

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

After that, just do:

$ gradlew clean
$ react-native link
Eugene Gr. Philippov
  • 1,908
  • 2
  • 23
  • 18
Asma_Kh
  • 93
  • 2
  • 15
2

This worked for me:

In your project folder run this

c:\Users\lenger\Desktop\YourProjectFolder>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

Scanning folders for symlinks in c:

\Users\lenger\Desktop\webrowser\node_modules (43ms)
Scanning folders for symlinks in c:\Users\lenger\Desktop\webrowser\node_modules (38ms)
Loading dependency graph, done.
bundle: start
bundle: finish
bundle: Writing bundle output to: android/app/src/main/assets/index.android.bundle
bundle: Done writing bundle output

Run react-native run-android again

I share the link where i found this solution: https://lengerrong.blogspot.com/2018/01/react-native-run-android-do-not.html

Inder
  • 3,711
  • 9
  • 27
  • 42
lisandro
  • 21
  • 1
2

For CodePush users

I was having this same problem but it didn't update my code just on a production build, it works fine in development.

My problem was CodePush, it was updating my app because it had the same version than the last CodePush release target version and it was a mandatory update (I didn't change the version target because it was just for testing purpose), then, I commented the CodePush code on my App.js and it works perfectly.

Jean Lambert
  • 131
  • 2
  • 10
2

After trying @SmoggeR_js answer and still if you have the same problem try following (Assuming that you have created keys and already signed the apk)

  1. Delete build inside android/app folder
  2. Delete build inside android folder
  3. run rm -rf $HOME/.gradle/caches/ to delete cache
  4. Open build.gradle --> android/app/build.gradle
  5. comment out this line apply from: "../../node_modules/react-native/react.gradle"
  6. Delete index.android.bundle file from assets folder ( android/app/src/main/assets/index.android.bundle)
  7. run following command 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
  8. react-native run-android --variant=release (you have to generate signed keys and all the keys should updated in the gradle file ref (https://s-pace.github.io/react-native/docs/signed-apk-android.html)
noone
  • 6,168
  • 2
  • 42
  • 51
1

In my case, deleting below line in gradle.properties solved it.

org.gradle.configureondemand = true

kimho
  • 11
  • 1
  • 2
1

For me the problem was that I had removed internet permissions from my AndroidManifest.xml (since it technically wasn't needed). React Native uses that permission to connect your app to the development machine (and enable live-debugging).

<uses-permission android:name="android.permission.INTERNET" />
Karl Penzhorn
  • 375
  • 1
  • 3
  • 12
1

Open your Android Studio -> "Tools" menu -> "AVD manager" and right click the emulator you are using, choose "Wipe Data" then "Cold Boot Now" should solve the problem.

enter image description here

J.Q
  • 669
  • 1
  • 6
  • 6
1

If you are using index.android.js then follow the following steps:

Delete index.android.bundle within android/app/src/main/assets and then -

  1. react-native bundle --platform android --dev false --entry-file index.android.js --bundle-output android/app/src/main/assets/index.android.bundle --assets-dest android/app/src/main/res/

  2. cd ./android

  3. ./gradlew assembleRelease -x bundleReleaseJsAndAssets

1

Fix it in 3 steps:

  1. Enable Live Reload
  2. Disable Hot Reloading
  3. In Dev Settings, uncheck JS Dev Mode

Now your app automatically updating everytime you made changes to your codes.

Engkus Kusnadi
  • 2,386
  • 2
  • 18
  • 40
  • I thought it was a bug and forget that you need to re-enable the live reload and hot reload every time you clone it onto a new system – GTHell Oct 05 '19 at 03:56
1

Try this

cd .git (in your react-native folder)
rm index.lock

and restart metro bundler i.e. react-native start

wallaa!!...

CKE
  • 1,533
  • 19
  • 18
  • 29
Rahul Shakya
  • 1,269
  • 15
  • 15
0

In your project directory, there is package.json file. You can add following code snippet in that json file under scripts:. After that you can run application using one command that is npm run android-windows. To work fine you should add below code script.

"android-windows": "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 && react-native run-android"

enter image description here

0

there was no index.android.js or index.ios.js file

In this case you have to follow the instructions on your mobile/emulator as below:

enter image description here

After saved your App.js, remember to type twice R in uppercase

For make it automatically changes, on Android emulator press CTRL + M (CMD + M on MacOS) or shake the Android device which has the running app and select Hot reloading (keep current state, change only the file you have changed) or Live reloading (reload the entire app).

NineCattoRules
  • 2,253
  • 6
  • 39
  • 84
0

Silly mistake by me that not to save edits of App.js. After Saving data will reflect :)

Shweta Shah
  • 97
  • 2
  • 6
0

In my case when I disable debugging then it updates. So this is my solution.

in Chrome dev tools > Network > Disable cache Hope that shell work for you

Shubham Sharma
  • 479
  • 4
  • 8
0

In case you are using "codepush".

I tried for two hours now to figure out why my Android version is always rolling back to the old code and doesn't show the new features.

The reason was an old CodePush which leads to downgrading the app.

Lucas0205
  • 55
  • 1
  • 6
0

Try deleting the

  • ./android/.idea folders.
  • ./android/.gradle folders.

It works for me

enter image description here

Trần Hiệp
  • 101
  • 1
  • 2
-1

In my case my code was not autosaving so it needed to CTRL + S first before reloading. To solve this I just set autosaving on VS Code. Note: This was because I had just reinstalled VS Code and might not be the case for everyone

Judefabi
  • 29
  • 3