Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set up gradle and android studio to do release build?

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?

like image 555
IBr Avatar asked Aug 27 '13 08:08

IBr


People also ask

How do I sync Gradle with Android Studio?

Open your gradle. properties file in Android Studio. Restart Android Studio for your changes to take effect. Click Sync Project with Gradle Files to sync your project.

What is Gradle build in Android Studio?

Android Studio uses Gradle, an advanced build toolkit, to automate and manage the build process, while allowing you to define flexible custom build configurations. Each build configuration can define its own set of code and resources, while reusing the parts common to all versions of your app.


2 Answers

  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.

like image 194
ipcjs Avatar answered Sep 18 '22 20:09

ipcjs


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 {      } } 
like image 20
dres Avatar answered Sep 20 '22 20:09

dres