📜  export aab bundle react native android - Javascript(1)

📅  最后修改于: 2023-12-03 14:41:04.288000             🧑  作者: Mango

Export AAB Bundle for React Native Android - Javascript

Overview

In this guide, we will learn how to export an AAB (Android App Bundle) for a React Native Android project. An Android App Bundle is a publishing format that includes all the compiled code and resources required to build and run an app. Exporting an AAB allows developers to optimize their app's size and deliver a more efficient release to users.

Prerequisites

Before proceeding, make sure you have the following installed on your system:

  • Node.js
  • React Native CLI
  • Android Studio
  • Java Development Kit (JDK)
  • Android SDK
Steps
  1. Configure the build.gradle file: Open the android/app/build.gradle file in your React Native project. Locate the defaultConfig section and add the following line to enable AAB export:

    bundle {
        language {
            enableSplit = false
        }
        density {
            enableSplit = true
        }
    }
    
  2. Generate the AAB bundle: Open a terminal, navigate to the root directory of your React Native project, and run the following command:

    npx 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
    

    This command will generate a bundle file index.android.bundle and copy all the required assets to the appropriate location.

  3. Build the release bundle: In the terminal, run the following command to generate the AAB:

    cd android && ./gradlew bundleRelease
    

    This command will build the release bundle and store it in the android/app/build/outputs/bundle/release directory.

  4. Locate the AAB file: Once the build process is complete, navigate to the android/app/build/outputs/bundle/release directory. You will find the generated AAB file, usually named app.aab.

Congratulations! You have successfully generated an AAB bundle for your React Native Android project. This AAB can now be submitted to the Google Play Store or be further optimized using Play Store's features like app signing and dynamic delivery.

Note: It is recommended to thoroughly test the generated AAB on various devices before distribution to ensure compatibility and functionality.

For more detailed information about Android App Bundle, refer to the official Android Developer Documentation.