This morning I generated an apk via this command:
./gradlew bundleRelease
which generated the following:
However, now I need to generate a newer version of the apk as I made some changes to the application.
I tried just running the above command again, but that did not seem to work. The files are all the same ones. How do I regenerate an apk? Do I need to delete the old ones first?
Clean your older build first using
./gradlew clean
Then build your apk using
# for debug
./gradlew assembleDebug
# for release
./gradlew assembleRelease
# if you want all the build variants, just using below command
./gradlew assemble
Your apks can be found inside output/apk directory
bundleRelease generates a bundle - filing in just the bundle directory you see. You should be using assembleRelease if you want to generate an APK and the apk directory:
./gradlew assembleRelease
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.
Every time when I need to build the debug and release ver for the QA what I do:
In BuildVariants change to Debug make a build APK.
Then I change the BuildVariants to Release and build one more APK.
So, question is if it is possible to build two versions at the same time?
If you go to the root folder of the proyect, you can compile the debug version using the command line:
gradlew.bat assembleDebug
Or if you want to compile a release:
gradlew.bat assembleRelease
Takng that into account, you can create a script, named "compile.bat" for example, with this content:
#echo off
title Compiling...
echo Compiling the debug and realease apk's...
gradlew.bat assembleDebug
gradlew.bat assembleRelease
#echo Finished!
pause
You can build an APK through the terminal, then you can launch as many build processes as you like.
$ ./gradlew assembleFlavouraFlavourbRelease & ./gradlew assembleFlavouraFlavourbDebug &
Let's say I have a build variant named debugAutomation.
I wan't to build this variant into .*apk file using gradle command. I do:
./gradlew assembleDebugAutomation
This provides me with application .*apk. But to perform automation tests in espresso I also need test .*apk. So I do again:
./gradlew assembleDebugAutomationAndroidTest
And .*apk with -androidTest is in my outputs/apk/ folder of my project.
Where is the trick and problem?
a) while performing assembleDebugAutomation I have only application .*apk built.
b) while performing assembleDebugAutomationAndroidTest then during build process THIS APK BEING INSTALLED ON ALL CURRENTLY VISIBLE DEVICES IN ADB.
My question is: How can I build androidTest .*apk with gradle command so it ONLY BUILDS APK and DOESN'T INSTALL IT on currently visible devices in ADB during build process?
To just assemble into an APK:
./gradlew assembleDebug
That will build however, but won't do any automation tests, nor would it install to devices.
./gradlew assembleDebug
Builds the debug APK.
./gradlew assembleDebugAndroidTest
Builds the test APK
Or if you have a flavour in your gradle file it would be:
./gradlew assemble<FlavourName>DebugAndroidTest
How to create an anpk file using gradle script.I have one android project.I want to create its apk but using gradle script not through android studio.
Is there any such script which will create apk.
You can use gradlew script to build your apk file. Gradlew script is part of the project which is created using Android Studio. You can run gradle script like this
gradlew assembleDebug
or
gradlew assembleRelease
first option will generate apk in debug configuration. Second will generate release APK. There is also several other things that you need to prepare before you run this script. The most important thing is that you need to create keystore and point it in your gradle file.
To create keystore you can use this command:
keytool -genkey -v -keystore keystore.jks -alias your-alias -keyalg RSA -keysize 2048 -validity 10000
keytool should be placed in bin folder in your java root directory.
If you run gradle tasks you will see available task for your project. Here is the Build section
Build tasks
-----------
assemble - Assembles all variants of all applications and secondary packages.
assembleAndroidTest - Assembles all the Test applications.
assembleDebug - Assembles all Debug builds.
assembleDebugAndroidTest - Assembles the android (on device) tests for the Debug build.
assembleRelease - Assembles all Release builds.
build - Assembles and tests this project.
buildDependents - Assembles and tests this project and all projects that depend on it.
buildNeeded - Assembles and tests this project and all projects it depends on.
clean - Deletes the build directory.
compileDebugAndroidTestSources
compileDebugSources
compileDebugUnitTestSources
compileReleaseSources
compileReleaseUnitTestSources
mockableAndroidJar - Creates a version of android.jar that's suitable for unit tests.
So
gradle build
should do the job
You can create your own script using available gradle commands.
Here is a detailed article for build, test and deploy via bash script.
Following is the sample script you can use.
enter code
#Define all paths, constants here
PROJECT_DIR='/Users/mayuri/CODE/AndroidBuildAutomationSample/'
OUTPUT_DIR='/Users/mayuri/CODE/AndroidBuildAutomationSample/OUTPUT_DIR/'
#Enter project dir
cd $PROJECT_DIR
#Start Build Process
echo "\n\n\nCleaning...\n"
./gradlew clean
echo "\n\n\ncleanBuildCache...\n"
./gradlew cleanBuildCache
echo "\n\n\n build...\n"
./gradlew build
echo "\n\n\n assembleDebug...\n"
./gradlew assembleDebug
#Install APK on device / emulator
echo "installDebug...\n"
./gradlew installDebug
Remember to give execute permissions to your script file
chmod +x automate.sh
Execute the following commands from the directory of the associated project.
# build project, runs both the assemble and check task
gradle build
# build project complete from scratch
gradle clean build
# speedup second grandle build by holding it in memory
gradle build --daemon
By default, the Gradle build creates two .apk files in the build/outputs/apk folder. Check this link for further information
.