92

I want to build android app and start signing it. For that I need to have Release version of apk. Google documentation suggests only Eclipse and ant ways to have release builds: http://developer.android.com/tools/publishing/app-signing.html#releasecompile

However I cannot find how to force gradle build release version of apk. build.gradle does not give any hints either. gradlew tasks suggests, that there is no install Release configuration, but uninstall release exists:

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 I am missing?

Jonik
  • 80,077
  • 70
  • 264
  • 372
IBr
  • 1,359
  • 1
  • 11
  • 16
  • I don't currently use Gradle in Android Studio, but the way to do it using the original Ant build is to simply use `Build` -> `Generate Signed APK` from the menu. – free3dom Aug 28 '13 at 07:31
  • Thanks I missed that, it will do. But still I want to know how to generate release version of unsigned package seperately and then do signing and whatever I want with it. – IBr Aug 28 '13 at 07:37
  • you should get automatically a release and debug version of your under your build variants. If you want an unsigned package let me know. – owe Aug 29 '13 at 13:00

6 Answers6

147
  1. open the Build Variants pane, typically found along the lower left side of the window:

Build Variants

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

then, Android Studio will execute assembleRelease task and install xx-release.apk to your device.

zwcloud
  • 4,546
  • 3
  • 40
  • 69
ipcjs
  • 2,082
  • 2
  • 17
  • 20
  • 5
    how do you open Build Variants? is this something i can do in Android Studio? – Lou Morda Mar 26 '15 at 16:58
  • 17
    The build variants is on the left hand side, please see the attached screenshot for a better idea of location :) [Screenshot](http://prntscr.com/6u7j3s) – Jake Nixon Apr 15 '15 at 21:21
  • 8
    Tried this. But getting error : "app-release-unsigned.apk is not signed. Please configure the signing information for the selected flavor using the Project Structure dialog.Open Project Structure Dialog" – jrh Jul 07 '15 at 12:34
  • 2
    @jrhamza Follow it prompts you to add a release key. – ipcjs Jul 09 '15 at 12:57
  • 2
    Amazing how well hidden this simple switch is if you've never had the Build Variants window open! – aardvarkk Nov 04 '16 at 00:28
  • It would've been too obvious to put it in the configurations! – Julius Sep 11 '19 at 15:53
47

in the latest version of android studio, you can just do:

./gradlew assembleRelease

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

See the docs 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 {

    }
}
Grace Huang
  • 5,355
  • 5
  • 30
  • 52
dres
  • 1,172
  • 11
  • 15
  • 3
    In the latest version of Android Studio (0.2.11) Generate Signed Apk no longer works. You're directed to set up a signing configuration in your gradle.bundle file, which (presumably) has to be run by hand from the command line unless you're willing to hardcode your password there: http://tools.android.com/tech-docs/new-build-system/user-guide#TOC-Signing-Configurations –  Oct 04 '13 at 12:01
  • 13
    Why the newer the Android Studio, the more difficult to use? – Bagusflyer Oct 08 '13 at 12:23
34

No need to update gradle for making release application in Android studio.If you were eclipse user then it will be so easy for you. If you are new then follow the steps

1: Go to the "Build" at the toolbar section. 2: Choose "Generate Signed APK..." option. enter image description here

3:fill opened form and go next 4 :if you already have .keystore or .jks then choose that file enter your password and alias name and respective password. 5: Or don't have .keystore or .jks file then click on Create new... button as shown on pic 1 then fill the form.enter image description here

Above process was to make build manually. If You want android studio to automatically Signing Your App

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

On the project browser, right click on your app and select Open Module Settings. On the Project Structure window, select your app's module under Modules. Click on the Signing tab. Select your keystore file, enter a name for this signing configuration (as you may create more than one), and enter the required information. enter image description here Figure 4. Create a signing configuration in Android Studio.

Click on the Build Types tab. Select the release build. Under Signing Config, select the signing configuration you just created. enter image description here Figure 5. Select a signing configuration in Android Studio.

4:Most Important thing that make debuggable=false at gradle.

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

visit for more in info developer.android.com

AndroidLad
  • 687
  • 7
  • 14
22

To activate the installRelease task, you simply need a signingConfig. That is all.

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

Finally, the plugin creates install/uninstall tasks for all build types (debug, release, test), as long as they can be installed (which 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 is how to obtain the installRelease task:

Example build.gradle:

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
    }
  }
}
Jared Burrows
  • 54,294
  • 25
  • 151
  • 185
21

This is a procedure to configure run release version

1- Change build variants to release version.

enter image description here

2- Open project structure. enter image description here

3- Change default config to $signingConfigs.release enter image description here

Houssin Boulla
  • 2,687
  • 1
  • 16
  • 22
6

To compile with release build as shown below:

enter image description here

Shiv Buyya
  • 3,770
  • 2
  • 30
  • 25