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.