Are you working on an Android application and need to save a ready one APK file for testing on a real device or transferring to colleagues? T Android Studio there are several ways to export the assembled application - from standard assembly through the menu to extraction from the project folder. This instruction will help you figure out how to properly save an APK in different scenarios: for debugging purposes, release or code analysis.
It is important to understand that APK (Android Application Package) is an archive with compiled code, resources and an application manifest. Depending on the type of assembly (debug or release) the files will differ in signature, optimization and installation ability. We will look at all the current methods, including hidden functions Android Studio Giraffe and Flamingo, as well as workarounds for older versions.
1. Standard APK assembly via the Build menu
The most obvious way is to use the built-in build tools. This method is suitable for quickly obtaining a maintenance version (debug.apk) or a signed release. Here's how to do it:
Open your project in Android Studio.
In the top menu, select
Build โ Build Bundle(s) / APK(s) โ Build APK.Wait for the build to complete (a notification will appear at the bottom
APK(s) generated successfully).Click on the link
locatein the notification - the folder with the file will openapp-debug.apk.
By default, the debug APK is saved in:
your_project/app/build/outputs/apk/debug/app-debug.apk
If the link locate does not appear, check the tab Build in the bottom panel Android Studio โall build logs are displayed there, including the path to the APK.
For release versions select Build โ Generate Signed Bundle / APK. Here you will need to specify the signature key (keystore) or create a new Release-APK will be optimized and ready for publication in Google Play.
2. Where to look for APK in the project folder
If the build was successful, but the notification is missing, or you want to find the APK manually, use the project file structure. All generated APKs are stored in the directory app/build/outputs/. Let's take a closer look:
- ๐ debug/ - debug versions (
app-debug.apk). Suitable for testing on an emulator or device viaadb install. - ๐ release/ โsigned release versions. Appear after selecting
Generate Signed APK. - ๐ flavors/ โif the project uses product flavors (for example,
freeandpaidversions), there will be corresponding APKs.
The path to the folder can be opened directly from Android Studio:
- Click
View โ Tool Windows โ Project(orAlt+1). - In the file tree, expand
app โ build โ outputs โ apk. - RMB by folder โ
Show in Files(orReveal in Finderon macOS).
What to do if the outputs folder is empty?
If after assembly the folder outputs/apk/ is empty, check:
1. Are there any errors in the logs (Build โ Build Output).
2. Is buildVariant in the bottom panel correctly indicated Android Studio (should be debug or release).
3. Is instant run disabled in the settings (may interfere with the generation of the full APK).
For convenience, add the folder outputs to your favorites in the file manager - this way you can quickly access new builds.
3. Export APK via Gradle (for experienced)
If you need to automate the build or get an APK with specific parameters, use tasks Gradle. This method is useful for CI/CD or custom configurations.
Open a terminal in Android Studio (Alt+F12and run one of the commands:
# Build debug-APK./gradlew assembleDebug
Build release-APK (without signatures)
./gradlew assembleRelease
Build a release-APK with a signature (a configured signingConfig is required)
./gradlew assembleRelease --stacktrace
After executing the command, the APK will appear in the standard folder outputs/apk/. To speed up the process, add alias for frequently used commands in ~/.bashrc or ~/.zshrc:
alias builddebug='cd /path/to/project && ./gradlew assembleDebug'
Important: when building via Gradle without a signature, the release-APK cannot be installed on the device - the Android system blocks unsigned applications. For testing, use the debugversion or configure signingConfig in build.gradle.
4. Extracting an APK from a connected device
If you have already installed an application on an emulator or physical device, but have lost the original APK, you can extract it back. This method even works for third-party applications (with limitations).
You will need:
- ๐ฑ Device with
USB debugging(included inSettings โ For developers). - ๐ป Computer with installed ADB (included in Android Studio).
- ๐ Application package name (can be found via
adb shell pm list packages).
Instructions:
- Connect the device via USB and check the connection:
adb devices - Find the path to APK:
adb shell pm path your.application packageExample answer:
package:/data/app/~~abc123/your.application package-1/base.apk. - Copy the APK to your computer:
adb pull /data/app/~~abc123/your.application package-1/base.apk
Make sure that USB debugging is enabled
Connect the device to the PC
Check the ADB operation with the command adb devices
Find out the application package name
Copy the APK to your computer-->
โ ๏ธ Attention: The extracted APK may not contain all the resources if the application uses split APKs (for example, for different architectures. In this case, you will need to download all parts via bundletool.
5. Problems when saving APK and their solutions
Even in standard scenarios, building an APK may fail with errors. Let's look at typical cases and ways to fix them:
| Error | Possible. reason | Solution |
|---|---|---|
Failed to read key from keystore |
Wrong password for keystore or file path. |
Check the data in signingConfigs in build.gradleUse keytool -list -keystore your_file.keystore for checking. |
APK not generated no errors |
Gradle cache or unsaved changes. | Run File โ Invalidate Caches, then rebuild the project. |
Installation failed: INSTALL_PARSE_FAILED_MANIFEST_MALFORMED |
Error in AndroidManifest.xml (for example, invalid targetSdkVersion). |
Check the manifest for validity through Android Lint (Analyze โ Inspect Code). |
Folder outputs/apk empty |
Build interrupted or in use instant run. |
Disable instant run in Settings โ Build, Execution, Deployment โ Instant Run. |
If the problem is not resolved, examine the build logs (View โ Tool Windows โ Build) or run Gradle with the flag --stacktrace for detailed information.
โ ๏ธ Attention: When building a release-APK without a signature Android Studio can silently create a file, but it will be unusable for installation. Always check the signature via apksigner verify --print-certs your_file.apk.
6. Optimizing the APK before saving
Before the final saving of the APK, it is recommended to optimize its size and performance. Here are the key settings in build.gradle:
- ๐๏ธ Resource compression: Enable
shrinkResources trueAndminifyEnabled trueto remove unused files. - ๐ ProGuard/R8: Adjust obfuscation rules to
proguard-rules.proto reduce code size. - ๐ฆ Split APKs: For large projects use
android.bundle.enableUncompressedNativeLibs=falseto separate by architecture.
Example configuration for build.gradle (Module: app):
android {buildTypes {
release {
minifyEnabled true
shrinkResources true
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
bundle {
language {
enableSplit = true
}
}
}
After optimization, compare the APK size before and after changes. To analyze the content, use APK Analyzer in Android Studio (Build โ Analyze APK). The tool will show which libraries or resources take up the most space.
The optimized APK loads faster and takes up less space on the device, which is critical for users with slow Internet or limited memory.
7. Alternative ways to obtain APK
If standard methods are not suitable, consider these options:
- ๐ Google Play Console: If the application has already been published, download the APK from the section
Release โ Production โ Artifact library. - ๐ Decompiler: To analyze other people's APKs, use JADX or Apktool (but remember the license restrictions!).
- โ๏ธ CI/CD services: Set up automatic assembly in GitHub Actions or Bitrise โ APK will be saved in artifacts after each commit.
For Google Play Console note:
โ ๏ธ Console interface details may change. For current instructions on downloading APK, see the official documentation Google Play.
If you are working with App Bundle (.aab), use to generate an APK bundletool:
java -jar bundletool.jar build-apks --bundle=my_app.aab --output=my_app.apks
FAQ: Frequently asked questions about saving APK
Is it possible to install debug-APK on any device?
Yes, but only if the option is enabled on the device Installation from unknown sources (Android 8.0+ will require permission for each application). Debug-APK is not optimized and may work slower than the release version.
Why does the release-APK weigh less than debug?
Release version goes through stages resource compression (shrinkResources), code obfuscation (ProGuard/R8) and removing debug symbols. Debug-APK contains additional information for debugging (for example, mapping files).
How to save an APK from an emulator?
Use adb the same as for a physical device. The path to the APK on the emulator will be similar: /data/app/application package/base.apk. Alternatively, copy the file via Device File Explorer to Android Studio (View โ Tool Windows โ Device File Explorer).
What to do if the APK does not install?
Check:
- Signed whether APK (for the release version).
- Compatibility
minSdkVersionwith the Android version on the device. - Presence of conflicts with an already installed version (uninstall the old application).
- File integrity (try rebuilding).
For diagnostics use adb logcat during installation.
Is it possible to convert an APK back to source code?
Partially - using decompilers (for example, JADX or Apktool). However:
- The code will be obfuscated (if ProGuard was used).
- Resources (for example, images) will be restored, but the project structure may differ.
- For closed libraries (for example,
.so-files) will require reverse engineering.