Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Studio: how to generate signed apk using Gradle?

I've searched on Google and SO but cannot find my answer.

This is the first time I'm working with the Gradle system and I am now at the point of generating a signed APK to upload to Google Play (project is imported from eclipse).

Now, I've read the part here that you should add signingConfigs to your build.gradle.

I've added these lines and now I saw that you need to run ./gradlew assembleRelease but running this in my CMD returns

'gradle' is not recognized as an internal or external command, operable program or batch file.

I've also tried to right click on the build.gradle and run it, saying it was sucessful but once I look in the build/apk folder only a file called app-debug-unaligned.apk.

So, how do I generate the signed APK using the Gradle system?

like image 338
Gooey Avatar asked Jan 04 '14 13:01

Gooey


People also ask

How can I get signed apk?

In the menu bar, click Build > Generate Signed Bundle/APK. In the Generate Signed Bundle or APK dialog, select Android App Bundle or APK and click Next. Below the field for Key store path, click Create new. On the New Key Store window, provide the following information for your keystore and key, as shown in figure 2.

Which file is used to generate signed apk?

If you miss the notification, you can still locate the APK file in the following path within your project folder: app/build/outputs/apk/debug. The file is named app-debug. apk by default.

What is a signed apk?

The signed apk is simply the unsigned apk that has been signed via the JDK jarsigner tool.


2 Answers

There are three ways to generate your build as per the buildType. (In your case, it's release but it can be named anything you want.)

  1. Go to Gradle Task in right panel of Android Studio and search for assembleRelease or assemble(#your_defined_buildtype) under Module Tasks

  2. Go to Build Variant in Left Panel and select the build from drop down

  3. Go to project root directory in File Explore and open cmd/terminal and run:

    Linux: ./gradlew assembleRelease or assemble(#your_defined_buildtype)

    Windows: gradlew assembleRelease or assemble(#your_defined_buildtype)

If you want to do a release build (only), you can use Build > Generate Signed apk. For other build types, only the above three options are available.

You can find the generated APK in your module/build directory having the build type name in it.

like image 117
Piyush Agarwal Avatar answered Sep 22 '22 17:09

Piyush Agarwal


It is possible to take any existing Android Studio gradle project and build/sign it from the command line without editing any files. This makes it very nice for storing your project in version control while keeping your keys and passwords separate:

./gradlew assembleRelease -Pandroid.injected.signing.store.file=$KEYFILE -Pandroid.injected.signing.store.password=$STORE_PASSWORD -Pandroid.injected.signing.key.alias=$KEY_ALIAS -Pandroid.injected.signing.key.password=$KEY_PASSWORD 
like image 29
Wayne Piekarski Avatar answered Sep 20 '22 17:09

Wayne Piekarski