问题
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:
- Open your Android Studio.
- Click "File" in the top Menu bar.
- Click "New Option" and "Import Project".
- Navigate to your React Native Project's Folder -> android -> app 5.Click "Ok" button at the bottom of the Dialog.
- Now wait for few minutes before Android Studio completes its process.
- Once Done, Click on "Build" in the top Menu Bar.
- Click on the Generate Signed APK option.
- 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.
- Fill in the "Key store Password", "Key alias", and "Key Password" and click "Next" button at the bottom of the Dialog.
- Select the Build Type from the Drop down menu, "Debug" or "Release".
- Check the Signature versions v1, v2 according to you requirements(v1,v2 both are usually checked when you make a build in android).
- Click on Finish.
Now wait for few minutes before the Android Studio completes its process of making an Android APK of your app.
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/resto 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