45

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.

Pawel Veselov
  • 3,996
  • 7
  • 44
  • 62
zidniryi
  • 1,212
  • 3
  • 15
  • 36

1 Answers1

109

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.
Andrew
  • 26,706
  • 9
  • 85
  • 101
  • 2
    It is worth to mention that signing data should be taken from another file (like keystore.properties) and this file should be added to gitignore, so others won't copy your signing. – MasterPiece Sep 13 '22 at 18:57
  • hi,if we add our fileName.keystore file to gitignore,it will prevent to copy yes you are right.But when we work in a team and other members will need it too,then what should we do? – Alihaydar Jan 17 '23 at 14:17
  • @Alihaydar Each developer should have their own keystore for development. Only a few trusted people and your CI server should have access to the production keystore. – Devin Brown Feb 16 '23 at 16:13
  • @DevinBrown,I see,thank you for your comment.King regards – Alihaydar Feb 17 '23 at 17:52