97

I am trying to build an APK that I can upload to the Play Store.

When I select Build|Generate Signed APK... in Android Studio (version 0.3.1), I am directed to a link on how to properly set up the signing process in the "gradle build scripts":

enter image description here

http://tools.android.com/tech-docs/new-build-system/user-guide#TOC-Signing-Configurations

Unfortunately, after checking that page I'm at a loss as to what file to edit and what to put in it - I'm coming from a Visual Studio background, so lazily expect stuff to 'just work' :).

(After OK'ing Android Studio's warning message, A.S. brings up a Generate Signed APK Wizard, which I went through, passing my key's details. The resulting APK was rejected by the Play Store for having a key with a too-soon expiry-date).

I also tried bringing up the Android Studio Terminal window and running 'gradle', as instructed in the above message, but this command was not found. So as an aside, since perhaps running the command might do something useful, how would I run gradle?

I found a 'Gradle' window in the A.S. IDE, and tried building the assembleRelease target found in that window. However, the Run window output just shows "Executing external task 'assembleRelease'...".

mackenir
  • 10,801
  • 16
  • 68
  • 100
  • 2
    The expiration date has to be after some date. It's 22 October 2033. http://developer.android.com/tools/publishing/app-signing.html – hichris123 Oct 27 '13 at 15:47
  • I created the key using the settings in the Android documentation for using keystore. I guess probably it just didn't use the key or something. I wouldn't get too hung up on that detail. Then again after two days of pain using Android dev tools, who knows... – mackenir Oct 27 '13 at 15:50
  • Try to use ADT+Eclipse http://developer.android.com/sdk/installing/bundle.html. It has GUI you are expecting from IDE, like build, run, debug, export release apk. AndroidStudio is alpha version for now, and still needs to smooth things over. – Sergii Pechenizkyi Oct 27 '13 at 17:15
  • I've decided to take your advice @plastiv. Android Studio will be nice when it's more stable - I use Resharper so was used to some of the shortcuts. – mackenir Oct 29 '13 at 21:47
  • Is it me or is the expiration date suspiciously close to the end of days? https://en.wikipedia.org/wiki/Year_2038_problem – Pica Jun 30 '18 at 17:53
  • See [this answer](https://stackoverflow.com/a/71169679/8583692) for Kotlin DSL. – Mahozad Feb 18 '22 at 07:37
  • 1
    Does this answer your question? [How to set up gradle and android studio to do release build?](https://stackoverflow.com/questions/18460774/how-to-set-up-gradle-and-android-studio-to-do-release-build) – Mahozad Feb 18 '22 at 11:26

3 Answers3

96

Follow these steps in the IDE: Build -> Generate Signed APK -> Create new...

Then fill up "New Key Store" form. If you wand to change .jnk file destination then chick on destination and give a name to get Ok button. After finishing it you will get "Key store password", "Key alias", "Key password" Press next and change your the destination folder. Then press finish, thats all. :)

enter image description here

enter image description here enter image description here

enter image description here enter image description here

Mahozad
  • 18,032
  • 13
  • 118
  • 133
Shohan Ahmed Sijan
  • 4,391
  • 1
  • 33
  • 39
54

Click \Build\Select Build Variant... in Android Studio. And choose release.

Alexander Lubyagin
  • 1,346
  • 1
  • 16
  • 30
25

AndroidStudio is alpha version for now. So you have to edit gradle build script files by yourself. Add next lines to your build.gradle

android {

    signingConfigs {

        release {

            storeFile file('android.keystore')
            storePassword "pwd"
            keyAlias "alias"
            keyPassword "pwd"
        }
    }

    buildTypes {

       release {

           signingConfig signingConfigs.release
       }
    }
}

To actually run your application at emulator or device run gradle installDebug or gradle installRelease.

You can create helloworld project from AndroidStudio wizard to see what structure of gradle files is needed. Or export gradle files from working eclipse project. Also this series of articles are helpfull http://blog.stylingandroid.com/archives/1872#more-1872

Sergii Pechenizkyi
  • 22,227
  • 7
  • 60
  • 71