Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to build android apk from my react-native project?

How to build android apk from my react-native project? This command "react-native run-android" create app-debug.apk on folder android\app\build\outputs\apk\ But when I installed it on my phone, I got an error "Unable to download JS bundle". When I started on emulator first time I use command to fix this problem:

react-native start curl "http://localhost:8081/index.android.bundle?platform=android" -o "android/app/src/main/assets/index.android.bundle"
like image 768
Maksim Avatar asked Feb 17 '16 07:02

Maksim


2 Answers

Generating APK

To manually create the bundle for a debug build:

react-native bundle --dev false --platform android --entry-file index.js --bundle-output ./android/app/src/main/assets/index.android.bundle --assets-dest ./android/app/src/main/res

To build the APK's after bundling

  • cd android
  • ./gradlew assembleDebug
  • ./gradlew assembleRelease
like image 61
vinay sagar Jami Avatar answered Nov 13 '22 18:11

vinay sagar Jami


  • You can download the Android Studio setup from this link : Android Studio Setup Link

    An easier way would be if you have some Android Studio usage + "Android" Past Experience,

    Even if you don't have any experience of Android Studio, I have given a step by step workaround for making a build, Also mentioned above is the Android Studio Setup Link:

    1. Open your Android Studio.
    2. Click "File" in the top Menu bar.
    3. Click "New Option" and "Import Project".
    4. Navigate to your React Native Project's Folder -> android -> app 5.Click "Ok" button at the bottom of the Dialog.
    5. Now wait for few minutes before Android Studio completes its process.
    6. Once Done, Click on "Build" in the top Menu Bar.
    7. Click on the Generate Signed APK option.
    8. Now, if you have a existing key store path, you are good to go, if not then click the "Create New" button, and enter data in the fields.
    9. Fill in the "Key store Password", "Key alias", and "Key Password" and click "Next" button at the bottom of the Dialog.
    10. Select the Build Type from the Drop down menu, "Debug" or "Release".
    11. Check the Signature versions v1, v2 according to you requirements(v1,v2 both are usually checked when you make a build in android).
    12. Click on Finish.
    13. Now wait for few minutes before the Android Studio completes its process of making an Android APK of your app.

    14. Once Done , You can find your React Native App's Android APK file in the : "YOURPROJECT/android/app/debug" folder, or in case of Release Build in the: "YOURPROJECT/android/app/release" folder.

like image 45
Ahmad Wahaj Avatar answered Nov 13 '22 19:11

Ahmad Wahaj