skip to Main Content

I have created a new project using react native version "0.71.2" . In APK the assets are not bundling and there is no option of bundleInDebug in Build.gradle

expecting to generate the build APK with bundling js and assets

2

Answers


  1. Build Debug with assets:

    You can build a debug version using this steps:

    1. Create an assets directory using (One Time Step)
    mkdir ./android/app/src/main/assets/
    
    1. create a blank file with the name index.android (One Time Step)
    touch ./android/app/src/main/assets/index.android
    
    1. bundle the app using
    react-native bundle --dev false --platform android --entry-file index.js --bundle-output ./android/app/src/main/assets/index.android --assets-dest ./android/app/src/main/res/
    react_native_generate_debug_apk1
    

    or

    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
    
    1. Build the debug APK using
    cd android/ 
    ./gradlew assembleDebug
    

    Build Release with assets:

    And you can build a release version which is much easier using this command:

    cd android
    ./gradlew assembleRelease
    
    Login or Signup to reply.
  2. This is what ultimately worked for me after some trial and error.

    Note: I’m running this in GitHub Actions which is why I am using npx but if running locally and you have the React Native CLI installed you don’t need the npx in step 3.

    1. Create assets directory:
    mkdir ./android/app/src/main/assets/
    
    1. Create bundle output file (I tried with just index.android first and it didn’t work)
    touch ./android/app/src/main/assets/index.android.bundle
    
    1. Bundle app
    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
    
    1. Create Android debug build
    cd android && ./gradlew assembleDebug
    

    I did these steps in GitHub Actions and was able to run the output .apk on an Android Emulator. Hope that helps!

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search