Search code examples
androidreact-nativeapk

How to generate an apk that works without dev server in react native


I'm developing an android application with react-native (0.59), and I want to test it on different devices. My goal is to create an .apk file that can be installed by simply transferring the file, without any requirement for development server running, usb cables, etc..

I have looked at different reply on previous questions about the subject but so far nothing as worked.

This reply still needs a dev-server to run: How to generate dev APK file without asking for dev settings server ip in react native

This reply generate an apk that won't install on the device with the error "app not installed": Build and Install unsigned apk on device without the development server?

I have tried the publish method from the react-native docs (ref: https://facebook.github.io/react-native/docs/signed-apk-android), I generated the .aab file, then I use bundletools to convert it with apks, as explained here: Generate Apk file from aab file (android app bundle) in this answer:

So far nobody has provided the solution to get the APK from an AAB.

This solution will generate a universal binary as an apk.

Add --mode=universal to your bundletool command (if you need a signed app, use the --ks parameters as required).

bundletool build-apks --bundle=/MyApp/my_app.aab --output=/MyApp/my_app.apks --mode=universal Change the output file name from .apks to .zip

Unzip and explore

The file universal.apk is your app

This universal binary will likely be quite big but is a great solution for sending to the QA department or distributing the App anywhere other than the Google Play store.

But unfortunately in my case, when I open the .zip file, there's no file called universal.apk:

enter image description here

All the .apk are pretty small in size (around 10mb, while the .aab file is 300).

Is there any other solution?


Solution

  • After you go through https://facebook.github.io/react-native/docs/signed-apk-android you can simply run

    // for build and run
    react-native run-android --variant=release
    

    and take apk in

    <rn_project_dir>/android/app/build/outputs/apk/release/app-release.apk