Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create a release signed apk file using Gradle?

I would like to have my Gradle build to create a release signed apk file using Gradle.

I'm not sure if the code is correct or if I'm missing a parameter when doing gradle build?

This is some of the code in my gradle file:

android {     ...     signingConfigs {           release {               storeFile file("release.keystore")               storePassword "******"               keyAlias "******"               keyPassword "******"          }      } } 

The gradle build finishes SUCCESSFUL, and in my build/apk folder I only see the ...-release-unsigned.apk and ...-debug-unaligned.apk files.

Any suggestions on how to solve this?

like image 915
Jan-Terje Sørensen Avatar asked Aug 20 '13 06:08

Jan-Terje Sørensen


People also ask

How do you generate a release 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.

Where is generated signed apk?

The Signed APK file is named app-release. You will find it in your project folder in the app/release directory.


Video Answer


2 Answers

Easier way than previous answers:

Put this into ~/.gradle/gradle.properties

RELEASE_STORE_FILE={path to your keystore} RELEASE_STORE_PASSWORD=***** RELEASE_KEY_ALIAS=***** RELEASE_KEY_PASSWORD=***** 

Modify your app/build.gradle, and add this inside the android { code block:

...     signingConfigs {     release {        storeFile file(RELEASE_STORE_FILE)        storePassword RELEASE_STORE_PASSWORD        keyAlias RELEASE_KEY_ALIAS        keyPassword RELEASE_KEY_PASSWORD         // Optional, specify signing versions used        v1SigningEnabled true        v2SigningEnabled true    } }  buildTypes {         release {             signingConfig signingConfigs.release         } } .... 

Then you can run gradle assembleRelease


Also see the reference for the signingConfigs Gradle DSL

like image 164
David Vávra Avatar answered Sep 18 '22 13:09

David Vávra


I managed to solve it adding this code, and building with gradle build:

android {     ...     signingConfigs {         release {             storeFile file("release.keystore")             storePassword "******"             keyAlias "******"             keyPassword "******"         }     }     buildTypes {         release {             signingConfig signingConfigs.release         }     } } 

This generates a signed release apk file.

like image 22
Jan-Terje Sørensen Avatar answered Sep 22 '22 13:09

Jan-Terje Sørensen