Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to build debug apk in react native

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

like image 423
Joe Avatar asked Mar 23 '18 04:03

Joe


2 Answers

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

like image 163
Jeeva Avatar answered Sep 22 '22 10:09

Jeeva


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

like image 23
Haswin Avatar answered Sep 23 '22 10:09

Haswin