DEV Community

nitish
nitish

Posted on

How to generate a debug apk in react-native

What is an .apk file?

An Android Package Kit (APK) is the package file format used by the Android OS for distribution and installation of mobile apps. It is similar to the .exe file you have on Windows OS, a .apk file is for android.

What can I use it for?

A debug .apk file will allow you to install and test your app before publishing to app stores. Mind you, this is not yet ready for publishing, and there are quite a few things you'll need to do to before you can publish. Nevertheless, it'll be useful for initial distribution and testing.

You'll need to enable debugging options on your phone to run this apk.

Prerequisite:

  • react-native version > 0.57

How to generate one in 3 steps?

Step 1: Go to the root of the project in the terminal and run the below 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

Step 2: Go to android directory:

cd android

Step 3: Now in this android folder, run this command

./gradlew assembleDebug

There! you'll find the apk file in the following path:
yourProject/android/app/build/outputs/apk/debug/app-debug.apk

Now you have your .apk file generated, install it on your android phone and enjoy!

Thank you.

Top comments (18)

Collapse
 
impdp profile image
Pradeep Annadurai

And if you build frequently, you can make the shortcut for bundle command in the scripts of Package.json

"bundle-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"

and in the terminal use:
npm run bundle-android

Collapse
 
nickap profile image
nickap • Edited

This might be because the files monitored by the system have reached the limit!

You can increase the number of the files like this:

sudo gedit /etc/sysctl.conf
fs.inotify.max_user_watches=524288
You might want to check:
sudo sysctl -p

Collapse
 
abhiram_saiganeshvarrey profile image
ABHIRAM SAI GANESH VARREY

D:\myprojecct\B2B3\mobileapp\android> ./gradlew assembledebug
gradlew : The term 'gradlew' is not recognized as the name of a
cmdlet, function, script file, or operable program. Check the

spelling of the name, or if a path was included, verify that the

path is correct and try again.
At line:1 char:1

  • gradlew assembledebug + ~~~~~~~
    • CategoryInfo : ObjectNotFound: (gradlew:String) [ ], CommandNotFoundException
    • FullyQualifiedErrorId : CommandNotFoundException

GETTING THIS ERROR EVERYTIME

Collapse
 
edufrazao profile image
Eduardo Frazão

Hi. Its possible to link a local debugger to this "self-contained bundled" APK, in order to get errors or warnings, or even "console.log/warn" outputs?

I have a APP where part of the developers feeds the application with dynamic code (views and business rules with javascript), that are parsed at runtime.
This developers don't need the entire application project + development server in order to do their work. If they can only get this errors/warnings in some attached debugger, it will be nice!

Collapse
 
gautham495 profile image
Gautham Vijayan

I did what the documentation said and got aab. With this post I got an apk thank you!!!

Collapse
 
zanottaa profile image
Rodrigo

worked like a charm, thank you my friend.

Collapse
 
noursaloom profile image
Nour

thx a lot
but be careful guys
u should use npx before first command

Collapse
 
paulhoriachiy profile image
Paul Horiachiy

Thanks, it works!

Collapse
 
kaulsalil88 profile image
Salil Kaul

Just a heads in case you get an error that error ENOENT: no such file or directory, open 'android/app/src/main/assets/index.android.bundle'. Please create the same using mkdir -p android/app/src/main/assets . Source : stackoverflow.com/questions/494423...

Collapse
 
joweltisso profile image
Jowel Tisso

Great Thanks... Helped me alot..