How to configure gradle and android studio to create release builds?

I want to create an Android app and start signing it. For this, I need to have an apk version. The Google documentation only offers Eclipse and ant ways to create releases: http://developer.android.com/tools/publishing/app-signing.html#releasecompile

However, I cannot find how to get gradle to build the apk version. build.gradle does not give any hints. gradlew tasks assumes that there is no installed version of Release configuration, but there is a delete version:

 Install tasks ------------- installDebug - Installs the Debug build installTest - Installs the Test build for the Debug build uninstallAll - Uninstall all applications. uninstallDebug - Uninstalls the Debug build uninstallRelease - Uninstalls the Release build uninstallTest - Uninstalls the Test build for the Debug build 

My build.gradle :

 buildscript { repositories { mavenCentral() } dependencies { classpath 'com.android.tools.build:gradle:0.5.+' } } apply plugin: 'android' repositories { mavenCentral() } dependencies { compile 'com.android.support:support-v4:13.0.+' compile files('libs/android-support-v4.jar') compile project(":libraries:ActionBarSherlock") compile project(":libraries:CollabsibleSearchMenu") } android { compileSdkVersion 18 buildToolsVersion "18.0.1" defaultConfig { minSdkVersion 8 targetSdkVersion 16 } } 

What am I missing?

+68
android android-studio android-gradle release gradle
Aug 27 '13 at 8:39 on
source share
4 answers

In the latest version of Android Studio, you can simply do:

 ./gradlew assembleRelease 

or aR for short. This will produce an unsigned apk release. Creating a signed apk can be done in a similar way or you can use Build -> Generate Signed Apk in Android Studio.

See documents here

Here is my build.gradle for reference:

 buildscript { repositories { mavenCentral() } dependencies { classpath 'com.android.tools.build:gradle:0.5.+' } } apply plugin: 'android' dependencies { compile fileTree(dir: 'libs', include: '*.jar') } android { compileSdkVersion 17 buildToolsVersion "17.0.0" sourceSets { main { manifest.srcFile 'AndroidManifest.xml' java.srcDirs = ['src'] resources.srcDirs = ['src'] aidl.srcDirs = ['src'] renderscript.srcDirs = ['src'] res.srcDirs = ['res'] assets.srcDirs = ['assets'] } // Move the tests to tests/java, tests/res, etc... instrumentTest.setRoot('tests') // Move the build types to build-types/<type> // For instance, build-types/debug/java, build-types/debug/AndroidManifest.xml, ... // This moves them out of them default location under src/<type>/... which would // conflict with src/ being used by the main source set. // Adding new build types or product flavors should be accompanied // by a similar customization. debug.setRoot('build-types/debug') release.setRoot('build-types/release') } buildTypes { release { } } 
+41
Sep 13 '13 at 1:44
source share
  1. open the Build Variants panel, usually located along the bottom left of the window :

Build variants

  1. set debug to release
  2. shift+f10 run !!

Then Android Studio will complete the assembleRelease task and install xx-release.apk on your device.

+97
Dec 25 '14 at 4:59
source share

No need to update gradle to create release application in android studio. If you were an eclipse user, it will be so easy for you. If you are new, follow the steps

1: Go to the "Assembly" section of the toolbar section. 2: Select the option "Create Signature APK ...". enter image description here

3: fill out the open form and move on 4: if you already have .keystore or .jks, then select this file, enter your password and an alias and the corresponding password. 5: Or you do not have a .keystore or .jks file, then click the "Create New ..." button, as shown in Figure 1, then fill out the form. enter image description here

The above was the manual creation process. If you want Android Android Studio to sign your application automatically

In Android Studio, you can configure your project to automatically subscribe to the APK during the build process:

In the project browser, right-click on your application and select "Open Module Settings". In the "Project Structure" window, select the application module in the "Modules" section. Click the Signing tab. Select the keystore file, enter a name for this signature configuration (since you can create several), and enter the required information. enter image description here Figure 4. Creating a signature configuration in Android Studio.

Click the Building Types tab. Select release build. In the "Subscription Settings" section, select the signature configuration that you just created. enter image description here Figure 5. Select the signature configuration in Android Studio.

4: The most important thing that debuggable = false does in gradle.

  buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard- android.txt'), 'proguard-rules.txt' debuggable false jniDebuggable false renderscriptDebuggable false zipAlignEnabled true } } 

visit developer.android.com for more information

+29
Jun 20 '15 at 11:53 on
source share

To activate the installRelease task, you just need signingConfig . It's all.

From http://tools.android.com/tech-docs/new-build-system/user-guide#TOC-Android-tasks :

Finally, the plugin creates installation and uninstallation tasks for the entire assembly of types (debugging, release, test), if they can be installed (requires signing).

Here is what you want:

 Install tasks ------------- installDebug - Installs the Debug build installDebugTest - Installs the Test build for the Debug build installRelease - Installs the Release build uninstallAll - Uninstall all applications. uninstallDebug - Uninstalls the Debug build uninstallDebugTest - Uninstalls the Test build for the Debug build uninstallRelease - Uninstalls the Release build <--- release 

Here's how to get the installRelease task:

build.gradle example:

 buildscript { repositories { jcenter() } dependencies { classpath 'com.android.tools.build:gradle:1.2.3' } } apply plugin: 'com.android.application' android { compileSdkVersion 22 buildToolsVersion '22.0.1' defaultConfig { applicationId 'demo' minSdkVersion 15 targetSdkVersion 22 versionCode 1 versionName '1.0' } signingConfigs { release { storeFile <file> storePassword <password> keyAlias <alias> keyPassword <password> } } buildTypes { release { signingConfig signingConfigs.release } } } 
+20
Nov 28 '14 at 4:23
source share