Question

What's the difference between gradlewAssembleRelease, gradlewInstallRelease, and gradlew bundleRelease and when to use which?

When I want to upload an Android application to the Play Store, which one should I use?

I have tried the above but I am still confused about which one is the most effective?

./gradlew assembleRelease
./gradlew installRelease
./gradlew bundleRelease

I expect the best way to do the above.

 48  26470  48
1 Jan 1970

Solution

 120

Most of the answers that you are looking for can be found here

assembleDebug

This builds an apk for your project using the debug variant.

This creates an APK named module_name-debug.apk in project_name/module_name/build/outputs/apk/. The file is already signed with the debug key and aligned with zipalign, so you can immediately install it on a device.

installDebug

This builds an apk for your project using the debug variant and then installs it on a connected device

Or to build the APK and immediately install it on a running emulator or connected device, instead invoke installDebug

assembleRelease

This creates a release apk of your app. You would then need to sign it using the command line or by setting the signing details in your build.gradle (see below) and then you can install it on your device using adb.

The steps involved for signing an apk by the command line are fairly long and it can depend on how your project is set up. Steps for signing can be found here

bundleRelease

This creates a release aab, this is Google's preferred format for uploading to the Play Store.

Android App Bundles include all your app’s compiled code and resources, but defer APK generation and signing to Google Play. Unlike an APK, you can't deploy an app bundle directly to a device. So, if you want to quickly test or share an APK with someone else, you should instead build an APK.

Signing your apk/aab

You can configure your app/build.gradle so that signing will be done after your build has been completed.

In your app/build.gradle

android {
    ...
    defaultConfig { ... }
    signingConfigs {
        release {
            // You need to specify either an absolute path or include the
            // keystore file in the same directory as the build.gradle file.
            storeFile file("my-release-key.jks")
            storePassword "password"
            keyAlias "my-alias"
            keyPassword "password"
        }
    }
    buildTypes {
        release {
            signingConfig signingConfigs.release
            ...
        }
    }
}

You can read more about signing your app here

Now, when you build your app by invoking a Gradle task, Gradle signs your app (and runs zipalign) for you.

Additionally, because you've configured the release build with your signing key, the "install" task is available for that build type. So you can build, align, sign, and install the release APK on an emulator or device all with the installRelease task.

NOTE

It is best practice to not store your your signing data in your app/build.gradle. The following answer shows you how to store the signing data.

installRelease

You will have to have set up the signing above for this to work for a release build. It is the same as the installDebug but it creates a signed release variant and installs it on a connected device.

Usage

  • I use assembleRelease to build an apk that I want to share with other people.
  • I use installRelease when I want to test a release build on a connected device.
  • I use bundleRelease when I am uploading my app to the Play Store.
2019-07-17

Solution

 0
*gradlew assembleRelease*

This command is used to build a release version of your Android application. When you run this command, Gradle compiles your code, packages the APK (Android Package), and performs other necessary tasks to create a release-ready build. The output APK can be found in the build/outputs/apk directory.
gradlew installRelease


 
This command is used to install the release version of your Android application on a connected device or emulator. It combines the building and installation steps in a single command. After running this command, the release version of your app will be installed on the specified device.
gradlew (or gradlew build)


    
The gradlew command is a generic command used to build your Android application. When you run it without any specific tasks, it usually defaults to building the debug version of your app. If you use gradlew build, it will build both the debug and release versions of your app. The output APKs can be found in the build/outputs/apk directory
2024-01-31