6

enter image description hereI 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.

enter image description here

Joe
  • 246
  • 1
  • 3
  • 15

4 Answers4

19

In your root project directory

Ensure you already have a directory android/app/src/main/assets/. If not already there, create a directory.

After that create a new file and save it as index.android.bundle and put your file in like this android/app/src/main/assets/index.android.bundle

After that has been done, run the 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/

and finally, run the following command.

cd android && ./gradlew assembleDebug

then you can get apk app/build/outputs/apk/debug/app-debug.apk

Kishor Pawar
  • 3,386
  • 3
  • 28
  • 61
Jeeva
  • 1,707
  • 1
  • 10
  • 7
4

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

Haswin
  • 697
  • 8
  • 20
  • I have used app.js. Then it shows the error is " ENOENT: no such file or directory, open 'D:\workspace\reactjs\native\myapp5\android\app\build\intermediates\assets\debug\index.android.bundle' " – Joe Mar 23 '18 at 06:37
  • @Joe I updated my answer. replace your entry file name with – Haswin Mar 23 '18 at 08:19
  • showing the same error. " ENOENT: no such file or directory, open 'D:\workspace\reactjs\native\myapp5\android\app\build\intermediates\assets\debug\index.android.bundle" – Joe Mar 23 '18 at 08:42
  • @Joe can you post the output of cd android && ./gradlew assembleDebug – Haswin Mar 23 '18 at 09:11
  • The output is " The system cannot find the path specified. " – Joe Mar 23 '18 at 10:41
  • if you are using windows it's cd android && gradlew assembleDebug – Haswin Mar 24 '18 at 10:23
  • you just have to go to the android folder and run gradlew assembleDebug on a terminal. post a screenshot if you get a error – Haswin Mar 24 '18 at 10:24
  • Thanks @HDevan i understand. But when running gradlew assembleDebug. it showing a error i have posted the screenshot below question. – Joe Mar 26 '18 at 04:14
  • As per the screenshot It seems like the package "lottie-react-native" is causing the failure. Anyhow I believe you resolved the issue. – Haswin Mar 26 '18 at 16:55
  • @Joe if it did solve the issue please mark as answer. – Haswin Mar 27 '18 at 05:49
  • I am not solve the issue. How to solve the error that shown on screen shot – Joe Mar 27 '18 at 06:54
  • As I said the issue seems to be on using lottie-react-native package. Remove any usage of that package and see if the app builds then. – Haswin Mar 27 '18 at 13:15
2

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
Waqar UlHaq
  • 6,144
  • 2
  • 34
  • 42
2

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
nafees ahmed
  • 948
  • 1
  • 12
  • 18