I've seen new release of react native for android and tried some examples. It works only with USB debug mode and "adb reverse tcp:8081 tcp:8081". How can I build android app for "production" including all dependencies and without react web-server connections.
Thank you.
To build a release version of your Android app:
$ cd your-app-folder
$ cd android && ./gradlew assembleRelease
You'll need to set up signing keys for the Play Store, full documentation here: https://reactnative.dev/docs/signed-apk-android
You will have to create a key to sign the apk. Use below to create your key:
keytool -genkey -v -keystore my-app-key.keystore -alias my-app-alias -keyalg RSA -keysize 2048 -validity 10000
Use a password when prompted
Once the key is generated, use it to generate the installable build:
react-native bundle --platform android --dev false --entry-file index.android.js \
--bundle-output android/app/src/main/assets/index.android.bundle \
--assets-dest android/app/src/main/res/
Generate the build using gradle
cd android && ./gradlew assembleRelease
Upload the APK to your phone. The -r flag will replace the existing app (if it exists)
adb install -r ./app/build/outputs/apk/app-release-unsigned.apk
A more detailed description is mentioned here: https://facebook.github.io/react-native/docs/signed-apk-android.html
As for me, I add in my package.json to "scripts":
"release": "cd android && ./gradlew assembleRelease"
And then in terminal I use:
npm run release
Or with yarn:
yarn release
I have put together some steps that worked for me. Hopefully it would save time.
For bundling the package to work in local you need to do
$ curl "http://localhost:8081/index.android.bundle?platform=android" -o "android/app/src/main/assets/index.android.bundle"
Then for compiling apk
$ ./gradlew assembleRelease
I have added detailed instructions at : https://github.com/shyjal/reactnative-android-production
To create a bundle of your android application to release application on play store.
cd /android
sudo ./gradlew bundleRelease
go to the android/build/outputs/bundle/release/app-release.apk
Upload this bundle on play store console.
Related
I was using expo build:android -t apk to get an apk file an try the application.
It was automatically available in expo.
Now I try to do the same with eas but it is not working.
I tried :
yarn eas build -p android -t apk
yarn eas build -p android --profile preview
yarn eas build -p android
All my build are of course created, but no one is available directly in expo like I was used to.
Any idea ?
I get a duplicate error after running 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 and consecutively react-native run-android --variant=release.
Deleting the duplicate resources by running rm -rf android/app/src/main/res/drawable-* actually helps. However, my changes doesn't get bundled after deleting those files. Hence, when I run react-native run-android --variant=release again, my changes isn't effected in the build.
Only the drawable_* delete.
android/app/sec/main/res/ and it work.
Or
Generate keystore
Place keystore under your project/android/app/
Edit android/gradle.properties file with your password for keystore
Edit android/app/build.gradle in your project folder and add the
signing config
Run this code in the command line cd android && gradlew
assembleRelease
If you run into a problem in building APK like this error:
Unable to process incoming event 'ProgressComplete ' (ProgressCompleteEvent)
I recommend to
upgrade gradle to 4.3 to avoid building problems
or use Gradlew.bat assembleRelease instead
I am working on react native. When i try to create a build of android using
gradlew assembleRelease
then getting an
* What went wrong:
Execution failed for task ':app:bundleReleaseJsAndAssets'.
> Process 'command 'npx.cmd'' finished with non-zero exit value 1
But when i create a build using below command build succesfully build
gradlew assembleRelease -x bundleReleaseJsAndAssets
But build not run on mobile device as i am opening my app after install it just crashed.
Also when i try to create build on different System (8gm ram) with same code then it creates build with same command and the build will successfully created. Provide me a solution for this,
use cd android
after that use this ./gradlew clean
and for apk ./gradlew assembleRelease -x bundleReleaseJsAndAssets
or use this for aab ./gradlew bundleRelease -x bundleReleaseJsAndAssets
Try these commands and please tell me if it works
For me, I had to run npm run android once and then ./gradlew assembleRelease worked
UPDATE: Run following command and see output log to find the bug
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
Personally, I had to run the app form within Android Studio.
That gave me a clearer error message which allowed me to fix the issue.
The error in my case had to do with entryFile: "index.android.js", inside app/build.gradle.
I had to change it to index.js since that was the entry point in my RN project.
I inherited a react native project, the original programmers generated an apk for android, but they are not available anymore.
In the project I see react-native.config.js, package.json and an android folder with gradlew.
For the moment I'd like just to generate apk for android...but I don't know where to start...
You can create an assemble release following these commands. Open up a command line / terminal within you project and run the following commands.
Install node modules.
npm install
Link dependencies.
react-native link
Create the metro bundle.
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
Change the directory to android.
cd android
Clean the Gradle.
gradlew clean
Create the assemble release.
gradlew assembleRelease -x bundleReleaseJsAndAssets
You can find the APK in
PROJECT_PATH\android\app\build\outputs\apk\release
Follow these steps.
perform npm start in your root-dir of project
run npm i in same root-dir of project
can perform react-native link in root-dir location
now cd android
now gradlew assembleRelease
it will generate your .apk file at project_name/android/app/build/outputs/apk/release
I tried to generate an unsigned apk to install on my other device.
I tried
cd android
then
gradlew assembleRelease
I got an "app-release-unsigned.apk" at android\app\build\outputs\apk\release
I transfered this "app-release-unsigned.apk" to my other android device. Turned on the "install unknown apps". Then installed the "app-release-unsigned.apk", but I got error
App not installed.
Did I missed any steps? Why can't I install this app? I thought for a release, the apk should have everything it need to run my app.
Try this and make sure you have created assets folder :
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 \
&& cd android \
&& ./gradlew clean\
&& ./gradlew assembleDebug
After this you can find your debug apk in
/android/app/build/outputs/apk/debug
Hope it will work .