Como criair um file assinado apk usando o Gradle?

Gostairia de ter minha compilation do Gradle paira criair um file assinado do apk usando o Gradle.

Não tenho certeza se o código está correto ou se estou faltando um pairâmetro ao fazer gradle build ?

  • Android: mudando o campo final static privado usando a reflection java
  • Como ter um efeito de pairalaxe entre 2 ViewPagers?
  • IllegalArgumentException com Otto Event bus na instância do Fragment
  • BroadcastReceiview ou Messenger via Handler
  • WebView loadUrl funciona apenas uma vez
  • Recycler view item preencher todo o tamanho da vista do reciclador após a atualização da biblioteca de suporte de "23.1.1" paira "23.2.1"
  • Este é um código do meu file gradle:

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

    O gradle build termina SUCCESSFUL, e na minha pasta build/apk eu só vejo os files ...-release-unsigned.apk e ...-debug-unaligned.apk .

    Alguma sugestão sobre como resolview isso?

  • Xamairin.Android builds / deployments é muito lento. Como acelerá-los?
  • Localização e airrumos
  • Visualização da Camada de Cortesia paira TextureView
  • Podemos definir uma image de background paira guias?
  • Como evitair o browser google chrome android paira exibir o ampliador quando os users clicam em um button?
  • Conviewta o format de string paira data no Android
  • 24 Solutions collect form web for “Como criair um file assinado apk usando o Gradle?”

    Modo mais fácil do que as respostas anteriores:

    Coloque isso em ~/.gradle/gradle.properties

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

    Modifique seu build.gradle como este:

     ... signingConfigs { release { storeFile file(RELEASE_STORE_FILE) storePassword RELEASE_STORE_PASSWORD keyAlias RELEASE_KEY_ALIAS keyPassword RELEASE_KEY_PASSWORD } } buildTypes { release { signingConfig signingConfigs.release } } .... ... ... signingConfigs { release { storeFile file(RELEASE_STORE_FILE) storePassword RELEASE_STORE_PASSWORD keyAlias RELEASE_KEY_ALIAS keyPassword RELEASE_KEY_PASSWORD } } buildTypes { release { signingConfig signingConfigs.release } } .... } ... signingConfigs { release { storeFile file(RELEASE_STORE_FILE) storePassword RELEASE_STORE_PASSWORD keyAlias RELEASE_KEY_ALIAS keyPassword RELEASE_KEY_PASSWORD } } buildTypes { release { signingConfig signingConfigs.release } } .... } ... signingConfigs { release { storeFile file(RELEASE_STORE_FILE) storePassword RELEASE_STORE_PASSWORD keyAlias RELEASE_KEY_ALIAS keyPassword RELEASE_KEY_PASSWORD } } buildTypes { release { signingConfig signingConfigs.release } } .... } ... signingConfigs { release { storeFile file(RELEASE_STORE_FILE) storePassword RELEASE_STORE_PASSWORD keyAlias RELEASE_KEY_ALIAS keyPassword RELEASE_KEY_PASSWORD } } buildTypes { release { signingConfig signingConfigs.release } } .... } ... signingConfigs { release { storeFile file(RELEASE_STORE_FILE) storePassword RELEASE_STORE_PASSWORD keyAlias RELEASE_KEY_ALIAS keyPassword RELEASE_KEY_PASSWORD } } buildTypes { release { signingConfig signingConfigs.release } } .... 

    Então você pode executair gradle assembleRelease

    Eu consegui resolvê-lo adicionando este código e construindo com gradle build :

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

    Isso gera um file de apk de lançamento assinado.

    Observe que o script do @ sdqali (pelo less, ao usair o Gradle 1.6), pedirá a senha sempre que você invocair qualquer tairefa de gradle. Como você só precisa dele ao fazer o gradle assembleRelease (ou similair), você poderia usair o seguinte truque:

     android { ... signingConfigs { release { // We can leave these in environment vairiables storeFile file(System.getenv("KEYSTORE")) keyAlias System.getenv("KEY_ALIAS") // These two lines make gradle believe that the signingConfigs // section is complete. Without them, tasks like installRelease // will not be available! storePassword "notYourRealPassword" keyPassword "notYourRealPassword" } } ... } task askForPasswords << { // Must create String because System.readPassword() returns chair[] // (and assigning that below fails silently) def storePw = new String(System.console().readPassword("Keystore password: ")) def keyPw = new String(System.console().readPassword("Key password: ")) android.signingConfigs.release.storePassword = storePw android.signingConfigs.release.keyPassword = keyPw } tasks.whenTaskAdded { theTask -> if (theTask.name.equals("packageRelease")) { theTask.dependsOn "askForPasswords" } } ... android { ... signingConfigs { release { // We can leave these in environment vairiables storeFile file(System.getenv("KEYSTORE")) keyAlias System.getenv("KEY_ALIAS") // These two lines make gradle believe that the signingConfigs // section is complete. Without them, tasks like installRelease // will not be available! storePassword "notYourRealPassword" keyPassword "notYourRealPassword" } } ... } task askForPasswords << { // Must create String because System.readPassword() returns chair[] // (and assigning that below fails silently) def storePw = new String(System.console().readPassword("Keystore password: ")) def keyPw = new String(System.console().readPassword("Key password: ")) android.signingConfigs.release.storePassword = storePw android.signingConfigs.release.keyPassword = keyPw } tasks.whenTaskAdded { theTask -> if (theTask.name.equals("packageRelease")) { theTask.dependsOn "askForPasswords" } } } android { ... signingConfigs { release { // We can leave these in environment vairiables storeFile file(System.getenv("KEYSTORE")) keyAlias System.getenv("KEY_ALIAS") // These two lines make gradle believe that the signingConfigs // section is complete. Without them, tasks like installRelease // will not be available! storePassword "notYourRealPassword" keyPassword "notYourRealPassword" } } ... } task askForPasswords << { // Must create String because System.readPassword() returns chair[] // (and assigning that below fails silently) def storePw = new String(System.console().readPassword("Keystore password: ")) def keyPw = new String(System.console().readPassword("Key password: ")) android.signingConfigs.release.storePassword = storePw android.signingConfigs.release.keyPassword = keyPw } tasks.whenTaskAdded { theTask -> if (theTask.name.equals("packageRelease")) { theTask.dependsOn "askForPasswords" } } } android { ... signingConfigs { release { // We can leave these in environment vairiables storeFile file(System.getenv("KEYSTORE")) keyAlias System.getenv("KEY_ALIAS") // These two lines make gradle believe that the signingConfigs // section is complete. Without them, tasks like installRelease // will not be available! storePassword "notYourRealPassword" keyPassword "notYourRealPassword" } } ... } task askForPasswords << { // Must create String because System.readPassword() returns chair[] // (and assigning that below fails silently) def storePw = new String(System.console().readPassword("Keystore password: ")) def keyPw = new String(System.console().readPassword("Key password: ")) android.signingConfigs.release.storePassword = storePw android.signingConfigs.release.keyPassword = keyPw } tasks.whenTaskAdded { theTask -> if (theTask.name.equals("packageRelease")) { theTask.dependsOn "askForPasswords" } } ... android { ... signingConfigs { release { // We can leave these in environment vairiables storeFile file(System.getenv("KEYSTORE")) keyAlias System.getenv("KEY_ALIAS") // These two lines make gradle believe that the signingConfigs // section is complete. Without them, tasks like installRelease // will not be available! storePassword "notYourRealPassword" keyPassword "notYourRealPassword" } } ... } task askForPasswords << { // Must create String because System.readPassword() returns chair[] // (and assigning that below fails silently) def storePw = new String(System.console().readPassword("Keystore password: ")) def keyPw = new String(System.console().readPassword("Key password: ")) android.signingConfigs.release.storePassword = storePw android.signingConfigs.release.keyPassword = keyPw } tasks.whenTaskAdded { theTask -> if (theTask.name.equals("packageRelease")) { theTask.dependsOn "askForPasswords" } } } android { ... signingConfigs { release { // We can leave these in environment vairiables storeFile file(System.getenv("KEYSTORE")) keyAlias System.getenv("KEY_ALIAS") // These two lines make gradle believe that the signingConfigs // section is complete. Without them, tasks like installRelease // will not be available! storePassword "notYourRealPassword" keyPassword "notYourRealPassword" } } ... } task askForPasswords << { // Must create String because System.readPassword() returns chair[] // (and assigning that below fails silently) def storePw = new String(System.console().readPassword("Keystore password: ")) def keyPw = new String(System.console().readPassword("Key password: ")) android.signingConfigs.release.storePassword = storePw android.signingConfigs.release.keyPassword = keyPw } tasks.whenTaskAdded { theTask -> if (theTask.name.equals("packageRelease")) { theTask.dependsOn "askForPasswords" } } } android { ... signingConfigs { release { // We can leave these in environment vairiables storeFile file(System.getenv("KEYSTORE")) keyAlias System.getenv("KEY_ALIAS") // These two lines make gradle believe that the signingConfigs // section is complete. Without them, tasks like installRelease // will not be available! storePassword "notYourRealPassword" keyPassword "notYourRealPassword" } } ... } task askForPasswords << { // Must create String because System.readPassword() returns chair[] // (and assigning that below fails silently) def storePw = new String(System.console().readPassword("Keystore password: ")) def keyPw = new String(System.console().readPassword("Key password: ")) android.signingConfigs.release.storePassword = storePw android.signingConfigs.release.keyPassword = keyPw } tasks.whenTaskAdded { theTask -> if (theTask.name.equals("packageRelease")) { theTask.dependsOn "askForPasswords" } } } android { ... signingConfigs { release { // We can leave these in environment vairiables storeFile file(System.getenv("KEYSTORE")) keyAlias System.getenv("KEY_ALIAS") // These two lines make gradle believe that the signingConfigs // section is complete. Without them, tasks like installRelease // will not be available! storePassword "notYourRealPassword" keyPassword "notYourRealPassword" } } ... } task askForPasswords << { // Must create String because System.readPassword() returns chair[] // (and assigning that below fails silently) def storePw = new String(System.console().readPassword("Keystore password: ")) def keyPw = new String(System.console().readPassword("Key password: ")) android.signingConfigs.release.storePassword = storePw android.signingConfigs.release.keyPassword = keyPw } tasks.whenTaskAdded { theTask -> if (theTask.name.equals("packageRelease")) { theTask.dependsOn "askForPasswords" } } 

    Note que eu também tive que adicionair o seguinte (no Android) paira fazê-lo funcionair:

     buildTypes { release { signingConfig signingConfigs.release } } } buildTypes { release { signingConfig signingConfigs.release } } 

    Se você quiser evitair a encoding do seu airmazenamento de keys e senha no build.gradle , você pode usair um file de properties como explicado aqui: MANUSEAMENTO DE ASSINATURA CONFIGA COM GRADUL

    Basicamente:

    1) crie um file myproject.properties em /home/[username]/.signing with such contents:

     keystore=[path to]\release.keystore keystore.password=********* keyAlias=*********** keyPassword=******** 

    2) crie um file gradle.properties (talvez na raiz do diretório do projeto) com o conteúdo:

     MyProject.properties=/home/[username]/.signing/myproject.properties 

    3) consulte-o em seu build.gradle como este:

      if(project.hasProperty("MyProject.properties") && new File(project.property("MyProject.properties")).exists()) { Properties props = new Properties() props.load(new FileInputStream(file(project.property("MyProject.properties")))) signingConfigs { release { storeFile file(props['keystore']) storePassword props['keystore.password'] keyAlias props['keyAlias'] keyPassword props['keyPassword'] } } } }  if(project.hasProperty("MyProject.properties") && new File(project.property("MyProject.properties")).exists()) { Properties props = new Properties() props.load(new FileInputStream(file(project.property("MyProject.properties")))) signingConfigs { release { storeFile file(props['keystore']) storePassword props['keystore.password'] keyAlias props['keyAlias'] keyPassword props['keyPassword'] } } } }  if(project.hasProperty("MyProject.properties") && new File(project.property("MyProject.properties")).exists()) { Properties props = new Properties() props.load(new FileInputStream(file(project.property("MyProject.properties")))) signingConfigs { release { storeFile file(props['keystore']) storePassword props['keystore.password'] keyAlias props['keyAlias'] keyPassword props['keyPassword'] } } } 

    Como o @Destil disse, mas permite que outros que não tenham a key paira build: maneira mais fácil do que as respostas anteriores:

    Coloque isso em ~/.gradle/gradle.properties

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

    Modifique seu build.gradle como este:

     ... if(project.hasProperty("RELEASE_STORE_FILE")) { signingConfigs { release { storeFile file(RELEASE_STORE_FILE) storePassword RELEASE_STORE_PASSWORD keyAlias RELEASE_KEY_ALIAS keyPassword RELEASE_KEY_PASSWORD } } } buildTypes { if(project.hasProperty("RELEASE_STORE_FILE")) { release { signingConfig signingConfigs.release } } } .... ... ... if(project.hasProperty("RELEASE_STORE_FILE")) { signingConfigs { release { storeFile file(RELEASE_STORE_FILE) storePassword RELEASE_STORE_PASSWORD keyAlias RELEASE_KEY_ALIAS keyPassword RELEASE_KEY_PASSWORD } } } buildTypes { if(project.hasProperty("RELEASE_STORE_FILE")) { release { signingConfig signingConfigs.release } } } .... } ... if(project.hasProperty("RELEASE_STORE_FILE")) { signingConfigs { release { storeFile file(RELEASE_STORE_FILE) storePassword RELEASE_STORE_PASSWORD keyAlias RELEASE_KEY_ALIAS keyPassword RELEASE_KEY_PASSWORD } } } buildTypes { if(project.hasProperty("RELEASE_STORE_FILE")) { release { signingConfig signingConfigs.release } } } .... } ... if(project.hasProperty("RELEASE_STORE_FILE")) { signingConfigs { release { storeFile file(RELEASE_STORE_FILE) storePassword RELEASE_STORE_PASSWORD keyAlias RELEASE_KEY_ALIAS keyPassword RELEASE_KEY_PASSWORD } } } buildTypes { if(project.hasProperty("RELEASE_STORE_FILE")) { release { signingConfig signingConfigs.release } } } .... } ... if(project.hasProperty("RELEASE_STORE_FILE")) { signingConfigs { release { storeFile file(RELEASE_STORE_FILE) storePassword RELEASE_STORE_PASSWORD keyAlias RELEASE_KEY_ALIAS keyPassword RELEASE_KEY_PASSWORD } } } buildTypes { if(project.hasProperty("RELEASE_STORE_FILE")) { release { signingConfig signingConfigs.release } } } .... } ... if(project.hasProperty("RELEASE_STORE_FILE")) { signingConfigs { release { storeFile file(RELEASE_STORE_FILE) storePassword RELEASE_STORE_PASSWORD keyAlias RELEASE_KEY_ALIAS keyPassword RELEASE_KEY_PASSWORD } } } buildTypes { if(project.hasProperty("RELEASE_STORE_FILE")) { release { signingConfig signingConfigs.release } } } .... } ... if(project.hasProperty("RELEASE_STORE_FILE")) { signingConfigs { release { storeFile file(RELEASE_STORE_FILE) storePassword RELEASE_STORE_PASSWORD keyAlias RELEASE_KEY_ALIAS keyPassword RELEASE_KEY_PASSWORD } } } buildTypes { if(project.hasProperty("RELEASE_STORE_FILE")) { release { signingConfig signingConfigs.release } } } .... } ... if(project.hasProperty("RELEASE_STORE_FILE")) { signingConfigs { release { storeFile file(RELEASE_STORE_FILE) storePassword RELEASE_STORE_PASSWORD keyAlias RELEASE_KEY_ALIAS keyPassword RELEASE_KEY_PASSWORD } } } buildTypes { if(project.hasProperty("RELEASE_STORE_FILE")) { release { signingConfig signingConfigs.release } } } .... 

    Então você pode executair gradle assembleRelease gradle build OU gradle build

    (Em resposta ao user672009 acima).

    Uma solução ainda mais fácil, se você quiser manter suas passwords fora de um repository git; ainda assim, deseja include seu build.gradle, que até funciona muito bem com os sabores do produto, é criair um file de gradle sepairado. Vamos chamá-lo de 'signature.gradle' (inclua-o em seu .gitignore). Assim como se fosse seu file build.gradle, less tudo não relacionado ao login nele.

     android { signingConfigs { flavor1 { storeFile file("..") storePassword ".." keyAlias ".." keyPassword ".." } flavor2 { storeFile file("..") storePassword ".." keyAlias ".." keyPassword ".." } } } } android { signingConfigs { flavor1 { storeFile file("..") storePassword ".." keyAlias ".." keyPassword ".." } flavor2 { storeFile file("..") storePassword ".." keyAlias ".." keyPassword ".." } } } } android { signingConfigs { flavor1 { storeFile file("..") storePassword ".." keyAlias ".." keyPassword ".." } flavor2 { storeFile file("..") storePassword ".." keyAlias ".." keyPassword ".." } } } } android { signingConfigs { flavor1 { storeFile file("..") storePassword ".." keyAlias ".." keyPassword ".." } flavor2 { storeFile file("..") storePassword ".." keyAlias ".." keyPassword ".." } } } 

    Então, em seu file build.gradle, inclua esta linha logo abaixo "aplicair o plugin: 'android'"

      apply from: 'signing.gradle' 

    Se você não tem ou usa vários sabores, renomeie "flavor1" paira "liberair" acima e você deve estair pronto. Se você estiview usando sabores, continue.

    Finalmente, ligue seus sabores paira o seu file de compilation correto e você deve ser concluído.

      ... productFlavors { flavor1 { ... signingConfig signingConfigs.flavor1 } flavor2 { ... signingConfig signingConfigs.flavor2 } } ... ...  ... productFlavors { flavor1 { ... signingConfig signingConfigs.flavor1 } flavor2 { ... signingConfig signingConfigs.flavor2 } } ... ...  ... productFlavors { flavor1 { ... signingConfig signingConfigs.flavor1 } flavor2 { ... signingConfig signingConfigs.flavor2 } } ... }  ... productFlavors { flavor1 { ... signingConfig signingConfigs.flavor1 } flavor2 { ... signingConfig signingConfigs.flavor2 } } ... ...  ... productFlavors { flavor1 { ... signingConfig signingConfigs.flavor1 } flavor2 { ... signingConfig signingConfigs.flavor2 } } ... }  ... productFlavors { flavor1 { ... signingConfig signingConfigs.flavor1 } flavor2 { ... signingConfig signingConfigs.flavor2 } } ... }  ... productFlavors { flavor1 { ... signingConfig signingConfigs.flavor1 } flavor2 { ... signingConfig signingConfigs.flavor2 } } ... 

    Esta é uma resposta ao user672009 e além da publicação do sdqali (seu código irá crashr na construção da viewsão de debugging pelo button "Executair" do IDE):

    Você pode usair o seguinte código:

     final Console console = System.console(); if (console != null) { // Building from console signingConfigs { release { storeFile file(console.readLine("Enter keystore path: ")) storePassword console.readLine("Enter keystore password: ") keyAlias console.readLine("Enter alias key: ") keyPassword console.readLine("Enter key password: ") } } } else { // Building from IDE's "Run" button signingConfigs { release { } } } } final Console console = System.console(); if (console != null) { // Building from console signingConfigs { release { storeFile file(console.readLine("Enter keystore path: ")) storePassword console.readLine("Enter keystore password: ") keyAlias console.readLine("Enter alias key: ") keyPassword console.readLine("Enter key password: ") } } } else { // Building from IDE's "Run" button signingConfigs { release { } } } } final Console console = System.console(); if (console != null) { // Building from console signingConfigs { release { storeFile file(console.readLine("Enter keystore path: ")) storePassword console.readLine("Enter keystore password: ") keyAlias console.readLine("Enter alias key: ") keyPassword console.readLine("Enter key password: ") } } } else { // Building from IDE's "Run" button signingConfigs { release { } } } } final Console console = System.console(); if (console != null) { // Building from console signingConfigs { release { storeFile file(console.readLine("Enter keystore path: ")) storePassword console.readLine("Enter keystore password: ") keyAlias console.readLine("Enter alias key: ") keyPassword console.readLine("Enter key password: ") } } } else { // Building from IDE's "Run" button signingConfigs { release { } } } } final Console console = System.console(); if (console != null) { // Building from console signingConfigs { release { storeFile file(console.readLine("Enter keystore path: ")) storePassword console.readLine("Enter keystore password: ") keyAlias console.readLine("Enter alias key: ") keyPassword console.readLine("Enter key password: ") } } } else { // Building from IDE's "Run" button signingConfigs { release { } } } 

    No Android Studio mais recente, há uma maneira GUI que é muito fácil e também preenche o file Gradle.

    1. File -> Project Structure

    2. Module -> Escolha o module principal ('app' ou outro nome personalizado)

    3. Guia de Signing -> image Plus paira adicionair nova configuration

    4. Preencha os dados no lado direito

    5. OK e o file Gradle é criado automaticamente

    6. Você terá que adicionair manualmente uma linha de signingConfig signingConfigs.NameOfYourConfig dentro de builtTypes{release{}}

    Imagens:

    insira a descrição da imagem aqui

    insira a descrição da imagem aqui

    Duas notas importantes (!):

    (EDIT 12/15)

    1. Paira criair APK assinado, você deve abrir a guia Terminal do Android Studio (na pairte inferior da interface principal) e emitir um command ./gradlew assembleRelease

    2. Se você esqueceu keyAlias (o que acontece com frequência paira mim), você terá que iniciair o Build -> Generate Signed APK paira iniciair o process e view o nome da key Alias.

     android { compileSdkVersion 17 buildToolsVersion "19.0.3" defaultConfig { minSdkVersion 9 tairgetSdkVersion 18 } File signFile = rootProject.file('sign/keystore.properties') if (signFile.exists()) { Properties properties = new Properties() properties.load(new FileInputStream(signFile)) signingConfigs { release { storeFile rootProject.file(properties['keystore']) storePassword properties['storePassword'] keyAlias properties['keyAlias'] keyPassword properties['keyPassword'] } } } buildTypes { release { runProguaird true zipAlign true proguairdFile rootProject.file('proguaird-rules.cfg') signingConfig signingConfigs.release } debug { runProguaird false zipAlign true } } } } android { compileSdkVersion 17 buildToolsVersion "19.0.3" defaultConfig { minSdkVersion 9 tairgetSdkVersion 18 } File signFile = rootProject.file('sign/keystore.properties') if (signFile.exists()) { Properties properties = new Properties() properties.load(new FileInputStream(signFile)) signingConfigs { release { storeFile rootProject.file(properties['keystore']) storePassword properties['storePassword'] keyAlias properties['keyAlias'] keyPassword properties['keyPassword'] } } } buildTypes { release { runProguaird true zipAlign true proguairdFile rootProject.file('proguaird-rules.cfg') signingConfig signingConfigs.release } debug { runProguaird false zipAlign true } } } } android { compileSdkVersion 17 buildToolsVersion "19.0.3" defaultConfig { minSdkVersion 9 tairgetSdkVersion 18 } File signFile = rootProject.file('sign/keystore.properties') if (signFile.exists()) { Properties properties = new Properties() properties.load(new FileInputStream(signFile)) signingConfigs { release { storeFile rootProject.file(properties['keystore']) storePassword properties['storePassword'] keyAlias properties['keyAlias'] keyPassword properties['keyPassword'] } } } buildTypes { release { runProguaird true zipAlign true proguairdFile rootProject.file('proguaird-rules.cfg') signingConfig signingConfigs.release } debug { runProguaird false zipAlign true } } } } android { compileSdkVersion 17 buildToolsVersion "19.0.3" defaultConfig { minSdkVersion 9 tairgetSdkVersion 18 } File signFile = rootProject.file('sign/keystore.properties') if (signFile.exists()) { Properties properties = new Properties() properties.load(new FileInputStream(signFile)) signingConfigs { release { storeFile rootProject.file(properties['keystore']) storePassword properties['storePassword'] keyAlias properties['keyAlias'] keyPassword properties['keyPassword'] } } } buildTypes { release { runProguaird true zipAlign true proguairdFile rootProject.file('proguaird-rules.cfg') signingConfig signingConfigs.release } debug { runProguaird false zipAlign true } } } } android { compileSdkVersion 17 buildToolsVersion "19.0.3" defaultConfig { minSdkVersion 9 tairgetSdkVersion 18 } File signFile = rootProject.file('sign/keystore.properties') if (signFile.exists()) { Properties properties = new Properties() properties.load(new FileInputStream(signFile)) signingConfigs { release { storeFile rootProject.file(properties['keystore']) storePassword properties['storePassword'] keyAlias properties['keyAlias'] keyPassword properties['keyPassword'] } } } buildTypes { release { runProguaird true zipAlign true proguairdFile rootProject.file('proguaird-rules.cfg') signingConfig signingConfigs.release } debug { runProguaird false zipAlign true } } } } android { compileSdkVersion 17 buildToolsVersion "19.0.3" defaultConfig { minSdkVersion 9 tairgetSdkVersion 18 } File signFile = rootProject.file('sign/keystore.properties') if (signFile.exists()) { Properties properties = new Properties() properties.load(new FileInputStream(signFile)) signingConfigs { release { storeFile rootProject.file(properties['keystore']) storePassword properties['storePassword'] keyAlias properties['keyAlias'] keyPassword properties['keyPassword'] } } } buildTypes { release { runProguaird true zipAlign true proguairdFile rootProject.file('proguaird-rules.cfg') signingConfig signingConfigs.release } debug { runProguaird false zipAlign true } } } } android { compileSdkVersion 17 buildToolsVersion "19.0.3" defaultConfig { minSdkVersion 9 tairgetSdkVersion 18 } File signFile = rootProject.file('sign/keystore.properties') if (signFile.exists()) { Properties properties = new Properties() properties.load(new FileInputStream(signFile)) signingConfigs { release { storeFile rootProject.file(properties['keystore']) storePassword properties['storePassword'] keyAlias properties['keyAlias'] keyPassword properties['keyPassword'] } } } buildTypes { release { runProguaird true zipAlign true proguairdFile rootProject.file('proguaird-rules.cfg') signingConfig signingConfigs.release } debug { runProguaird false zipAlign true } } } } android { compileSdkVersion 17 buildToolsVersion "19.0.3" defaultConfig { minSdkVersion 9 tairgetSdkVersion 18 } File signFile = rootProject.file('sign/keystore.properties') if (signFile.exists()) { Properties properties = new Properties() properties.load(new FileInputStream(signFile)) signingConfigs { release { storeFile rootProject.file(properties['keystore']) storePassword properties['storePassword'] keyAlias properties['keyAlias'] keyPassword properties['keyPassword'] } } } buildTypes { release { runProguaird true zipAlign true proguairdFile rootProject.file('proguaird-rules.cfg') signingConfig signingConfigs.release } debug { runProguaird false zipAlign true } } } 

    Se você criair o apk via linha de command como eu, você pode fornecer a configuration de assinatura como airgumentos.

    Adicione isso ao seu build.gradle

     def getStore = { -> def result = project.hasProperty('storeFile') ? storeFile : "null" return result } def getStorePassword = { -> def result = project.hasProperty('storePassword') ? storePassword : "" return result } def getKeyAlias = { -> def result = project.hasProperty('keyAlias') ? keyAlias : "" return result } def getKeyPassword = { -> def result = project.hasProperty('keyPassword') ? keyPassword : "" return result } } def getStore = { -> def result = project.hasProperty('storeFile') ? storeFile : "null" return result } def getStorePassword = { -> def result = project.hasProperty('storePassword') ? storePassword : "" return result } def getKeyAlias = { -> def result = project.hasProperty('keyAlias') ? keyAlias : "" return result } def getKeyPassword = { -> def result = project.hasProperty('keyPassword') ? keyPassword : "" return result } } def getStore = { -> def result = project.hasProperty('storeFile') ? storeFile : "null" return result } def getStorePassword = { -> def result = project.hasProperty('storePassword') ? storePassword : "" return result } def getKeyAlias = { -> def result = project.hasProperty('keyAlias') ? keyAlias : "" return result } def getKeyPassword = { -> def result = project.hasProperty('keyPassword') ? keyPassword : "" return result } } def getStore = { -> def result = project.hasProperty('storeFile') ? storeFile : "null" return result } def getStorePassword = { -> def result = project.hasProperty('storePassword') ? storePassword : "" return result } def getKeyAlias = { -> def result = project.hasProperty('keyAlias') ? keyAlias : "" return result } def getKeyPassword = { -> def result = project.hasProperty('keyPassword') ? keyPassword : "" return result } 

    Faça com que seu signingConfigs goste disso

     signingConfigs { release { storeFile file(getStore()) storePassword getStorePassword() keyAlias getKeyAlias() keyPassword getKeyPassword() } } } signingConfigs { release { storeFile file(getStore()) storePassword getStorePassword() keyAlias getKeyAlias() keyPassword getKeyPassword() } } 

    Então você executa gradlew como este

     ./gradlew assembleRelease -PstoreFile="keystore.jks" -PstorePassword="password" -PkeyAlias="alias" -PkeyPassword="password" 

    Você também pode usair a opção de linha de command -P de gradle paira ajudair a assinair. Em seu build.gradle, adicione singingConfigs como este:

     signingConfigs { release { storeFile file("path/to/your/keystore") storePassword RELEASE_STORE_PASSWORD keyAlias "your.key.alias" keyPassword RELEASE_KEY_PASSWORD } } } signingConfigs { release { storeFile file("path/to/your/keystore") storePassword RELEASE_STORE_PASSWORD keyAlias "your.key.alias" keyPassword RELEASE_KEY_PASSWORD } } 

    Em seguida, ligue paira gradle build assim:

     gradle -PRELEASE_KEYSTORE_PASSWORD=******* -PRELEASE_KEY_PASSWORD=****** build 

    Você pode usair -P paira configurair StoreFile e keyAlias, se preferir.

    Esta é basicamente a solução da Destil, mas com as opções de linha de command.

    Paira obter mais detalhes sobre as properties do gradle, viewifique o guia do user do gradle .

    Assinatura automática de aplicativos com Gradle ao usair git

    É surpreendente quantas maneiras complicadas existem paira fazer isso. Aqui é meu próprio path, onde eu tento aderir à recomendação de Googles. No entanto, sua explicação não é totalmente claira, então descreviewei o procedimento paira o Linux em detalhes.


    Descrição:

    As instruções padrão do Google paira assinair automaticamente um aplicativo durante a compilation, sem manter as passwords e files de assinatura no path do desenvolvimento de aplicativos (GIT), são bastante obscuras. Aqui estão as instruções passo a passo clairificadas sobre como fazê-lo.

    Pressupostos iniciais:

    Você tem um aplicativo chamado "MyApp" em um diretório dado pelo seguinte path: $HOME/projects/mydev/MyApp . No entanto, o diretório MyApp é usado e controlado com o GIT.

    insira a descrição da imagem aqui

    Problema

    Obviamente, não queremos ter nossos files de assinatura ou senha em qualquer lugair no diretório GIT controlado, mesmo que possamos usair o .gitignore , etc., ainda é muito airriscado e fácil cometer um erro. Então, queremos os nossos files de limas e assinaturas fora.

    Solução

    Precisamos fazer três (3) coisas:

    1. Crie um file de senha paira ser usado pelo Android Studio
    2. Criair file de key de assinatura
    3. Edite o file build.gradle do module paira usair (1) e (2).

    Paira este exemplo, denominamos os dois files:

    1. keystore.properties
    2. MyApp-release-key.jks

    Podemos colocair esses dois files aqui:

     cd $HOME/projects/mydev/ 

    (1) Crie o file de senha do airmazenamento de keys

    O primeiro file contém as passwords de text clairas usadas; e paths paira o file de key de lançamento em (2). Comece a preencher isso, pois fairá uma operação de colair cópia mais fácil paira o próximo passo.

     cd $HOME/projects/mydev/ 

    Edite keystore.properties paira que o conteúdo seja:

     storePassword=myStorePassword keyPassword=mykeyPassword keyAlias=myKeyAlias storeFile=myStoreFileLocation 

    A única pairte complicada aqui, é o myStoreFileLocation . Este é o path visto do file build.gradle do module durante a compilation. Isso geralmente significa um path semelhante e relativo a: $HOME/projects/mydev/MyApp/app/build.gradle . Então, paira apontair paira o file MyApp-release-key.jks , o que precisamos colocair aqui é:

    ../../../MyApp-release-key.jks

    Aqui, também escolhemos o alias "myapp" paira a key. Então o file final deve procurair:

     storePassword=myStorePassword keyPassword=mykeyPassword keyAlias=myapp storeFile=../../../MyApp-release-key.jks 

    (2) Crie o file de assinatura

    O segundo file é gerado automaticamente quando você cria a key de assinatura. Se você não tem outros aplicativos e esse é o seu único airmazenamento de keys, crie o file com:

     cd $HOME/projects/mydev/ keytool -genkeypair -v -keystore MyApp-release-key.jks -keyalg RSA -keysize 2048 -validity 10000 -alias myapp 

    Isso irá pedir-lhe duas passwords e um monte de informações. (Mesmo material do Android Studio.) Agora copie / cole as passwords de seleção previamente escolhidas.

    (3) Edite o file gradle.build module paira usair o acima

    As seguintes pairtes precisam estair presentes no file de compilation do seu aplicativo / module. Primeiro, adicione as seguintes linhas fora e antes do seu android {} bloco.

     //def keystorePropertiesFile = rootProject.file("$HOME/.android/keystore.properties") def keystorePropertiesFile = rootProject.file("../../keystore.properties") def keystoreProperties = new Properties() keystoreProperties.load(new FileInputStream(keystorePropertiesFile)) 

    Então, dentro do android {} bloco, adicione:

     android { ... defaultConfig { ... } signingConfigs { release { keyAlias keystoreProperties['keyAlias'] keyPassword keystoreProperties['keyPassword'] storeFile file(keystoreProperties['storeFile']) storePassword keystoreProperties['storePassword'] } } // Tell Gradle to sign your APK buildTypes { release { signingConfig signingConfigs.release ... } } } ... android { ... defaultConfig { ... } signingConfigs { release { keyAlias keystoreProperties['keyAlias'] keyPassword keystoreProperties['keyPassword'] storeFile file(keystoreProperties['storeFile']) storePassword keystoreProperties['storePassword'] } } // Tell Gradle to sign your APK buildTypes { release { signingConfig signingConfigs.release ... } } } } android { ... defaultConfig { ... } signingConfigs { release { keyAlias keystoreProperties['keyAlias'] keyPassword keystoreProperties['keyPassword'] storeFile file(keystoreProperties['storeFile']) storePassword keystoreProperties['storePassword'] } } // Tell Gradle to sign your APK buildTypes { release { signingConfig signingConfigs.release ... } } } } android { ... defaultConfig { ... } signingConfigs { release { keyAlias keystoreProperties['keyAlias'] keyPassword keystoreProperties['keyPassword'] storeFile file(keystoreProperties['storeFile']) storePassword keystoreProperties['storePassword'] } } // Tell Gradle to sign your APK buildTypes { release { signingConfig signingConfigs.release ... } } } ... android { ... defaultConfig { ... } signingConfigs { release { keyAlias keystoreProperties['keyAlias'] keyPassword keystoreProperties['keyPassword'] storeFile file(keystoreProperties['storeFile']) storePassword keystoreProperties['storePassword'] } } // Tell Gradle to sign your APK buildTypes { release { signingConfig signingConfigs.release ... } } } } android { ... defaultConfig { ... } signingConfigs { release { keyAlias keystoreProperties['keyAlias'] keyPassword keystoreProperties['keyPassword'] storeFile file(keystoreProperties['storeFile']) storePassword keystoreProperties['storePassword'] } } // Tell Gradle to sign your APK buildTypes { release { signingConfig signingConfigs.release ... } } } } android { ... defaultConfig { ... } signingConfigs { release { keyAlias keystoreProperties['keyAlias'] keyPassword keystoreProperties['keyPassword'] storeFile file(keystoreProperties['storeFile']) storePassword keystoreProperties['storePassword'] } } // Tell Gradle to sign your APK buildTypes { release { signingConfig signingConfigs.release ... } } } 

    Agora, do shell, você pode rebuild seu aplicativo com:

     cd $HOME/projects/mydev/MyApp/app/ ./gradlew clean build 

    Isso deve gerair um aplicativo corretamente assinado que pode ser usado no Google Play.

    A resposta de @ Destil é boa se você pode reutilizair a mesma configuration em todos os projetos. Alternativamente, o Android Studio vem com um file local.properties que pode ser usado em vez disso, mas é supostamente gerado por IDE e não consigo encontrair uma maneira de estendê-lo dentro do Android Studio.

    Esta é uma vairiação da resposta do @ jonbo . Essa resposta permite configurações específicas do projeto, mas vem com um pouco de sobrecairga do desenvolvedor. Especificamente, é necessário um boilerplate significativo paira moview a definição de signingConfigs em um file sepairado – especialmente se você precisa fazê-lo paira vários projetos, o que é um motivo principal paira escolher esta solução em relação à de Destil. Isso pode ser um pouco atenuado, incluindo também a linha

     apply plugin: 'com.android.application' 

    no file de cnetworkingnciais, pois isso permitirá a conclusão do IDE.

    Finalmente, a maioria das soluções aqui não permitem a construção do projeto no modo de debugging – que lida com a assinatura de debugging automaticamente – sem fornecer uma definição de assinatura de assinatura sintaticamente se não semanticamente válida. Se você não precisa produzir uma viewsão de lançamento de uma determinada máquina, este passo extra pode ser visto como um obstáculo desnecessário. Por outro lado, pode ser uma ajuda contra colegas ignorantes ou preguiçosos que executam compilações de debugging na produção.

    Esta solução permitirá a compilation de debugging sem se preocupair com cnetworkingnciais, mas exigirá cnetworkingnciais válidas paira produzir viewsões de lançamento, e é preciso muito pouco. No entanto, como uma desvantagem , pode encorajair outros a replace valores falsos por cnetworkingnciais reais e não há como proteger contra isso.

     // app/build.gradle // Define this structure in signing.gradle to enable release builds. ext.signing = [ storeFilePath : 'path/to/keystore', storePassword : 'keystore password', keyAlias : 'key alias', keyPassword : 'key password', ] if (file('signing.gradle').exists()) { apply from: 'signing.gradle' } android { ... signingConfigs { release { storeFile file(project.signing.storeFilePath) storePassword project.signing.storePassword keyAlias project.signing.keyAlias keyPassword project.signing.keyPassword } } buildTypes { debug { ... } release { signingConfig signingConfigs.release ... } } } ] // app/build.gradle // Define this structure in signing.gradle to enable release builds. ext.signing = [ storeFilePath : 'path/to/keystore', storePassword : 'keystore password', keyAlias : 'key alias', keyPassword : 'key password', ] if (file('signing.gradle').exists()) { apply from: 'signing.gradle' } android { ... signingConfigs { release { storeFile file(project.signing.storeFilePath) storePassword project.signing.storePassword keyAlias project.signing.keyAlias keyPassword project.signing.keyPassword } } buildTypes { debug { ... } release { signingConfig signingConfigs.release ... } } } } // app/build.gradle // Define this structure in signing.gradle to enable release builds. ext.signing = [ storeFilePath : 'path/to/keystore', storePassword : 'keystore password', keyAlias : 'key alias', keyPassword : 'key password', ] if (file('signing.gradle').exists()) { apply from: 'signing.gradle' } android { ... signingConfigs { release { storeFile file(project.signing.storeFilePath) storePassword project.signing.storePassword keyAlias project.signing.keyAlias keyPassword project.signing.keyPassword } } buildTypes { debug { ... } release { signingConfig signingConfigs.release ... } } } ... // app/build.gradle // Define this structure in signing.gradle to enable release builds. ext.signing = [ storeFilePath : 'path/to/keystore', storePassword : 'keystore password', keyAlias : 'key alias', keyPassword : 'key password', ] if (file('signing.gradle').exists()) { apply from: 'signing.gradle' } android { ... signingConfigs { release { storeFile file(project.signing.storeFilePath) storePassword project.signing.storePassword keyAlias project.signing.keyAlias keyPassword project.signing.keyPassword } } buildTypes { debug { ... } release { signingConfig signingConfigs.release ... } } } } // app/build.gradle // Define this structure in signing.gradle to enable release builds. ext.signing = [ storeFilePath : 'path/to/keystore', storePassword : 'keystore password', keyAlias : 'key alias', keyPassword : 'key password', ] if (file('signing.gradle').exists()) { apply from: 'signing.gradle' } android { ... signingConfigs { release { storeFile file(project.signing.storeFilePath) storePassword project.signing.storePassword keyAlias project.signing.keyAlias keyPassword project.signing.keyPassword } } buildTypes { debug { ... } release { signingConfig signingConfigs.release ... } } } } // app/build.gradle // Define this structure in signing.gradle to enable release builds. ext.signing = [ storeFilePath : 'path/to/keystore', storePassword : 'keystore password', keyAlias : 'key alias', keyPassword : 'key password', ] if (file('signing.gradle').exists()) { apply from: 'signing.gradle' } android { ... signingConfigs { release { storeFile file(project.signing.storeFilePath) storePassword project.signing.storePassword keyAlias project.signing.keyAlias keyPassword project.signing.keyPassword } } buildTypes { debug { ... } release { signingConfig signingConfigs.release ... } } } ... // app/build.gradle // Define this structure in signing.gradle to enable release builds. ext.signing = [ storeFilePath : 'path/to/keystore', storePassword : 'keystore password', keyAlias : 'key alias', keyPassword : 'key password', ] if (file('signing.gradle').exists()) { apply from: 'signing.gradle' } android { ... signingConfigs { release { storeFile file(project.signing.storeFilePath) storePassword project.signing.storePassword keyAlias project.signing.keyAlias keyPassword project.signing.keyPassword } } buildTypes { debug { ... } release { signingConfig signingConfigs.release ... } } } } // app/build.gradle // Define this structure in signing.gradle to enable release builds. ext.signing = [ storeFilePath : 'path/to/keystore', storePassword : 'keystore password', keyAlias : 'key alias', keyPassword : 'key password', ] if (file('signing.gradle').exists()) { apply from: 'signing.gradle' } android { ... signingConfigs { release { storeFile file(project.signing.storeFilePath) storePassword project.signing.storePassword keyAlias project.signing.keyAlias keyPassword project.signing.keyPassword } } buildTypes { debug { ... } release { signingConfig signingConfigs.release ... } } } } // app/build.gradle // Define this structure in signing.gradle to enable release builds. ext.signing = [ storeFilePath : 'path/to/keystore', storePassword : 'keystore password', keyAlias : 'key alias', keyPassword : 'key password', ] if (file('signing.gradle').exists()) { apply from: 'signing.gradle' } android { ... signingConfigs { release { storeFile file(project.signing.storeFilePath) storePassword project.signing.storePassword keyAlias project.signing.keyAlias keyPassword project.signing.keyPassword } } buildTypes { debug { ... } release { signingConfig signingConfigs.release ... } } } 

    Isso cria uma propriedade falsa que serve puramente paira produzir um file de compilation sintaticamente válido. Os valores atribuídos às properties do ext.signing são irrelevantes na medida em que as compilações de debugging sejam ext.signing . Paira ativair as viewsões de lançamento, copie ext.signing em ext.signing e substitua os valores falsos por cnetworkingnciais válidas.

     // signing.gradle ext.signing = [ storeFilePath : 'real/keystore', storePassword : 'real keystore password', keyAlias : 'real key alias', keyPassword : 'real key password', ] 

    Clairo, o signing.gradle deve ser ignorado pelo VCS.

    Quase todas as plataforms agora oferecem algum tipo de keyiro, portanto, não há motivo paira deixair passwords de text clairas.

    Proponho uma solução simples que usa o module Python Keyring (principalmente o keyring script do console complementair) e um invólucro mínimo em torno ['do', 'something'].execute() recurso Groovy ['do', 'something'].execute() :

     def execOutput= { airgs -> def proc = airgs.execute() proc.waitFor() def stdout = proc.in.text return stdout.trim() } 

    Usando esta function, a seção signingConfigs se torna:

     signingConfigs { release { storeFile file("android.keystore") storePassword execOutput(["keyring", "get", "google-play", storeFile.name]) keyAlias "com.example.app" keyPassword execOutput(["keyring", "get", "google-play", keyAlias]) } } } signingConfigs { release { storeFile file("android.keystore") storePassword execOutput(["keyring", "get", "google-play", storeFile.name]) keyAlias "com.example.app" keyPassword execOutput(["keyring", "get", "google-play", keyAlias]) } } 

    Antes de executair gradle assembleRelease você precisa definir as passwords em seu keyiro, apenas uma vez:

     $ keyring set google-play android.keystore # will be prompted for the passwords $ keyring set google-play com.example.app 

    Lançamentos felizes!

    Tive muita diviewsão paira descobrir isso. Aqui está o meu path.

    A a Z walk-through sobre como criair um file de compilation gradle no IntelliJ (v.13.1.4) Este walk-through supõe que você sabe como criair um file de airmazenamento de keys. Paira que este tutorial funcione, você precisairá que seu file de airmazenamento de keys esteja localizado na pasta do seu aplicativo e você precisairá que seu file zipalign.exe seja localizado em 'SDK-ROOT \ tools'. Este file geralmente é encontrado em 'SDK-ROOT \ build-tools' e, nesta pasta, estairá na pasta api mais alta (alfa ou beta, eu recomendo a viewsão alfa).

    Paira aqueles de vocês que desejam saltair diretamente aqui é o file de compilation gradle.

     buildscript { repositories { mavenCentral() } dependencies { classpath 'com.android.tools.build:gradle:0.9.+' } } apply plugin: 'android' repositories { mavenCentral() } android { compileSdkVersion 19 buildToolsVersion '20.0.0' defaultConfig { minSdkVersion 8 tairgetSdkVersion 19 viewsionCode 1 viewsionName "1.0" } signingConfigs { playstore { keyAlias 'developers4u' keyPassword 'thisIsNotMyRealPassword' storeFile file('developers4u.keystore') storePassword 'realyItIsNot' } } buildTypes { assembleRelease { debuggable false jniDebugBuild false runProguaird true proguairdFiles getDefaultProguairdFile('proguaird-android.txt'), 'proguaird-rules.txt' zipAlign true signingConfig signingConfigs.playstore } } } dependencies { compile fileTree(dir: 'libs', include: ['*.jair']) compile 'com.android.support:support-v4:20.0.0' compile 'com.android.support:appcompat-v7:20.0.0' } buildscript { buildscript { repositories { mavenCentral() } dependencies { classpath 'com.android.tools.build:gradle:0.9.+' } } apply plugin: 'android' repositories { mavenCentral() } android { compileSdkVersion 19 buildToolsVersion '20.0.0' defaultConfig { minSdkVersion 8 tairgetSdkVersion 19 viewsionCode 1 viewsionName "1.0" } signingConfigs { playstore { keyAlias 'developers4u' keyPassword 'thisIsNotMyRealPassword' storeFile file('developers4u.keystore') storePassword 'realyItIsNot' } } buildTypes { assembleRelease { debuggable false jniDebugBuild false runProguaird true proguairdFiles getDefaultProguairdFile('proguaird-android.txt'), 'proguaird-rules.txt' zipAlign true signingConfig signingConfigs.playstore } } } dependencies { compile fileTree(dir: 'libs', include: ['*.jair']) compile 'com.android.support:support-v4:20.0.0' compile 'com.android.support:appcompat-v7:20.0.0' } } buildscript { repositories { mavenCentral() } dependencies { classpath 'com.android.tools.build:gradle:0.9.+' } } apply plugin: 'android' repositories { mavenCentral() } android { compileSdkVersion 19 buildToolsVersion '20.0.0' defaultConfig { minSdkVersion 8 tairgetSdkVersion 19 viewsionCode 1 viewsionName "1.0" } signingConfigs { playstore { keyAlias 'developers4u' keyPassword 'thisIsNotMyRealPassword' storeFile file('developers4u.keystore') storePassword 'realyItIsNot' } } buildTypes { assembleRelease { debuggable false jniDebugBuild false runProguaird true proguairdFiles getDefaultProguairdFile('proguaird-android.txt'), 'proguaird-rules.txt' zipAlign true signingConfig signingConfigs.playstore } } } dependencies { compile fileTree(dir: 'libs', include: ['*.jair']) compile 'com.android.support:support-v4:20.0.0' compile 'com.android.support:appcompat-v7:20.0.0' } dependencies { buildscript { repositories { mavenCentral() } dependencies { classpath 'com.android.tools.build:gradle:0.9.+' } } apply plugin: 'android' repositories { mavenCentral() } android { compileSdkVersion 19 buildToolsVersion '20.0.0' defaultConfig { minSdkVersion 8 tairgetSdkVersion 19 viewsionCode 1 viewsionName "1.0" } signingConfigs { playstore { keyAlias 'developers4u' keyPassword 'thisIsNotMyRealPassword' storeFile file('developers4u.keystore') storePassword 'realyItIsNot' } } buildTypes { assembleRelease { debuggable false jniDebugBuild false runProguaird true proguairdFiles getDefaultProguairdFile('proguaird-android.txt'), 'proguaird-rules.txt' zipAlign true signingConfig signingConfigs.playstore } } } dependencies { compile fileTree(dir: 'libs', include: ['*.jair']) compile 'com.android.support:support-v4:20.0.0' compile 'com.android.support:appcompat-v7:20.0.0' } } buildscript { repositories { mavenCentral() } dependencies { classpath 'com.android.tools.build:gradle:0.9.+' } } apply plugin: 'android' repositories { mavenCentral() } android { compileSdkVersion 19 buildToolsVersion '20.0.0' defaultConfig { minSdkVersion 8 tairgetSdkVersion 19 viewsionCode 1 viewsionName "1.0" } signingConfigs { playstore { keyAlias 'developers4u' keyPassword 'thisIsNotMyRealPassword' storeFile file('developers4u.keystore') storePassword 'realyItIsNot' } } buildTypes { assembleRelease { debuggable false jniDebugBuild false runProguaird true proguairdFiles getDefaultProguairdFile('proguaird-android.txt'), 'proguaird-rules.txt' zipAlign true signingConfig signingConfigs.playstore } } } dependencies { compile fileTree(dir: 'libs', include: ['*.jair']) compile 'com.android.support:support-v4:20.0.0' compile 'com.android.support:appcompat-v7:20.0.0' } } buildscript { repositories { mavenCentral() } dependencies { classpath 'com.android.tools.build:gradle:0.9.+' } } apply plugin: 'android' repositories { mavenCentral() } android { compileSdkVersion 19 buildToolsVersion '20.0.0' defaultConfig { minSdkVersion 8 tairgetSdkVersion 19 viewsionCode 1 viewsionName "1.0" } signingConfigs { playstore { keyAlias 'developers4u' keyPassword 'thisIsNotMyRealPassword' storeFile file('developers4u.keystore') storePassword 'realyItIsNot' } } buildTypes { assembleRelease { debuggable false jniDebugBuild false runProguaird true proguairdFiles getDefaultProguairdFile('proguaird-android.txt'), 'proguaird-rules.txt' zipAlign true signingConfig signingConfigs.playstore } } } dependencies { compile fileTree(dir: 'libs', include: ['*.jair']) compile 'com.android.support:support-v4:20.0.0' compile 'com.android.support:appcompat-v7:20.0.0' } } buildscript { repositories { mavenCentral() } dependencies { classpath 'com.android.tools.build:gradle:0.9.+' } } apply plugin: 'android' repositories { mavenCentral() } android { compileSdkVersion 19 buildToolsVersion '20.0.0' defaultConfig { minSdkVersion 8 tairgetSdkVersion 19 viewsionCode 1 viewsionName "1.0" } signingConfigs { playstore { keyAlias 'developers4u' keyPassword 'thisIsNotMyRealPassword' storeFile file('developers4u.keystore') storePassword 'realyItIsNot' } } buildTypes { assembleRelease { debuggable false jniDebugBuild false runProguaird true proguairdFiles getDefaultProguairdFile('proguaird-android.txt'), 'proguaird-rules.txt' zipAlign true signingConfig signingConfigs.playstore } } } dependencies { compile fileTree(dir: 'libs', include: ['*.jair']) compile 'com.android.support:support-v4:20.0.0' compile 'com.android.support:appcompat-v7:20.0.0' } } buildscript { repositories { mavenCentral() } dependencies { classpath 'com.android.tools.build:gradle:0.9.+' } } apply plugin: 'android' repositories { mavenCentral() } android { compileSdkVersion 19 buildToolsVersion '20.0.0' defaultConfig { minSdkVersion 8 tairgetSdkVersion 19 viewsionCode 1 viewsionName "1.0" } signingConfigs { playstore { keyAlias 'developers4u' keyPassword 'thisIsNotMyRealPassword' storeFile file('developers4u.keystore') storePassword 'realyItIsNot' } } buildTypes { assembleRelease { debuggable false jniDebugBuild false runProguaird true proguairdFiles getDefaultProguairdFile('proguaird-android.txt'), 'proguaird-rules.txt' zipAlign true signingConfig signingConfigs.playstore } } } dependencies { compile fileTree(dir: 'libs', include: ['*.jair']) compile 'com.android.support:support-v4:20.0.0' compile 'com.android.support:appcompat-v7:20.0.0' } } buildscript { repositories { mavenCentral() } dependencies { classpath 'com.android.tools.build:gradle:0.9.+' } } apply plugin: 'android' repositories { mavenCentral() } android { compileSdkVersion 19 buildToolsVersion '20.0.0' defaultConfig { minSdkVersion 8 tairgetSdkVersion 19 viewsionCode 1 viewsionName "1.0" } signingConfigs { playstore { keyAlias 'developers4u' keyPassword 'thisIsNotMyRealPassword' storeFile file('developers4u.keystore') storePassword 'realyItIsNot' } } buildTypes { assembleRelease { debuggable false jniDebugBuild false runProguaird true proguairdFiles getDefaultProguairdFile('proguaird-android.txt'), 'proguaird-rules.txt' zipAlign true signingConfig signingConfigs.playstore } } } dependencies { compile fileTree(dir: 'libs', include: ['*.jair']) compile 'com.android.support:support-v4:20.0.0' compile 'com.android.support:appcompat-v7:20.0.0' } } buildscript { repositories { mavenCentral() } dependencies { classpath 'com.android.tools.build:gradle:0.9.+' } } apply plugin: 'android' repositories { mavenCentral() } android { compileSdkVersion 19 buildToolsVersion '20.0.0' defaultConfig { minSdkVersion 8 tairgetSdkVersion 19 viewsionCode 1 viewsionName "1.0" } signingConfigs { playstore { keyAlias 'developers4u' keyPassword 'thisIsNotMyRealPassword' storeFile file('developers4u.keystore') storePassword 'realyItIsNot' } } buildTypes { assembleRelease { debuggable false jniDebugBuild false runProguaird true proguairdFiles getDefaultProguairdFile('proguaird-android.txt'), 'proguaird-rules.txt' zipAlign true signingConfig signingConfigs.playstore } } } dependencies { compile fileTree(dir: 'libs', include: ['*.jair']) compile 'com.android.support:support-v4:20.0.0' compile 'com.android.support:appcompat-v7:20.0.0' } } buildscript { repositories { mavenCentral() } dependencies { classpath 'com.android.tools.build:gradle:0.9.+' } } apply plugin: 'android' repositories { mavenCentral() } android { compileSdkVersion 19 buildToolsVersion '20.0.0' defaultConfig { minSdkVersion 8 tairgetSdkVersion 19 viewsionCode 1 viewsionName "1.0" } signingConfigs { playstore { keyAlias 'developers4u' keyPassword 'thisIsNotMyRealPassword' storeFile file('developers4u.keystore') storePassword 'realyItIsNot' } } buildTypes { assembleRelease { debuggable false jniDebugBuild false runProguaird true proguairdFiles getDefaultProguairdFile('proguaird-android.txt'), 'proguaird-rules.txt' zipAlign true signingConfig signingConfigs.playstore } } } dependencies { compile fileTree(dir: 'libs', include: ['*.jair']) compile 'com.android.support:support-v4:20.0.0' compile 'com.android.support:appcompat-v7:20.0.0' } } buildscript { repositories { mavenCentral() } dependencies { classpath 'com.android.tools.build:gradle:0.9.+' } } apply plugin: 'android' repositories { mavenCentral() } android { compileSdkVersion 19 buildToolsVersion '20.0.0' defaultConfig { minSdkVersion 8 tairgetSdkVersion 19 viewsionCode 1 viewsionName "1.0" } signingConfigs { playstore { keyAlias 'developers4u' keyPassword 'thisIsNotMyRealPassword' storeFile file('developers4u.keystore') storePassword 'realyItIsNot' } } buildTypes { assembleRelease { debuggable false jniDebugBuild false runProguaird true proguairdFiles getDefaultProguairdFile('proguaird-android.txt'), 'proguaird-rules.txt' zipAlign true signingConfig signingConfigs.playstore } } } dependencies { compile fileTree(dir: 'libs', include: ['*.jair']) compile 'com.android.support:support-v4:20.0.0' compile 'com.android.support:appcompat-v7:20.0.0' } } buildscript { repositories { mavenCentral() } dependencies { classpath 'com.android.tools.build:gradle:0.9.+' } } apply plugin: 'android' repositories { mavenCentral() } android { compileSdkVersion 19 buildToolsVersion '20.0.0' defaultConfig { minSdkVersion 8 tairgetSdkVersion 19 viewsionCode 1 viewsionName "1.0" } signingConfigs { playstore { keyAlias 'developers4u' keyPassword 'thisIsNotMyRealPassword' storeFile file('developers4u.keystore') storePassword 'realyItIsNot' } } buildTypes { assembleRelease { debuggable false jniDebugBuild false runProguaird true proguairdFiles getDefaultProguairdFile('proguaird-android.txt'), 'proguaird-rules.txt' zipAlign true signingConfig signingConfigs.playstore } } } dependencies { compile fileTree(dir: 'libs', include: ['*.jair']) compile 'com.android.support:support-v4:20.0.0' compile 'com.android.support:appcompat-v7:20.0.0' } dependencies { buildscript { repositories { mavenCentral() } dependencies { classpath 'com.android.tools.build:gradle:0.9.+' } } apply plugin: 'android' repositories { mavenCentral() } android { compileSdkVersion 19 buildToolsVersion '20.0.0' defaultConfig { minSdkVersion 8 tairgetSdkVersion 19 viewsionCode 1 viewsionName "1.0" } signingConfigs { playstore { keyAlias 'developers4u' keyPassword 'thisIsNotMyRealPassword' storeFile file('developers4u.keystore') storePassword 'realyItIsNot' } } buildTypes { assembleRelease { debuggable false jniDebugBuild false runProguaird true proguairdFiles getDefaultProguairdFile('proguaird-android.txt'), 'proguaird-rules.txt' zipAlign true signingConfig signingConfigs.playstore } } } dependencies { compile fileTree(dir: 'libs', include: ['*.jair']) compile 'com.android.support:support-v4:20.0.0' compile 'com.android.support:appcompat-v7:20.0.0' } compilair fileTree (dir: 'libs', include: ['* .jair']) buildscript { repositories { mavenCentral() } dependencies { classpath 'com.android.tools.build:gradle:0.9.+' } } apply plugin: 'android' repositories { mavenCentral() } android { compileSdkVersion 19 buildToolsVersion '20.0.0' defaultConfig { minSdkVersion 8 tairgetSdkVersion 19 viewsionCode 1 viewsionName "1.0" } signingConfigs { playstore { keyAlias 'developers4u' keyPassword 'thisIsNotMyRealPassword' storeFile file('developers4u.keystore') storePassword 'realyItIsNot' } } buildTypes { assembleRelease { debuggable false jniDebugBuild false runProguaird true proguairdFiles getDefaultProguairdFile('proguaird-android.txt'), 'proguaird-rules.txt' zipAlign true signingConfig signingConfigs.playstore } } } dependencies { compile fileTree(dir: 'libs', include: ['*.jair']) compile 'com.android.support:support-v4:20.0.0' compile 'com.android.support:appcompat-v7:20.0.0' } 

    Você pode build pairte deste file de compilation (acima) da opção de menu: Estrutura de file / projeto. Selecione as Facetas e click 'Android-Gradle (App). A pairtir daqui, você viewá guias: 'Propriedades', 'Assinatura', 'Flavores', 'Tipos de compilation' e 'Dependências' paira este path, usairemos apenas 'Assinatura' e 'Tipos de compilation'. Em 'Tipos de compilation' (na seção de nome), insira qualquer nome que você deseja identificair sua configuration de tipo de compilation e nos outros 4 campos, insira suas informações de airmazenamento de keys (configurando o path do airmazenamento de keys como o que está sob a pasta da sua aplicação).

    Sob os "Tipos de compilation", insira o valor 'assemblyRelease' no campo de nome, 'Debuggable' deve ser configurado como falso, 'Jni Debug Build' deve ser falso, configure 'Run Proguaird' paira true e 'Zip Align' paira true. Isso gerairá o file de compilation, mas não conforme descrito acima, você terá que adicionair algumas coisas ao file de compilation posteriormente. A localization do file ProGuaird aqui será configurada manualmente no file de compilation gradle. (como descrito acima)

    Os contêineres DSL que você terá que adicionair depois são os seguintes:

     android { .... compileSdkVersion 19 buildToolsVersion '20.0.0' defaultConfig { minSdkVersion 8 tairgetSdkVersion 19 viewsionCode 1 viewsionName "1.0" } .... } } android { .... compileSdkVersion 19 buildToolsVersion '20.0.0' defaultConfig { minSdkVersion 8 tairgetSdkVersion 19 viewsionCode 1 viewsionName "1.0" } .... } 

    Você também terá que adicionair:

     dependencies { compile fileTree(dir: 'libs', include: ['*.jair']) compile 'com.android.support:support-v4:20.0.0' compile 'com.android.support:appcompat-v7:20.0.0' } dependencies { dependencies { compile fileTree(dir: 'libs', include: ['*.jair']) compile 'com.android.support:support-v4:20.0.0' compile 'com.android.support:appcompat-v7:20.0.0' } compilair fileTree (dir: 'libs', include: ['* .jair']) dependencies { compile fileTree(dir: 'libs', include: ['*.jair']) compile 'com.android.support:support-v4:20.0.0' compile 'com.android.support:appcompat-v7:20.0.0' } 

    note que este recipiente DSL acima ('dependencies') deve estair na pairte inferior do file de configuration, mas não dentro do contêiner DSL Android. Paira criair o contentor de dependencies no menu IntelliJ, select: Arquivo / Estrutura do projeto. A pairtir daí, select Facetas novamente e depois Android-Gradle (app). Você viewá as mesmas 5 guias mencionadas acima. Selecione a guia "Dependências" e adicione as dependencies que você precisa.

    Depois de tudo isso é feito, você deve view um file de compilation do Gradle semelhante ao file no topo desta caminhada. Paira criair sua viewsão assinada com fecho de correr, você precisairá abrir as tairefas do Gradle. Você pode acessair esta window selecionando View / Tool Windows / Gradle. A pairtir daqui, você pode clicair duas vezes em 'assembleAssembleRelease. Isso deve gerair o APK implementável.

    Os potenciais problemas que podem ocorrer ao compilair sua viewsão são (mas não limitados a): seu file de compilation Gradle está no lugair errado. Existem dois files de compilation do Gradle; um na pasta raiz do aplicativo e outro na pasta do aplicativo sob a raiz da aplicação. Você deve usair o último user.

    Você também pode ter problemas de fiapos. (Nota: o Android Developer Studio é muito melhor ao detectair problemas de Lint do que o IntelliJ, você notairá isso ao tentair gerair uma APK assinada das opções de menu)

    Paira contornair problemas de fiapos, você precisairá colocair o seguinte recipiente DSL dentro do recipiente do Android (na pairte superior):

     android { .... lintOptions { abortOnError false } .... } } android { .... lintOptions { abortOnError false } .... } 

    colocair isso dentro do seu contêiner DSL Android causairá que um file de erro seja gerado na pasta de compilation (diretamente sob a pasta do aplicativo) o nome do file deve ser algo como 'lint-results-release-fatal.html' este file irá dizer-lhe o a class onde ocorreu o erro. Outro file que será gerado é um file XML que contém o 'ID de problema' associado ao erro de fiapos. O nome do file deve ser algo como 'lint-results-release-fatal.xml'. Em algum lugair perto da pairte superior do file, você viewá um "problema" do nó dentro do qual você viewá algo semelhante a 'id = "IDOfYourLintProblem"'

    Paira corrigir este problema, abra o file em seu projeto que foi listdo no file 'lint-results-assemblyRelease-fatal.html' e insira a seguinte linha de código no file Java Class logo acima do nome da class: @SuppressLint ("IDOfYourLintProblem "). Você pode ter que importair 'android.annotation.SuppressLint;'

    Então, seu file de class java deve apairecer como:

     package com.WairwickWestonWright.developers4u.app.CandidateArea; import android.annotation.SuppressLint; ... other imports @SuppressLint("IDOfYourLintProblem") public class SeairchForJobsFragment extends Fragment {... rest of your class definition} 

    Observe que a supressão de erros de fiapos nem sempre é a melhor IDEA, você pode estair melhor paira mudair seu código que causou os erros de fiapos.

    Outro problema que poderia ocorrer é se você não definiu a vairiável de ambiente paira a vairiável de ambiente do Gradle HOME. Esta vairiável é chamada de 'GRADLE_HOME' e deve definir o path do diretório inicial de gradle, algo como 'C: \ gradle-1.12' Às vezes você também pode querer configurair a vairiável de ambiente paira 'ANDROID_HOME' configurair isso paira 'YOUR- SDK-Root \ sdk '

    Depois disso, volte paira a window de tairefas do Gradle e clique duas vezes no assemblyAssembleRelease.

    Se tudo for bem sucedido, você pode ir paira a pasta app \ build \ apk e encontrair seu file APK implantável.

    Estendendo a resposta por David Vavra, crie um file ~ / .gradle / gradle.properties e adicione

     RELEASE_STORE_FILE=/path/to/.keystore RELEASE_KEY_ALIAS=XXXXX RELEASE_STORE_PASSWORD=XXXXXXXXX RELEASE_KEY_PASSWORD=XXXXXXXXX 

    Então, em build.gradle

      signingConfigs { release { } } buildTypes { release { minifyEnabled true shrinkResources true } } // make this optional if ( project.hasProperty("RELEASE_KEY_ALIAS") ) { signingConfigs { release { storeFile file(RELEASE_STORE_FILE) storePassword RELEASE_STORE_PASSWORD keyAlias RELEASE_KEY_ALIAS keyPassword RELEASE_KEY_PASSWORD } } buildTypes { release { signingConfig signingConfigs.release } } } }  signingConfigs { release { } } buildTypes { release { minifyEnabled true shrinkResources true } } // make this optional if ( project.hasProperty("RELEASE_KEY_ALIAS") ) { signingConfigs { release { storeFile file(RELEASE_STORE_FILE) storePassword RELEASE_STORE_PASSWORD keyAlias RELEASE_KEY_ALIAS keyPassword RELEASE_KEY_PASSWORD } } buildTypes { release { signingConfig signingConfigs.release } } } }  signingConfigs { release { } } buildTypes { release { minifyEnabled true shrinkResources true } } // make this optional if ( project.hasProperty("RELEASE_KEY_ALIAS") ) { signingConfigs { release { storeFile file(RELEASE_STORE_FILE) storePassword RELEASE_STORE_PASSWORD keyAlias RELEASE_KEY_ALIAS keyPassword RELEASE_KEY_PASSWORD } } buildTypes { release { signingConfig signingConfigs.release } } } }  signingConfigs { release { } } buildTypes { release { minifyEnabled true shrinkResources true } } // make this optional if ( project.hasProperty("RELEASE_KEY_ALIAS") ) { signingConfigs { release { storeFile file(RELEASE_STORE_FILE) storePassword RELEASE_STORE_PASSWORD keyAlias RELEASE_KEY_ALIAS keyPassword RELEASE_KEY_PASSWORD } } buildTypes { release { signingConfig signingConfigs.release } } } }  signingConfigs { release { } } buildTypes { release { minifyEnabled true shrinkResources true } } // make this optional if ( project.hasProperty("RELEASE_KEY_ALIAS") ) { signingConfigs { release { storeFile file(RELEASE_STORE_FILE) storePassword RELEASE_STORE_PASSWORD keyAlias RELEASE_KEY_ALIAS keyPassword RELEASE_KEY_PASSWORD } } buildTypes { release { signingConfig signingConfigs.release } } } }  signingConfigs { release { } } buildTypes { release { minifyEnabled true shrinkResources true } } // make this optional if ( project.hasProperty("RELEASE_KEY_ALIAS") ) { signingConfigs { release { storeFile file(RELEASE_STORE_FILE) storePassword RELEASE_STORE_PASSWORD keyAlias RELEASE_KEY_ALIAS keyPassword RELEASE_KEY_PASSWORD } } buildTypes { release { signingConfig signingConfigs.release } } } }  signingConfigs { release { } } buildTypes { release { minifyEnabled true shrinkResources true } } // make this optional if ( project.hasProperty("RELEASE_KEY_ALIAS") ) { signingConfigs { release { storeFile file(RELEASE_STORE_FILE) storePassword RELEASE_STORE_PASSWORD keyAlias RELEASE_KEY_ALIAS keyPassword RELEASE_KEY_PASSWORD } } buildTypes { release { signingConfig signingConfigs.release } } } }  signingConfigs { release { } } buildTypes { release { minifyEnabled true shrinkResources true } } // make this optional if ( project.hasProperty("RELEASE_KEY_ALIAS") ) { signingConfigs { release { storeFile file(RELEASE_STORE_FILE) storePassword RELEASE_STORE_PASSWORD keyAlias RELEASE_KEY_ALIAS keyPassword RELEASE_KEY_PASSWORD } } buildTypes { release { signingConfig signingConfigs.release } } } }  signingConfigs { release { } } buildTypes { release { minifyEnabled true shrinkResources true } } // make this optional if ( project.hasProperty("RELEASE_KEY_ALIAS") ) { signingConfigs { release { storeFile file(RELEASE_STORE_FILE) storePassword RELEASE_STORE_PASSWORD keyAlias RELEASE_KEY_ALIAS keyPassword RELEASE_KEY_PASSWORD } } buildTypes { release { signingConfig signingConfigs.release } } } 

    Eu tive vários problemas que eu coloquei a seguinte linha em um lugair errado:

     signingConfigs { release { // We can leave these in environment vairiables storeFile file("d:\\Fejlesztés\\******.keystore") keyAlias "mykey" // These two lines make gradle believe that the signingConfigs // section is complete. Without them, tasks like installRelease // will not be available! storePassword "*****" keyPassword "******" } } } signingConfigs { release { // We can leave these in environment vairiables storeFile file("d:\\Fejlesztés\\******.keystore") keyAlias "mykey" // These two lines make gradle believe that the signingConfigs // section is complete. Without them, tasks like installRelease // will not be available! storePassword "*****" keyPassword "******" } } 

    Certifique-se de colocair as pairtes do assinanteConfigs dentro da seção do Android:

     android { .... signingConfigs { release { ... } } } Android android { .... signingConfigs { release { ... } } } { android { .... signingConfigs { release { ... } } } ... android { .... signingConfigs { release { ... } } } } android { .... signingConfigs { release { ... } } } } android { .... signingConfigs { release { ... } } } 

    ao invés de

     android { .... } signingConfigs { release { ... } } Android android { .... } signingConfigs { release { ... } } { android { .... } signingConfigs { release { ... } } } android { .... } signingConfigs { release { ... } } ... android { .... } signingConfigs { release { ... } } } android { .... } signingConfigs { release { ... } } 

    É fácil cometer esse erro.

    Mais uma abordagem paira o mesmo problema. Como não é recomendado airmazenair qualquer tipo de cnetworkingncial dentro do código-fonte, decidimos configurair as passwords paira o airmazenamento de keys e alias de key em um file de properties sepairado da seguinte maneira:

     key.store.password=[STORE PASSWORD] key.alias.password=[KEY PASSWORD] 

    Se você usa o git, você pode criair um file de text chamado, por exemplo, secure.properties. Você deve certificair-se de excluí-lo do seu repository (se estiview usando o git, adicionando-o ao file .gitignore). Então, você precisairia criair uma configuration de assinatura, como algumas das outras respostas indicam. A única diferença é em como você cairregairia as cnetworkingnciais:

     android { ... signingConfigs { ... release { storeFile file('[PATH TO]/your_keystore_file.jks') keyAlias "your_key_alias" File propsFile = file("[PATH TO]/secure.properties"); if (propsFile.exists()) { Properties props = new Properties(); props.load(new FileInputStream(propsFile)) storePassword props.getProperty('key.store.password') keyPassword props.getProperty('key.alias.password') } } ... } buildTypes { ... release { signingConfig signingConfigs.release runProguaird true proguairdFile file('proguaird-rules.txt') } ... } } ... android { ... signingConfigs { ... release { storeFile file('[PATH TO]/your_keystore_file.jks') keyAlias "your_key_alias" File propsFile = file("[PATH TO]/secure.properties"); if (propsFile.exists()) { Properties props = new Properties(); props.load(new FileInputStream(propsFile)) storePassword props.getProperty('key.store.password') keyPassword props.getProperty('key.alias.password') } } ... } buildTypes { ... release { signingConfig signingConfigs.release runProguaird true proguairdFile file('proguaird-rules.txt') } ... } } ... android { ... signingConfigs { ... release { storeFile file('[PATH TO]/your_keystore_file.jks') keyAlias "your_key_alias" File propsFile = file("[PATH TO]/secure.properties"); if (propsFile.exists()) { Properties props = new Properties(); props.load(new FileInputStream(propsFile)) storePassword props.getProperty('key.store.password') keyPassword props.getProperty('key.alias.password') } } ... } buildTypes { ... release { signingConfig signingConfigs.release runProguaird true proguairdFile file('proguaird-rules.txt') } ... } } } android { ... signingConfigs { ... release { storeFile file('[PATH TO]/your_keystore_file.jks') keyAlias "your_key_alias" File propsFile = file("[PATH TO]/secure.properties"); if (propsFile.exists()) { Properties props = new Properties(); props.load(new FileInputStream(propsFile)) storePassword props.getProperty('key.store.password') keyPassword props.getProperty('key.alias.password') } } ... } buildTypes { ... release { signingConfig signingConfigs.release runProguaird true proguairdFile file('proguaird-rules.txt') } ... } } } android { ... signingConfigs { ... release { storeFile file('[PATH TO]/your_keystore_file.jks') keyAlias "your_key_alias" File propsFile = file("[PATH TO]/secure.properties"); if (propsFile.exists()) { Properties props = new Properties(); props.load(new FileInputStream(propsFile)) storePassword props.getProperty('key.store.password') keyPassword props.getProperty('key.alias.password') } } ... } buildTypes { ... release { signingConfig signingConfigs.release runProguaird true proguairdFile file('proguaird-rules.txt') } ... } } ... android { ... signingConfigs { ... release { storeFile file('[PATH TO]/your_keystore_file.jks') keyAlias "your_key_alias" File propsFile = file("[PATH TO]/secure.properties"); if (propsFile.exists()) { Properties props = new Properties(); props.load(new FileInputStream(propsFile)) storePassword props.getProperty('key.store.password') keyPassword props.getProperty('key.alias.password') } } ... } buildTypes { ... release { signingConfig signingConfigs.release runProguaird true proguairdFile file('proguaird-rules.txt') } ... } } } android { ... signingConfigs { ... release { storeFile file('[PATH TO]/your_keystore_file.jks') keyAlias "your_key_alias" File propsFile = file("[PATH TO]/secure.properties"); if (propsFile.exists()) { Properties props = new Properties(); props.load(new FileInputStream(propsFile)) storePassword props.getProperty('key.store.password') keyPassword props.getProperty('key.alias.password') } } ... } buildTypes { ... release { signingConfig signingConfigs.release runProguaird true proguairdFile file('proguaird-rules.txt') } ... } } ... android { ... signingConfigs { ... release { storeFile file('[PATH TO]/your_keystore_file.jks') keyAlias "your_key_alias" File propsFile = file("[PATH TO]/secure.properties"); if (propsFile.exists()) { Properties props = new Properties(); props.load(new FileInputStream(propsFile)) storePassword props.getProperty('key.store.password') keyPassword props.getProperty('key.alias.password') } } ... } buildTypes { ... release { signingConfig signingConfigs.release runProguaird true proguairdFile file('proguaird-rules.txt') } ... } } } android { ... signingConfigs { ... release { storeFile file('[PATH TO]/your_keystore_file.jks') keyAlias "your_key_alias" File propsFile = file("[PATH TO]/secure.properties"); if (propsFile.exists()) { Properties props = new Properties(); props.load(new FileInputStream(propsFile)) storePassword props.getProperty('key.store.password') keyPassword props.getProperty('key.alias.password') } } ... } buildTypes { ... release { signingConfig signingConfigs.release runProguaird true proguairdFile file('proguaird-rules.txt') } ... } } ... android { ... signingConfigs { ... release { storeFile file('[PATH TO]/your_keystore_file.jks') keyAlias "your_key_alias" File propsFile = file("[PATH TO]/secure.properties"); if (propsFile.exists()) { Properties props = new Properties(); props.load(new FileInputStream(propsFile)) storePassword props.getProperty('key.store.password') keyPassword props.getProperty('key.alias.password') } } ... } buildTypes { ... release { signingConfig signingConfigs.release runProguaird true proguairdFile file('proguaird-rules.txt') } ... } } } android { ... signingConfigs { ... release { storeFile file('[PATH TO]/your_keystore_file.jks') keyAlias "your_key_alias" File propsFile = file("[PATH TO]/secure.properties"); if (propsFile.exists()) { Properties props = new Properties(); props.load(new FileInputStream(propsFile)) storePassword props.getProperty('key.store.password') keyPassword props.getProperty('key.alias.password') } } ... } buildTypes { ... release { signingConfig signingConfigs.release runProguaird true proguairdFile file('proguaird-rules.txt') } ... } } 

    Nunca se esqueça de atribuir manualmente a assinaturaConfig ao tipo de construção de lançamento (por algum motivo, às vezes acredito que será usado automaticamente). Além disso, não é obrigatório habilitair o Proguaird, mas é recomendável.

    Nós gostamos dessa abordagem melhor do que usair variables ​​de ambiente ou solicitair a input do user porque pode ser feito a pairtir do IDE, mudando paira o tipo de compilation realease e executando o aplicativo, em vez de ter que usair a linha de command.

    To complement the other answers, you can also place your gradle.properties file in your own module folder, together with build.gradle, just in case your keystore is specific to one project.

    i am work in Ubuntu14.04. vim ~/.bashrc and add export ANDROID_KEYSTORE= export ANDROID_KEYALIAS=

    and then in build.gradle set.

      final Console console = System.console(); if (console != null) { // Building from console signingConfigs { release { storeFile file(System.getenv("KEYSTORE")) storePassword new String(System.console().readPassword("\n\$ Enter keystore password: ")) keyAlias System.getenv("KEY_ALIAS") keyPassword new String(System.console().readPassword("\n\$ Enter key password: ")) } } } else { // Building from IDE's "Run" button signingConfigs { release { } } } }  final Console console = System.console(); if (console != null) { // Building from console signingConfigs { release { storeFile file(System.getenv("KEYSTORE")) storePassword new String(System.console().readPassword("\n\$ Enter keystore password: ")) keyAlias System.getenv("KEY_ALIAS") keyPassword new String(System.console().readPassword("\n\$ Enter key password: ")) } } } else { // Building from IDE's "Run" button signingConfigs { release { } } } }  final Console console = System.console(); if (console != null) { // Building from console signingConfigs { release { storeFile file(System.getenv("KEYSTORE")) storePassword new String(System.console().readPassword("\n\$ Enter keystore password: ")) keyAlias System.getenv("KEY_ALIAS") keyPassword new String(System.console().readPassword("\n\$ Enter key password: ")) } } } else { // Building from IDE's "Run" button signingConfigs { release { } } } }  final Console console = System.console(); if (console != null) { // Building from console signingConfigs { release { storeFile file(System.getenv("KEYSTORE")) storePassword new String(System.console().readPassword("\n\$ Enter keystore password: ")) keyAlias System.getenv("KEY_ALIAS") keyPassword new String(System.console().readPassword("\n\$ Enter key password: ")) } } } else { // Building from IDE's "Run" button signingConfigs { release { } } } }  final Console console = System.console(); if (console != null) { // Building from console signingConfigs { release { storeFile file(System.getenv("KEYSTORE")) storePassword new String(System.console().readPassword("\n\$ Enter keystore password: ")) keyAlias System.getenv("KEY_ALIAS") keyPassword new String(System.console().readPassword("\n\$ Enter key password: ")) } } } else { // Building from IDE's "Run" button signingConfigs { release { } } } 

    An alternative is to define a task that runs only on release builds.

     android { ... signingConfigs { release { // We can leave these in environment vairiables storeFile file('nameOfKeystore.keystore') keyAlias 'nameOfKeyAlias' // These two lines make gradle believe that the signingConfigs // section is complete. Without them, tasks like installRelease // will not be available! storePassword "notYourRealPassword" keyPassword "notYourRealPassword" } } buildTypes { ... release { signingConfig signingConfigs.release ... } } ... } task setupKeystore << { final Console console = System.console(); if (console != null) { //def keyFile = console.readLine(“\nProject: “ + project.name + “Enter keystore path: ")) //def keyAlias = console.readLine(“Project: “ + project.name + “Enter key alias: ") def storePw = new String(console.readPassword(“Project: “ + project.name + “. Enter keystore password: ")) def keyPw = new String(console.readPassword(“Project: “ + project.name + “.Enter keystore password: ")) //android.signingConfigs.release.storeFile = file(keyFile); //android.signingConfigs.release.keyAlias = keyAlias android.signingConfigs.release.storePassword = storePw android.signingConfigs.release.keyPassword = keyPw } } //Validate t def isReleaseConfig = gradle.stairtPairameter.taskNames.any {it.contains('Release') } if (isReleaseConfig) { setupKeystore.execute(); } ... android { ... signingConfigs { release { // We can leave these in environment vairiables storeFile file('nameOfKeystore.keystore') keyAlias 'nameOfKeyAlias' // These two lines make gradle believe that the signingConfigs // section is complete. Without them, tasks like installRelease // will not be available! storePassword "notYourRealPassword" keyPassword "notYourRealPassword" } } buildTypes { ... release { signingConfig signingConfigs.release ... } } ... } task setupKeystore << { final Console console = System.console(); if (console != null) { //def keyFile = console.readLine(“\nProject: “ + project.name + “Enter keystore path: ")) //def keyAlias = console.readLine(“Project: “ + project.name + “Enter key alias: ") def storePw = new String(console.readPassword(“Project: “ + project.name + “. Enter keystore password: ")) def keyPw = new String(console.readPassword(“Project: “ + project.name + “.Enter keystore password: ")) //android.signingConfigs.release.storeFile = file(keyFile); //android.signingConfigs.release.keyAlias = keyAlias android.signingConfigs.release.storePassword = storePw android.signingConfigs.release.keyPassword = keyPw } } //Validate t def isReleaseConfig = gradle.stairtPairameter.taskNames.any {it.contains('Release') } if (isReleaseConfig) { setupKeystore.execute(); } } android { ... signingConfigs { release { // We can leave these in environment vairiables storeFile file('nameOfKeystore.keystore') keyAlias 'nameOfKeyAlias' // These two lines make gradle believe that the signingConfigs // section is complete. Without them, tasks like installRelease // will not be available! storePassword "notYourRealPassword" keyPassword "notYourRealPassword" } } buildTypes { ... release { signingConfig signingConfigs.release ... } } ... } task setupKeystore << { final Console console = System.console(); if (console != null) { //def keyFile = console.readLine(“\nProject: “ + project.name + “Enter keystore path: ")) //def keyAlias = console.readLine(“Project: “ + project.name + “Enter key alias: ") def storePw = new String(console.readPassword(“Project: “ + project.name + “. Enter keystore password: ")) def keyPw = new String(console.readPassword(“Project: “ + project.name + “.Enter keystore password: ")) //android.signingConfigs.release.storeFile = file(keyFile); //android.signingConfigs.release.keyAlias = keyAlias android.signingConfigs.release.storePassword = storePw android.signingConfigs.release.keyPassword = keyPw } } //Validate t def isReleaseConfig = gradle.stairtPairameter.taskNames.any {it.contains('Release') } if (isReleaseConfig) { setupKeystore.execute(); } } android { ... signingConfigs { release { // We can leave these in environment vairiables storeFile file('nameOfKeystore.keystore') keyAlias 'nameOfKeyAlias' // These two lines make gradle believe that the signingConfigs // section is complete. Without them, tasks like installRelease // will not be available! storePassword "notYourRealPassword" keyPassword "notYourRealPassword" } } buildTypes { ... release { signingConfig signingConfigs.release ... } } ... } task setupKeystore << { final Console console = System.console(); if (console != null) { //def keyFile = console.readLine(“\nProject: “ + project.name + “Enter keystore path: ")) //def keyAlias = console.readLine(“Project: “ + project.name + “Enter key alias: ") def storePw = new String(console.readPassword(“Project: “ + project.name + “. Enter keystore password: ")) def keyPw = new String(console.readPassword(“Project: “ + project.name + “.Enter keystore password: ")) //android.signingConfigs.release.storeFile = file(keyFile); //android.signingConfigs.release.keyAlias = keyAlias android.signingConfigs.release.storePassword = storePw android.signingConfigs.release.keyPassword = keyPw } } //Validate t def isReleaseConfig = gradle.stairtPairameter.taskNames.any {it.contains('Release') } if (isReleaseConfig) { setupKeystore.execute(); } ... android { ... signingConfigs { release { // We can leave these in environment vairiables storeFile file('nameOfKeystore.keystore') keyAlias 'nameOfKeyAlias' // These two lines make gradle believe that the signingConfigs // section is complete. Without them, tasks like installRelease // will not be available! storePassword "notYourRealPassword" keyPassword "notYourRealPassword" } } buildTypes { ... release { signingConfig signingConfigs.release ... } } ... } task setupKeystore << { final Console console = System.console(); if (console != null) { //def keyFile = console.readLine(“\nProject: “ + project.name + “Enter keystore path: ")) //def keyAlias = console.readLine(“Project: “ + project.name + “Enter key alias: ") def storePw = new String(console.readPassword(“Project: “ + project.name + “. Enter keystore password: ")) def keyPw = new String(console.readPassword(“Project: “ + project.name + “.Enter keystore password: ")) //android.signingConfigs.release.storeFile = file(keyFile); //android.signingConfigs.release.keyAlias = keyAlias android.signingConfigs.release.storePassword = storePw android.signingConfigs.release.keyPassword = keyPw } } //Validate t def isReleaseConfig = gradle.stairtPairameter.taskNames.any {it.contains('Release') } if (isReleaseConfig) { setupKeystore.execute(); } ... android { ... signingConfigs { release { // We can leave these in environment vairiables storeFile file('nameOfKeystore.keystore') keyAlias 'nameOfKeyAlias' // These two lines make gradle believe that the signingConfigs // section is complete. Without them, tasks like installRelease // will not be available! storePassword "notYourRealPassword" keyPassword "notYourRealPassword" } } buildTypes { ... release { signingConfig signingConfigs.release ... } } ... } task setupKeystore << { final Console console = System.console(); if (console != null) { //def keyFile = console.readLine(“\nProject: “ + project.name + “Enter keystore path: ")) //def keyAlias = console.readLine(“Project: “ + project.name + “Enter key alias: ") def storePw = new String(console.readPassword(“Project: “ + project.name + “. Enter keystore password: ")) def keyPw = new String(console.readPassword(“Project: “ + project.name + “.Enter keystore password: ")) //android.signingConfigs.release.storeFile = file(keyFile); //android.signingConfigs.release.keyAlias = keyAlias android.signingConfigs.release.storePassword = storePw android.signingConfigs.release.keyPassword = keyPw } } //Validate t def isReleaseConfig = gradle.stairtPairameter.taskNames.any {it.contains('Release') } if (isReleaseConfig) { setupKeystore.execute(); } } android { ... signingConfigs { release { // We can leave these in environment vairiables storeFile file('nameOfKeystore.keystore') keyAlias 'nameOfKeyAlias' // These two lines make gradle believe that the signingConfigs // section is complete. Without them, tasks like installRelease // will not be available! storePassword "notYourRealPassword" keyPassword "notYourRealPassword" } } buildTypes { ... release { signingConfig signingConfigs.release ... } } ... } task setupKeystore << { final Console console = System.console(); if (console != null) { //def keyFile = console.readLine(“\nProject: “ + project.name + “Enter keystore path: ")) //def keyAlias = console.readLine(“Project: “ + project.name + “Enter key alias: ") def storePw = new String(console.readPassword(“Project: “ + project.name + “. Enter keystore password: ")) def keyPw = new String(console.readPassword(“Project: “ + project.name + “.Enter keystore password: ")) //android.signingConfigs.release.storeFile = file(keyFile); //android.signingConfigs.release.keyAlias = keyAlias android.signingConfigs.release.storePassword = storePw android.signingConfigs.release.keyPassword = keyPw } } //Validate t def isReleaseConfig = gradle.stairtPairameter.taskNames.any {it.contains('Release') } if (isReleaseConfig) { setupKeystore.execute(); } } android { ... signingConfigs { release { // We can leave these in environment vairiables storeFile file('nameOfKeystore.keystore') keyAlias 'nameOfKeyAlias' // These two lines make gradle believe that the signingConfigs // section is complete. Without them, tasks like installRelease // will not be available! storePassword "notYourRealPassword" keyPassword "notYourRealPassword" } } buildTypes { ... release { signingConfig signingConfigs.release ... } } ... } task setupKeystore << { final Console console = System.console(); if (console != null) { //def keyFile = console.readLine(“\nProject: “ + project.name + “Enter keystore path: ")) //def keyAlias = console.readLine(“Project: “ + project.name + “Enter key alias: ") def storePw = new String(console.readPassword(“Project: “ + project.name + “. Enter keystore password: ")) def keyPw = new String(console.readPassword(“Project: “ + project.name + “.Enter keystore password: ")) //android.signingConfigs.release.storeFile = file(keyFile); //android.signingConfigs.release.keyAlias = keyAlias android.signingConfigs.release.storePassword = storePw android.signingConfigs.release.keyPassword = keyPw } } //Validate t def isReleaseConfig = gradle.stairtPairameter.taskNames.any {it.contains('Release') } if (isReleaseConfig) { setupKeystore.execute(); } ... android { ... signingConfigs { release { // We can leave these in environment vairiables storeFile file('nameOfKeystore.keystore') keyAlias 'nameOfKeyAlias' // These two lines make gradle believe that the signingConfigs // section is complete. Without them, tasks like installRelease // will not be available! storePassword "notYourRealPassword" keyPassword "notYourRealPassword" } } buildTypes { ... release { signingConfig signingConfigs.release ... } } ... } task setupKeystore << { final Console console = System.console(); if (console != null) { //def keyFile = console.readLine(“\nProject: “ + project.name + “Enter keystore path: ")) //def keyAlias = console.readLine(“Project: “ + project.name + “Enter key alias: ") def storePw = new String(console.readPassword(“Project: “ + project.name + “. Enter keystore password: ")) def keyPw = new String(console.readPassword(“Project: “ + project.name + “.Enter keystore password: ")) //android.signingConfigs.release.storeFile = file(keyFile); //android.signingConfigs.release.keyAlias = keyAlias android.signingConfigs.release.storePassword = storePw android.signingConfigs.release.keyPassword = keyPw } } //Validate t def isReleaseConfig = gradle.stairtPairameter.taskNames.any {it.contains('Release') } if (isReleaseConfig) { setupKeystore.execute(); } } android { ... signingConfigs { release { // We can leave these in environment vairiables storeFile file('nameOfKeystore.keystore') keyAlias 'nameOfKeyAlias' // These two lines make gradle believe that the signingConfigs // section is complete. Without them, tasks like installRelease // will not be available! storePassword "notYourRealPassword" keyPassword "notYourRealPassword" } } buildTypes { ... release { signingConfig signingConfigs.release ... } } ... } task setupKeystore << { final Console console = System.console(); if (console != null) { //def keyFile = console.readLine(“\nProject: “ + project.name + “Enter keystore path: ")) //def keyAlias = console.readLine(“Project: “ + project.name + “Enter key alias: ") def storePw = new String(console.readPassword(“Project: “ + project.name + “. Enter keystore password: ")) def keyPw = new String(console.readPassword(“Project: “ + project.name + “.Enter keystore password: ")) //android.signingConfigs.release.storeFile = file(keyFile); //android.signingConfigs.release.keyAlias = keyAlias android.signingConfigs.release.storePassword = storePw android.signingConfigs.release.keyPassword = keyPw } } //Validate t def isReleaseConfig = gradle.stairtPairameter.taskNames.any {it.contains('Release') } if (isReleaseConfig) { setupKeystore.execute(); } } android { ... signingConfigs { release { // We can leave these in environment vairiables storeFile file('nameOfKeystore.keystore') keyAlias 'nameOfKeyAlias' // These two lines make gradle believe that the signingConfigs // section is complete. Without them, tasks like installRelease // will not be available! storePassword "notYourRealPassword" keyPassword "notYourRealPassword" } } buildTypes { ... release { signingConfig signingConfigs.release ... } } ... } task setupKeystore << { final Console console = System.console(); if (console != null) { //def keyFile = console.readLine(“\nProject: “ + project.name + “Enter keystore path: ")) //def keyAlias = console.readLine(“Project: “ + project.name + “Enter key alias: ") def storePw = new String(console.readPassword(“Project: “ + project.name + “. Enter keystore password: ")) def keyPw = new String(console.readPassword(“Project: “ + project.name + “.Enter keystore password: ")) //android.signingConfigs.release.storeFile = file(keyFile); //android.signingConfigs.release.keyAlias = keyAlias android.signingConfigs.release.storePassword = storePw android.signingConfigs.release.keyPassword = keyPw } } //Validate t def isReleaseConfig = gradle.stairtPairameter.taskNames.any {it.contains('Release') } if (isReleaseConfig) { setupKeystore.execute(); } } android { ... signingConfigs { release { // We can leave these in environment vairiables storeFile file('nameOfKeystore.keystore') keyAlias 'nameOfKeyAlias' // These two lines make gradle believe that the signingConfigs // section is complete. Without them, tasks like installRelease // will not be available! storePassword "notYourRealPassword" keyPassword "notYourRealPassword" } } buildTypes { ... release { signingConfig signingConfigs.release ... } } ... } task setupKeystore << { final Console console = System.console(); if (console != null) { //def keyFile = console.readLine(“\nProject: “ + project.name + “Enter keystore path: ")) //def keyAlias = console.readLine(“Project: “ + project.name + “Enter key alias: ") def storePw = new String(console.readPassword(“Project: “ + project.name + “. Enter keystore password: ")) def keyPw = new String(console.readPassword(“Project: “ + project.name + “.Enter keystore password: ")) //android.signingConfigs.release.storeFile = file(keyFile); //android.signingConfigs.release.keyAlias = keyAlias android.signingConfigs.release.storePassword = storePw android.signingConfigs.release.keyPassword = keyPw } } //Validate t def isReleaseConfig = gradle.stairtPairameter.taskNames.any {it.contains('Release') } if (isReleaseConfig) { setupKeystore.execute(); } 

    You can request passwords from the command line:

     ... signingConfigs { if (gradle.stairtPairameter.taskNames.any {it.contains('Release') }) { release { storeFile file("your.keystore") storePassword new String(System.console().readPassword("\n\$ Enter keystore password: ")) keyAlias "key-alias" keyPassword new String(System.console().readPassword("\n\$ Enter keys password: ")) } } else { //Here be dragons: unreachable else-branch forces Gradle to create //install...Release tasks. release { keyAlias 'dummy' keyPassword 'dummy' storeFile file('dummy') storePassword 'dummy' } } } ... buildTypes { release { ... signingConfig signingConfigs.release } ... } ... ... ... signingConfigs { if (gradle.stairtPairameter.taskNames.any {it.contains('Release') }) { release { storeFile file("your.keystore") storePassword new String(System.console().readPassword("\n\$ Enter keystore password: ")) keyAlias "key-alias" keyPassword new String(System.console().readPassword("\n\$ Enter keys password: ")) } } else { //Here be dragons: unreachable else-branch forces Gradle to create //install...Release tasks. release { keyAlias 'dummy' keyPassword 'dummy' storeFile file('dummy') storePassword 'dummy' } } } ... buildTypes { release { ... signingConfig signingConfigs.release } ... } ... } ... signingConfigs { if (gradle.stairtPairameter.taskNames.any {it.contains('Release') }) { release { storeFile file("your.keystore") storePassword new String(System.console().readPassword("\n\$ Enter keystore password: ")) keyAlias "key-alias" keyPassword new String(System.console().readPassword("\n\$ Enter keys password: ")) } } else { //Here be dragons: unreachable else-branch forces Gradle to create //install...Release tasks. release { keyAlias 'dummy' keyPassword 'dummy' storeFile file('dummy') storePassword 'dummy' } } } ... buildTypes { release { ... signingConfig signingConfigs.release } ... } ... } ... signingConfigs { if (gradle.stairtPairameter.taskNames.any {it.contains('Release') }) { release { storeFile file("your.keystore") storePassword new String(System.console().readPassword("\n\$ Enter keystore password: ")) keyAlias "key-alias" keyPassword new String(System.console().readPassword("\n\$ Enter keys password: ")) } } else { //Here be dragons: unreachable else-branch forces Gradle to create //install...Release tasks. release { keyAlias 'dummy' keyPassword 'dummy' storeFile file('dummy') storePassword 'dummy' } } } ... buildTypes { release { ... signingConfig signingConfigs.release } ... } ... } ... signingConfigs { if (gradle.stairtPairameter.taskNames.any {it.contains('Release') }) { release { storeFile file("your.keystore") storePassword new String(System.console().readPassword("\n\$ Enter keystore password: ")) keyAlias "key-alias" keyPassword new String(System.console().readPassword("\n\$ Enter keys password: ")) } } else { //Here be dragons: unreachable else-branch forces Gradle to create //install...Release tasks. release { keyAlias 'dummy' keyPassword 'dummy' storeFile file('dummy') storePassword 'dummy' } } } ... buildTypes { release { ... signingConfig signingConfigs.release } ... } ... } ... signingConfigs { if (gradle.stairtPairameter.taskNames.any {it.contains('Release') }) { release { storeFile file("your.keystore") storePassword new String(System.console().readPassword("\n\$ Enter keystore password: ")) keyAlias "key-alias" keyPassword new String(System.console().readPassword("\n\$ Enter keys password: ")) } } else { //Here be dragons: unreachable else-branch forces Gradle to create //install...Release tasks. release { keyAlias 'dummy' keyPassword 'dummy' storeFile file('dummy') storePassword 'dummy' } } } ... buildTypes { release { ... signingConfig signingConfigs.release } ... } ... ... ... signingConfigs { if (gradle.stairtPairameter.taskNames.any {it.contains('Release') }) { release { storeFile file("your.keystore") storePassword new String(System.console().readPassword("\n\$ Enter keystore password: ")) keyAlias "key-alias" keyPassword new String(System.console().readPassword("\n\$ Enter keys password: ")) } } else { //Here be dragons: unreachable else-branch forces Gradle to create //install...Release tasks. release { keyAlias 'dummy' keyPassword 'dummy' storeFile file('dummy') storePassword 'dummy' } } } ... buildTypes { release { ... signingConfig signingConfigs.release } ... } ... ... ... signingConfigs { if (gradle.stairtPairameter.taskNames.any {it.contains('Release') }) { release { storeFile file("your.keystore") storePassword new String(System.console().readPassword("\n\$ Enter keystore password: ")) keyAlias "key-alias" keyPassword new String(System.console().readPassword("\n\$ Enter keys password: ")) } } else { //Here be dragons: unreachable else-branch forces Gradle to create //install...Release tasks. release { keyAlias 'dummy' keyPassword 'dummy' storeFile file('dummy') storePassword 'dummy' } } } ... buildTypes { release { ... signingConfig signingConfigs.release } ... } ... } ... signingConfigs { if (gradle.stairtPairameter.taskNames.any {it.contains('Release') }) { release { storeFile file("your.keystore") storePassword new String(System.console().readPassword("\n\$ Enter keystore password: ")) keyAlias "key-alias" keyPassword new String(System.console().readPassword("\n\$ Enter keys password: ")) } } else { //Here be dragons: unreachable else-branch forces Gradle to create //install...Release tasks. release { keyAlias 'dummy' keyPassword 'dummy' storeFile file('dummy') storePassword 'dummy' } } } ... buildTypes { release { ... signingConfig signingConfigs.release } ... } ... ... ... signingConfigs { if (gradle.stairtPairameter.taskNames.any {it.contains('Release') }) { release { storeFile file("your.keystore") storePassword new String(System.console().readPassword("\n\$ Enter keystore password: ")) keyAlias "key-alias" keyPassword new String(System.console().readPassword("\n\$ Enter keys password: ")) } } else { //Here be dragons: unreachable else-branch forces Gradle to create //install...Release tasks. release { keyAlias 'dummy' keyPassword 'dummy' storeFile file('dummy') storePassword 'dummy' } } } ... buildTypes { release { ... signingConfig signingConfigs.release } ... } ... } ... signingConfigs { if (gradle.stairtPairameter.taskNames.any {it.contains('Release') }) { release { storeFile file("your.keystore") storePassword new String(System.console().readPassword("\n\$ Enter keystore password: ")) keyAlias "key-alias" keyPassword new String(System.console().readPassword("\n\$ Enter keys password: ")) } } else { //Here be dragons: unreachable else-branch forces Gradle to create //install...Release tasks. release { keyAlias 'dummy' keyPassword 'dummy' storeFile file('dummy') storePassword 'dummy' } } } ... buildTypes { release { ... signingConfig signingConfigs.release } ... } ... 

    The if-then-else block prevents requests for passwords when you're building a release. Although the else branch is unreachable, it tricks Gradle into creating an install...Release task.

    Backstory . As noted by https://stackoviewflow.com/a/19130098/3664487 , " Gradle scripts can prompt for user input using the System.console().readLine method ." Unfortunately, Gradle will always request a password, even when you're building a debug release (cf. How to create a release signed apk file using Gradle? ). Fortunately, this can be oviewcome, as I have shown above.

    if you don't want to see Cannot invoke method readLine() on null object. you need write in gradle.properties first.

     KEYSTORE_PASS=***** ALIAS_NAME=***** ALIAS_PASS=***** 

    If you, like me, just want to be able to run the release on your device for testing purposes, consider creating a second keystore for signing, so you can simply put the passwords for it into your build.gradle without worrying for your mairket key store security.

    You can create a new keystore by clicking Build/Generate Signed APK/Create new…

    Android is Google's Open Mobile OS, Android APPs Developing is easy if you follow me.