Release version of *.apk in Android Studio - android

I want to submite an application to Google Market. I found there is only one apk file generated in a project, its path is Project1Project/Project1/build/apk/Project1-debug-unaligned.apk
It looks like it's a debug version. Where do I find (if any) a release version of an application or how do I generate it?

Since Android Studio is based on IntelliJ, that's how to do it in IntelliJ:
Build -> Generate Signed APK
and provide it with your key and its password.

You can build an unsigned release version. See the answer here. I don't see an easy way to do it from the GUI, but you can use the shell command:
./gradlew assembleRelease
Make sure to cd to your project's directory before running the command. This will produce the file
Project1Project/Project1/build/apk/Project1-release-unaligned.apk
If you run ./gradlew assemble, both the release and debug version will be built.
More documentation here.

From Android Studio 1.3.1, the ready-to-publish apk location is :
app -> app-release.apk
This should be published to Google Play
Intermediate apks are at :
app -> build -> outputs -> apk -> app-release-unaligned.apk
This is Intermediate result of Signing process, should not be published to Google Play

Android gradle produces apk in two binaries: Unaligned and Aligned. Unaligned refers to how the data, files are structured within the APK file. A utility called zipalign modifies the APK to align data in a way that is optimized for users. Unaligned simply skips the zipalign stage.
Whereas an Aligned APK is an optimized version. The files are more structured and compressed, which helps the app run faster. They are also optimized for RAM usage so they can consume less RAM on the devices.
you will also see size difference in the APK generated.

Related

Android Studio: How to separate Run APK & Build APK

When I run an APK from Android studio it generates a partial apk in the build folder. When I click on Build APK, it generates the full apk in the same folder. They overwrite each other. I need to separate the output so that if I just hit on Run, the apk will have its own "run" folder, and when I build the apk, it would not be overwritten by Run APK. If this is possible, can someone guide me through the setup? Probably a config in gradle, or in Studio itself? Thank you very much!
When you run the app from android studio and create a build apk its the same thing so it overwrites the apk. It builds the app-debug.apk file. I think you are trying to create a app-release apk. You need to create an apk using generate signed apk for this. It will seperate the debug and release apk in two folders as debug and release.

How to generate full APK file including dynamic feature module

My project has dynamic feature module and I would like to generate debug or release APK including the dynamic feature. Currently I can get only base APK file.
Basically I would generate an APK file like normal application. But I couldn't do with dynamic feature. Yes, I know dynamic feature will work based on AAB.
Is there any ways to make a normal(base + all modules) APK file?. Please help on this.
Thanks
I don't see it documented anywhere, but the Android Gradle build tools include tasks to extract the universal APK for you. You can use something similar to:
./gradlew :yourmodule:packageDebugUniversalApk
Under the hood it uses bundletool and does essentially the same thing as the other answer, but it's nice to be able to do it from Gradle.
You can specify if your on demand module needs to be included in the universal APK that is usually generated for older devices, and then you can use bundletool to generate an Universal APK from the App Bundle:.
In this particular case, you can use something like:
bundletool build-apks --bundle <bundle_file> --output <APKS file> --ks <key_store> --key-pass <jks password> --ks-key-alias <key_alias> --ks-pass <key password> --overwrite --mode=universal
The key point is to include the --mode=universal this instruct bundletool to generate an Universal APK that will include all modules that have <dist:fusing dist:include="true"/> in the manifest.
In a similar way, when you run your project from Android Studio on a device, using the default configuration for Run (Deploy = Default APK) it includes all of your on demand modules.
Instead, when you run the application from Studio using the Run configuration (Deploy = APK from AppBundle) you can pick and choose which modules are installed.
However, in both cases, you cannot test on demand module downloads if you don't go through the Play store.
Note (November 2020)
As reported in another answer below, the Android Gradle Plugin includes a couple of undocumented tasks that can be used to generate Debug and unsigned Release universal APKs of your application.
The task related to the Debug version can be a quick alternative if you just need this type of build:
./gradlew :app:packageDebugUniversalApk
This task will generate (by default) app/build/outputs/universal_apk/debug/app-debug-universal.apk.
Update June 2019
Google introduced at I/O Internal App Sharing that allows to allow testing easily your App Bundles and APKs, including debug builds:
With internal app sharing, you can quickly share an app bundle or APK with your internal team and testers by uploading an APK or app bundle on the internal app sharing upload page.
Download bundletool jar file from Github (Latest release > Assets > bundletool-all-version.jar file). Rename that file to bundletool.jar
Generate your aab file from Android Studio eg: myapp-release.aab
Run following command:
java -jar "path/to/bundletool.jar" build-apks
--bundle=myapp-release.aab --output=myapp.apks --ks="/path/to/myapp-release.keystore" --ks-pass=pass:myapp-keystore-pass --ks-key-alias=myapp-alias --key-pass=pass:myapp-alias-pass
myapp.apks file will be generated
below is the command to generate the universal apk
java -jar bundletool.jar build-apks --bundle=nhl.aab --output=nhl.apks
--mode=universal
`

Android Instant App APKs

Whenever I use command line to produce feature APKs, it produces 2 APK. My feature apk and base apk. However, I don't upload them to Play Store. It says : Sorry we could not save your changes" Whenever I use Android Studio -> Build -> Generate Signed APK it only produces my base feature apk and when I try to upload the zip folder to Play Store, it says "Your Feature APKs contains "productdetail" apk either does not exist or was not included". Any idea why can it happen? Or any help how to produce v1+v2 signed APKs to upload them to Play Store?
At the moment, there are some bugs building your Instant App via the Studio menus (Build -> Generate Signed APK). You should run gradle directly, either by using the far right gradle panel in Studio and executing the top level assembleRelease task or via command line (./gradlew assembleRelease).
If you haven't already, to setup gradle to sign your APKs (v1+v2) use signingConfigs as per here.
Each of your feature modules (including base) will need to have signingConfigs setup in their build.gradle file to ensure each feature APK is signed correctly.

How to get the updated Apk file from the android studio.?

I am developing an android application. All the things is going well when I run the application into genymotion virtual device.And Since the apk is stored in F:...\app\build\outputs\apk location. So I just want to collect it from this location and download it to install in a android phone.As I simultaneously updating the application with code but this apk doesn't provide me the updated apk file according to the updated code .They just give me the old apk file even if i run my application again and again from the android studio. Can anyone suggest me why this is happening ??? I just want to run this apk into phone or download this apk file for another purpose.
This three steps will do Go build->Build apk
Go to Build > Build APK to generate a normal APK.
Go to Build > Generate Signed APK to generate signed APK.
Signed APK are those which we generate to release our application. Here it is, why is it necessary to generate signed APKs: Why should I Sign my Application APK before release
If you build a debug APK, it will still work on all devices but you cannot release it.
From terminal run the following command to make sure that you get the updated apk.
1. gradle clean (from windows )
-or-
./gradlew clean (from linux) -
Above command deletes the build folder.
2. gradle build (from windows)
-or-
./gradlew build(from linux)
Above command builds all the flavor for your application.
Edit: Original answer
Signed apk is needed to install in any other non debug device. This will be same as the debug app that runs in your test device/emulator.
Build -> Generate signed apk

Updating apk SHA1 differs even after using same keystore

I have uploaded my app to Goggle Play few months back after signing it with a release keystore, I have stored that Keystore for future updation. Now I have updated the apk with some changes, while trying to upload the new apk signed with same keystore along with same alias and password, the apk is not allowed to upload to Goggle Play.
Playstore shows me following error :
The only change is, earlier the appication was developed and build using eclipse and now in android studio Can this be the reason for showing the above error???
From the error message I would say you have mixed up the keystores, or android studio is just using the wrong one to do the release build. The best way to be completely sure is to clearly setup your build.gradle, and build it yourself on the command line using
./gradlew clean assembleRelease
What is probably happening is that Android Studio is using your debug keystore (ie. the default) to sign the release build because it can't find the original keystore you used in eclipse, or you have the wrong password somewhere...
Have a look at this configuration, note the location of the keystores, the naming convention and how it corresponds to the build.gradle. Note the signingconfigs and how they are setup for the release build. To build from the command line, simply cd into the directory with your "gradlew" file, and run
./gradlew clean assembleRelease
to build the release apk, or
./gradlew clean assembleDebug
to build the debug apk. If it fails, try
./gradlew clean assembleRelease --stacktrace
Screenshot of build.gradle and filesystem setup
But please remember not to put your keys in your source control! That means editing your .gitignore file.
There is a stack of information on how to do this here:
http://developer.android.com/tools/publishing/app-signing.html

Categories

Resources