How to build debug apk in react native

14,457

Solution 1

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

Solution 2

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

Solution 3

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
Share:
14,457
Joe
Author by

Joe

Updated on June 05, 2022

Comments

  • Joe
    Joe almost 2 years

    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
    Joe about 6 years
    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\interm‌​ediates\assets\debug‌​\index.android.bundl‌​e' "
  • Haswin
    Haswin about 6 years
    @Joe I updated my answer. replace your entry file name with <your-entry-file>
  • Joe
    Joe about 6 years
    showing the same error. " ENOENT: no such file or directory, open 'D:\workspace\reactjs\native\myapp5\android\app\build\interm‌​ediates\assets\debug‌​\index.android.bundl‌​e"
  • Haswin
    Haswin about 6 years
    @Joe can you post the output of cd android && ./gradlew assembleDebug
  • Joe
    Joe about 6 years
    The output is " The system cannot find the path specified. "
  • Haswin
    Haswin about 6 years
    if you are using windows it's cd android && gradlew assembleDebug
  • Haswin
    Haswin about 6 years
    you just have to go to the android folder and run gradlew assembleDebug on a terminal. post a screenshot if you get a error
  • Joe
    Joe about 6 years
    Thanks @HDevan i understand. But when running gradlew assembleDebug. it showing a error i have posted the screenshot below question.
  • Haswin
    Haswin about 6 years
    As per the screenshot It seems like the package "lottie-react-native" is causing the failure. Anyhow I believe you resolved the issue.
  • Haswin
    Haswin about 6 years
    @Joe if it did solve the issue please mark as answer.
  • Joe
    Joe about 6 years
    I am not solve the issue. How to solve the error that shown on screen shot
  • Haswin
    Haswin about 6 years
    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.
  • Shahid Iqbal
    Shahid Iqbal almost 5 years
    This is the correct solution latest react native SDK. Worked well on 0.55.9