I'm working on a Project in ReactNative & it's working fine in debug build (When installing via react-native run-android but When I generate a release build it crashes as soon as I open it, according to logs it's unable to load script, and android/app/src/main/assets directory is empty.
To resolve this I had to run these commands:
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
rm -rf ./android/app/src/main/res/drawable-*
But now the file index.android.js won't update in a release build, so I have to run the above commands every time I need a release build, what am I doing wrong?
Here are my packages.json details:
"scripts": {
"start": "node node_modules/react-native/local-cli/cli.js start",
"test": "jest"
},
"react": "16.8.3",
"react-native": "0.59.5"
In short: How to create or update index.android.bundle automatically when I generate a release build?
for react-native 0.70.6:
make sure you have com.android.tools.build:gradle:7.2.2 in your android/build.gradle and not com.android.tools.build:gradle:7.3.1
Follow the procedure first time.
mkdir android/app/src/main/assets
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
npm start -- --reset-cache
react-native run-android
if you want to take an apk file
cd android && ./gradlew clean
finally
./gradlew assembleRelease
Basically The below commands worked for me
cd android
./gradlew clean
./gradlew assembleRelease
Related
I am trying to generate a new apk and I get a very old apk when I run
./gradlew assembleRelease
I am using react native above 0.63.
I tried to remove the build folder and remove caches and it still produces the old apk.
so my question is why does it produce the old apk? and how to get the new apk?
Delete files inside directory android/app/src/main/assets.
run $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
try with:
rm -rf android/app/build
rm -rf android/build
cd android
./gradlew clean
cd ..
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
cd android
./gradlew assembleRelease
this should clean the build folder and create a new index.android.bundle with all the updates
Try this:
cd android
./gradlew clean
./gradlew assembleRelease
cd ..
Android Studio is generating very old apk for react-native project like 3 months old. But running perfectly in emulator while running this command "react-native run-android"
Process -
* Open file location
* Build => Build Bundles => Build APK
Tried re-installing android studio but still getting old APK
In the old react-native version, when we generate the android APK, sometimes the bundle is old, we have to generate it by ourself.
In the react-native 0.61, I find the problem is dismissed.
In the old version, firstly you should add the following script to the package.json
"scripts":{
...
"bundle-android": "react-native bundle --entry-file index.js --platform android --dev false --bundle-output ./android/app/src/main/assets/index.android.bundle --assets-dest ./android/app/src/main/res",
...
}
the when you generate the apk , you firstly run the follwing script in the termail to generate the new bundle
npm run bundle-android
when the bundle outputs successfully, then go into the android directory and assemble the APK
cd android
./gradlew assembleRelease
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 get an error of duplicate resources than go to res folder and delete the drawable-hdpi,drawable-mdpi,drawable-xhdpi,drawable-xxhdpi,drawable-xxxhdpi folder only and try to rebuild the project. It will work.
It is because, you have old index.android.bundle file. Follow these steps to update this file and create a new apk:
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
curl "http://localhost:8081/index.bundle?platform=android" -o "android/app/src/main/assets/index.android.bundle"
cd android && ./gradlew clean assembleDebug
I want to build unsigned apk or debug apk. My application is successfully running on localhost. I have tried different methods. But it shows the error. I have got the answer from Here . when applying the command
react-native bundle --dev false --platform android --entry-file index.android.js --bundle-output ./android/app/build/intermediates/assets/debug/index.android.bundle --assets-dest ./android/app/build/intermediates/res/merged/debug
It showing the error is
Cannot find entry file index.android.js in any of the roots: ["D:\\workspace\\reactjs\\native\\myapp5"]
Then i have change index.android.js to App.js
Then it will showing the error is
ENOENT: no such file or directory, open 'D:\workspace\reactjs\native\myapp5\android\app\build\intermediates\assets\debug\index.android.bundle'
How to solve this problem? Please help me.
My react native versions are react-native-cli: 2.0.1 , react-native: 0.52.0 . Screenshot of my root folder i have posted.
when i run gradlew assembleDebug in android folder it showing the error.
In your root project directory
Make sure if you have already directory android/app/src/main/assets/ if not there create directory after that create new file and save as index.android.bundle and put your file in like this android/app/src/main/assets/index.android.bundle
After run this in cmd
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/
cd android && ./gradlew assembleDebug
then you can get apk app/build/outputs/apk/debug/app-debug.apk
The problem here is that you do not seem to have the entry file you have specified for react native bundle:
index.android.js
Replace it with your project's entry file index.js or app.js according to your project structure.
Update:
react-native bundle --dev false --platform android --entry-file <your-entry-file> --bundle-output ./android/app/build/intermediates/assets/debug/index.android.bundle --assets-dest ./android/app/build/intermediates/res/merged/debug
Create debug build:
cd android && ./gradlew assembleDebug
Your apk will be at android/app/build/outputs/apk
In the root folder of your project, run the following command:
For RN Old Version:
mkdir -p android/app/src/main/assets && rm -rf android/app/build &&
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
&& cd android && ./gradlew clean assembleDebug && cd ../
For RN New Version:
mkdir -p android/app/src/main/assets && rm -rf android/app/build &&
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 &&
cd android && ./gradlew clean assembleDebug && cd ../
The apk is generated in following folder:
app/build/outputs/apk/debug/app-debug.apk
And if you want to run the apk on simulator. Run the following command:
react-native run-android --variant=debug
This will work..
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/
cd android && ./gradlew assembleDebug
I'm new in react-native.
I have run react native project on Ubuntu by using 'react-native run-android' command. And I got the error on emulator
"Unable to load script from assets 'index.android.bundle'.Make sure your bundle is packaged correctly or you are running a package server."
I also got this and I resolved this using following commands in your project directory:
$ mkdir android/app/src/main/assets
$ 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
$ react-native run-android
Using
npm version 4.3.0
react-native-cli version 2.01
react-native version 0.49.5
In project directory,
mkdir android/app/src/main/assets
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
The file name has changed from index.android.js to index.js
In my case (embedding React Native as a new Activity into an existing Android Code Base), the problem was Android Studio had auto-imported the wrong BuildConfig.
Wrong:
import com.facebook.react.BuildConfig;
Right:
import com.mywebdomain.myapp.BuildConfig;
This would apply to the wherever you are housing this block of code:
mReactRootView = new ReactRootView(this);
mReactInstanceManager = ReactInstanceManager.builder()
.setApplication(getApplication())
.setBundleAssetName("index.android.bundle")
.setJSMainModulePath("index")
.addPackage(new MainReactPackage())
.setUseDeveloperSupport(BuildConfig.DEBUG)
.setInitialLifecycleState(LifecycleState.RESUMED)
.build();
For this error :
unable to load script from assets 'index.android.bundle'
1) Check for "assets" folder at :
mkdir android\app\src\main\assets
If the folder is not available, create a folder with name "assets" manually. and execute the Curl command in terminal.
2). Curl command:
curl "http://localhost:8081/index.android.bundle?platform=android" -o"android/app/src/main/assets/index.android.bundle"
It will create the "index.android.bundle" file in assets folder automatically and resolved the issue.
3) Then:
react-native run-android
This helped me resolve the problem in following steps.
If not than (in project directory) mkdir android/app/src/main/assets
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
react-native run-android
Ubuntu
first time, I created new app with react-native init project-name. I got the same error. so i do the following steps to resolve this in my case.
Firstly run sudo chown user-name-of-pc /dev/kvm in my case.
While debugging from your Android phone, select Use USB to Transfer photos (PTP).
Create Folder assets in 'project-name/android/app/src/main'.
make sure index.js be avaiable into your project root directory and then run below command from console after cd project-name directory.
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
or for index.android.js then
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
run command ./studio.sh in android-studio/bin directory. It will opens up Android Studio.
run command react-native run-android.
It seems to be a problem in the newest version of React Native (0.46). Using the previous version seems to solve the problem react-native init name --version react-native#0.45.1 and removes the error when running react-native run-android.
Edit: It is now fixed in version 0.46.1.
In my case the problem was in this row in the React Activity file:
mReactInstanceManager = ReactInstanceManager.builder()
...
.setUseDeveloperSupport(BuildConfig.DEBUG)
...
BuildConfig.DEBUG must be set to true, while in my case it was false
For Windows user only:
Copy the path of adb location and set into PATH in your system variable,
Open project structure and delete node module folder.
Edit your project package.JSON file
change react-native version "react-native": "0.55.2", and
babel "babel-preset-react-native": "4", after that run npm install
Restart cmd and js server and run your react native project by react-native run-android
I was stuck in the same problem for hours and what solved my issue is this :
Create "assets" folder in main directory of project as well as in "newreactproject\android\app\src\main". Then put this script in package.json "android-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"
like:
"name": "newreactproject",
"version": "0.0.1",
"private": true,
"scripts": {
"android-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",
"start": "node node_modules/react-native/local-cli/cli.js start",
"test": "jest"
}
I discovered a solution suggested in the thread at https://github.com/facebook/react-native/issues/15388
It is to manually set the Debug server host & port for device setting for the app on the phone.
Step by Step to eject and run a CRNA on Android
In terminal:
create-react-native-app myApp
cd myApp
yarn run eject (I used default options "regular React Native project")
react-native run-android
(now the app should be compiled and installed on the phone)
On phone:
Run the app (expect to see the red error screen! - click Dismiss button in bottom left)
Shake the phone and pick Dev Settings
Pick Debug server host & port for device and set to 192.168.x.x:8081 (make it your actual LAN IP of course)
Restart app on phone and you should see green bar at the top "Loading from 192.168.x.x:8081..."
You should also see some "Bundling index.js" action in the Metro Bundler (that opened when running react-native run-android)
After the bundle is finished, the app should be running on your Android device!
Live Reload (when source files change) also works - just shake the phone and touch "Enable Live Reload"
You can run the project from Android Studio, but you need to first start the Metro Bundler with the command react-native start in the CRNA project root.
I was getting this error too. But adb reverseworked for me
i'm using ubuntu 18.04 LTS ,react-native: 0.55.2. In my case here are few solutions for the problem .
in the terminal before you run npm run android type npm start. you might see an error
ERROR Metro Bundler can't listen on port 8081.
this occurs because there might be a process which is already running
Solution- type sudo lsof -i :8081
you will see an output similar to this
**COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
node 5670 tasif 17u IPv6 80997 0t0 TCP *:tproxy (LISTEN)**
type kill -9 (PID number)then run npm android.
if it still doesnt work type again npm start . you might see this error
ERROR ENOSPC: no space left on device, watch'....../......./.....'
solution :
$ sudo sysctl fs.inotify.max_user_watches=524288
$ sudo sysctl -p
then type npm run android.
please go to this link to see different solutions and more details https://github.com/guard/listen/wiki/Increasing-the-amount-of-inotify-watchers#the-technical-details
delete the emulator and build it again. kill the recent terminal and then build emulator and start again.
I have used following command to run but index.android.bundle not getting.
react-native run-android
react-native start
http://localhost:8081/index.android.bundle?platform=android&dev=true&hot=true&minify=false
This is not giving me the package bundle js what to do. and It's been a couple of days i stock in this problem i could not get help.
Below is the screencast of my code:
Thanks in Advance!
Your screenshot starting the server for react native debug.
The app in the debug mode will point to this server js then you can change your code for debug easily.
If you want to package the bundle file you can use these commands:
Android:
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/
IOS:
react-native bundle --platform ios --dev false --assets-dest ./ios --entry-file index.ios.js --bundle-output ios/main.jsbundle
Got Solution For me:
Go to your project directory and check if this folder exists android/app/src/main/assets
i) If it exists then delete two files viz index.android.bundle and index.android.bundle.meta
ii) If the folder assets doesn’t exist then create the assets directory there.
From your root project directory do
cd android
./gradlew clean
Finally, navigate back to the root directory and check
i) If there is only one file i.e. index.js then 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
NOTE: That is one single command.
ii) If there are two files i.e index.android.js and index.ios.js then run this:
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
This is a single command too!
Now run react-native run-android
Found Solution from this url, Click here to Check
I have just found why my react-native application is not building bundle js because of watchman and after uninstall previous watchman and installing new watchman.It working correctly thanks. Using Following Code.
$ git clone https://github.com/facebook/watchman.git
$ cd watchman/
$ git checkout v4.7.0
$ sudo apt-get install -y autoconf automake build-essential python-dev
$ ./autogen.sh
$ ./configure
$ make
$ sudo make install
$ watchman --version
$ echo 999999 | sudo tee -a /proc/sys/fs/inotify/max_user_watches && echo 999999 | sudo tee -a /proc/sys/fs/inotify/max_queued_events && echo 999999 | sudo tee -a /proc/sys/fs/inotify/max_user_instances && watchman shutdown-server