Developing a mobile application is not only writing code, but also the final stage of packaging the product for users. For many novice developers, the moment when project ready to be handed over to testers or published in the store becomes a point of misunderstanding. The development environment interface may seem overloaded, and finding the right button to create an installation file can be difficult.

Export APK (Android Package Kit) is a critical stage in the life cycle of any application. It is this file that contains the compiled code, resources and manifest necessary for installation on a device running Android. Unlike debug versions, which are built automatically when launched on the emulator, a release build requires a special approach to configuration and signing.

In this article we will analyze in detail the process of creating both debug and release versions of the application. You will learn about the differences between .apk and .aabformats, learn how to set up a digital signature and understand where exactly in the project structure finished files are saved. This knowledge will allow you to confidently complete the project and transfer it to the end user.

Preparing the project for assembly

Before you start generating the installation package, you need to make sure that your project is in a stable state. Compilation errors or missing dependencies can interrupt the build process early on. Open the file build.gradle (Module: app) and check that the library versions are up to date.

Often developers forget to update code version i name version before exporting. These are critical parameters that identify your application in the system and stores. If you plan to release updates, increasing these numbers is mandatory, otherwise the system will refuse to install the new version over the old one.

โš ๏ธ Attention: Make sure that the manifest file AndroidManifest.xml has the correct permissions and components. Errors here may result in the application installing but not running on the target device.

It is also recommended to clear the project of temporary build files to avoid cache conflicts. This can be done through the menu by selecting Build โ†’ Clean Project, and then Build โ†’ Rebuild Project. This approach ensures that you export exactly the code that you see in the editor, without artifacts from previous builds.

โ˜‘๏ธ The project is ready for export

Done: 0 / 4

Differences between Debug and Release builds

The environment Android Studio offers two main types of assembly, each of which has its own purpose. Understanding the difference between them will help you avoid situations where the application works on the developerโ€™s phone, but crashes on the userโ€™s.

Debug build (Debug) is created by default when the run button is clicked. It is signed by an automatic debug key that is generated by the development environment. This option is ideal for testing functionality, but is absolutely not suitable for publication in Google Play for security reasons.

The release assembly (Release) requires manual configuration of the signature and often includes processes of code obfuscation (compression and obfuscation) through ProGuard or R8. This reduces file size and protects the source code from reverse engineering. It is this type of assembly that is used for the final export.

Characteristic Debug APK Release APK
Signature Automatic debug key Custom key (Keystore)
Optimization Disabled (for debugging speed) Enabled (Shrink, Minify)
Debugging Enabled (debuggable=true) Prohibited
Purpose Testing on an emulator/device Publishing in stores/distribution
๐Ÿ’ก

Never publish the Debug version of the application for a wide audience. It contains debugging information that can be used by attackers to hack your product.

Creating an application signature (Keystore)

A digital signature is a certificate confirming the authorship of the application. Without it, the system Android will not allow installation, and the application store will not accept the file for moderation. The process of creating a key store (Keystore) is a one-time action for a specific project, but requires careful handling.

To generate a key in Android Studio, go to the menu Build โ†’ Generate Signed Bundle / APK. In the window that opens, select the format APK and click Next. If you don't have a vault yet, click the Create new... next to the file selection field.

You will need to set a password for the storage, as well as create an alias (alias) for a specific key inside it. Keystore and alias password must be saved in a safe place, since their recovery is impossible. Losing the key means that you will never be able to update this application again, since new versions must be signed with the same key.

  • ๐Ÿ” Create a complex password containing letters, numbers and special characters.
  • ๐Ÿ“… Set a long certificate validity period (recommended 25 years or more).
  • ๐Ÿ’พ Make a backup copy of the file .jks or .keystore to an external storage device.

โš ๏ธ Attention: The interface of the Key Creation Wizard may vary slightly in different versions of Android Studio. If you do not see the create button, make sure that you have the latest SDK Tools updates installed.

๐Ÿ“Š Where do you store the signing keys?
In cloud storage
On a flash drive/external drive
In the manager passwords
Written in notepad

Step-by-step export of an APK file

After the key storage has been created and configured, you can proceed to direct export. Return to the window Generate Signed Bundle / APK, select mode APK and specify the path to your storage file. Enter all required passwords.

At the next stage of the build wizard, you will be asked to select a build option (Build Variant). Make sure that option releaseis selected. Also here you can configure obfuscation parameters if they are not already registered in build.gradle. The V1 (Jar Signature) and V2 (Full APK Signature) checkboxes must be active for compatibility with all versions of Android.

Click the Finishbutton to start the compilation process. A window will appear at the bottom of the screen Build, where the progress of tasks will be displayed. After successful completion, the system will prompt you to go to the folder with the finished file or immediately install it on the connected device.

Default path to the file:

app/release/app-release.apk

The finished file can be found in the project directory along the path specified above. Now this APK file is completely ready for distribution to users or uploading to the developer console.

๐Ÿ’ก

Always make sure that the 'release' build is selected and not 'debug' before the final export, otherwise the application will not pass moderation in Google Play.

Configuring Gradle for automatic assembly

Manual export through the menu is convenient for one-time actions, but professional development requires automation. File configuration build.gradle allows you to configure assembly types and signatures directly in the project code. This is especially useful when using continuous integration (CI/CD) systems.

There is a section android of your gradle module file. Here you can specify the path to the storage and passwords. However, storing passwords in clear text in a configuration file is unsafe if the project is in a public repository. signingConfigsin the block

For secure work, it is recommended to place sensitive data in a separate file keystore.properties, which is added to .gitignore. The build script then reads this data dynamically. This approach protects your keys from leakage when sharing code with colleagues.

  • ๐Ÿ“‚ Create a file keystore.properties in the root of the project.
  • ๐Ÿ”‘ Write the parameters there: storeFile, storePassword, keyAlias, keyPassword.
  • ๐Ÿ“œ Configure build.gradle to read this file during initialization.

Using build scripts also allows you to create different versions of the application for different stores or regions, changing only the configuration parameters. This saves time and reduces the risk of human error when manually selecting settings.

Android App Bundle (AAB) format vs APK

Since mid-2021, Google has required all new applications in Google Play to be published in the format Android App Bundle (.aab). This format is not a ready-made installation package, but a set of all resources and code from which the store generates an optimized APK for a specific userโ€™s device.

The main advantage AAB is a significant reduction in the size of the downloaded file for the user. The store sends to the phone only those resources (languages, screen densities, processor architectures) that this particular device needs. Traditional APK contains everything at once, which makes it heavier.

Is it possible to install AAB directly on the phone?

No, the .aab format is not intended for direct installation on the device. To test AAB on a real phone without publishing it in the store, you need to use Google's bundletool tool or the gradle command, which will generate a universal APK from the bundle. However, the format has not completely disappeared. It is still required to distribute applications through third-party stores, company portals, or direct file transfer to the user. If your target audience is in a region where Google Play is not available, exporting a classic APK is your only option.

However, the format APK did not disappear completely. It is still required to distribute applications through third-party stores, company portals, or direct file transfer to the user. If your target audience is in a region where Google Play is not available, exporting a classic APK is your only option.

โš ๏ธ Please note: App store publishing guidelines are subject to change. Before preparing a release, always check the current requirements in the help for developers of a specific marketplace.

Common errors and ways to solve them

The build process rarely goes perfectly smoothly the first time, especially in complex projects. One of the most common problems is signature error INSTALL_PARSE_FAILED_NO_CERTIFICATES. It occurs when the package is not signed or the signature is incorrect. Check that the passwords match and that the correct storage file is selected.

Another common situation is an error minSdkVersion. If your code uses features that are only available in newer versions of Android, and your project settings are set to support older devices, the build will fail. Use annotations @RequiresApi or check the logs to identify specific incompatibilities.

Developers also face the problem of low memory when building large projects. In this case, increasing the amount of memory allocated to the Gradle process helps. This is done in the file gradle.properties by changing the parameter org.gradle.jvmargs.

  • ๐Ÿ›  Error "Keystore was tampered with": incorrect storage password.
  • ๐Ÿ›  Error "Duplicate files": conflict of resources with the same names.
  • ๐Ÿ›  Error "Execution failed": network problems when downloading dependencies.
Where is the APK file physically located after assembly?

By default, the compiled file is saved in your project folder along the path: Project Name/app/release/. The file name is usually formed according to the template app-release.apk or app-release-universal.apkif you collected a universal package.

Is it possible to change the application icon after exporting the APK?

No, you canโ€™t. The icon is part of the resources that are compiled inside the APK file. To change the icon, you need to make changes to the source project, rebuild the application and export a new file.

What should I do if I lost the Keystore file?

Unfortunately, it is impossible to recover a lost signing key. You won't be able to update an existing app on Google Play. You will have to create a new application with a new package name, which means the loss of the user base and ratings of the old application.

What is the difference between V1 and V2 signature scheme?

V1 (Jar Signature) signs each file inside the archive separately, which allows you to modify the APK after signing (for example, to introduce viruses). V2 (Full APK Signature) signs the entire archive, ensuring integrity and security. For modern devices, V2 is mandatory.