I'm trying to build APK from command line in my React Native project. I've used react-native-config plugin to define my API URLs based on selected environment.
When I try to launch the app on emulator with the command (from Terminal), ENVFILE=.env.dev react-native run-android, app builds and launches properly.
But when I try to generate Release build using the command (from Terminal), ENVFILE=.env.dev && cd android && ./gradlew clean build, command fails with the log:
> Configure project :app
Reading env from: .env
**************************
*** Missing .env file ****
**************************
Question: How to build Release APK using ENVFILE from Terminal?
Try below
cd android && ENVFILE=.env.dev ./gradlew clean build
Related
I have a react native project.
I want to build a release to publish on play store, here in react native official documentation to publish an app we can see:
Generating the release AAB
Run the following in a terminal:
cd android
./gradlew bundleRelease
Here is the first outputs I got:
./gradlew bundleRelease
Starting a Gradle Daemon (subsequent builds will be faster)
> Configure project :app
Reading env from: .env
gradlew is reading my env vars in .env file while I got a .env.production that I want gradlew to read instead.
How can I do this ?
I would recommend you to use react-native-config if you want to use other type of .env files for different environments.
I am using react-native 0.60 version and my Gradle version is 5.4.1. Now I'm trying to extract signed apk. When I execute, all the steps the apk build successfully. But When I checking this path F:\React Native\AwesomeProject1\android\app\build\outputs\apk
please check this screenshot https://prnt.sc/p391mr.
Use this command to generate release apk
react-native run-android --variant=release
Note that --variant=release is only available if you've set up signing as described above.
You can kill any running packager instances, since all your framework and JavaScript code is bundled in the APK's assets.
Please follow this link
https://facebook.github.io/react-native/docs/signed-apk-android
You using this command
$ cd android
$ ./gradlew bundleRelease
You only generate android apk bundle (AAB)not an apk.The generated AAB can be found under
android/app/build/outputs/bundle/release/app.aab
On windows if you're going to use gradlew directly you need to run the windows variant of the command. See https://developer.android.com/studio/build/building-cmdline
So you should be running gradlew bundleRelease
From your screenshot you are running the *nix variant of ./gradlew bundleRelease. Note the removal of the leading ./ in the Windows version.
When running the android app in react native i'm geeting this error
Execution failed for task ':react-native-contacts:compileDebugJavaWithJavac'.
Could not find tools.jar. Please check that C:\Program Files\Java\New folder contains a valid JDK installation.
I have also checked the java version it is installted. My java version is 1.8.0_151.
add Jdk path org.gradle.java.home=C:\\Program Files\\Java\\jdk1.8.0_144 to gradle.properties file and then run this command line in your projects root
cd android && gradlew clean && cd .. && react-native run-android
Here, I have built the react native android app using this documentation Doc
in jenkins which was configured on ubuntu 16.04 (in virtual machine).
Here is the build command which I used to build the react native app(android) in Jenkins
cd $WORKSPACE && chmod -R 777 ./android && cd ./android && npm install && ./gradlew clean && ./gradlew assembleDebug
The build process end successfully creating an apk file in the following path
build_release_v1/ws/android/app/build/outputs/apk/
Note build_release_v1 is the jenkins project name and ws is for the workspace of it.
Though the apk is created it comes up with following errors
What may be the case ....please help me with this ...Thanks in advance...
The problem is that if you want a debug build (since you are using assembleDebug), React Native generates an APK that expects to have a connection to the bundle server (it does the same as react-native run-android). My guess is that you want to test the app without the bundler, so you have two options: either run assembleRelease instead (have a look here for more details) or manually create the bundled JavaScript code and then create the APK. Please refer to this question for details.
Building apk for large project take much time to process all Gradle task.
I have try this but it clean and build
$ gradle installDebug
How to write separate gradle task and add to project Gradle run configuration.
So that by simply excuting gradle task it install existing build debug apk or release apk or any other build type without rebuidling it.
It will save deployment time of apk in multiple devices
Hope this can help you: I created a new shell file install_apk:
#!/bin/bash
# Usage
# run ./install_apk # to install debug apk
# run ./install_apk release # to install release apk
if [ $1 == "release" ]; then
adb install -r ./app/build/outputs/apk/app-release.apk
echo "install release apk"
else
echo "install debug apk"
adb install -r ./app/build/outputs/apk/app-debug.apk
fi
you can update android studio to version > 2.0 which has instant run as a built in feature
http://tools.android.com/tech-docs/instant-run
here some more details , cheers