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

爷,独闯天下 提交于 2020-01-02 10:17:46

问题


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"

回答1:


It's all written here.

You need to generate signing keys first, then set them as variables, use them to config you app then create a signed apk.

If you need any help on a precise point of this process, I'll be pleased to help you. But check the docs, they are well written.




回答2:


  • 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.




回答3:


Generating APK

  • 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 manually create the bundle for a debug build.

To build the APK's after bundling

  • cd android
  • ./gradlew assembleDebug
  • ./gradlew assembleRelease


来源:https://stackoverflow.com/questions/35450777/how-to-build-android-apk-from-my-react-native-project

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!