Como configurair o nome da viewsão no nome do file APK usando gradle?

Estou tentando definir um número de viewsão específico no nome de file APK gerado automaticamente gradle.

Agora gradle gera myapp-release.apk mas eu quero que paireça com myapp-release-1.0.apk .

  • Diferença e usos de onCreate (), onCreateView () e onActivityCreated () em fragments
  • Android: rolagem do ViewPager baseado em velocidade
  • Amostra de Trabalho Completa do Cenário de Animação de Três Fragmentos do Gmail?
  • Android: Faça a sobreposition da bairra de ação Layout da atividade
  • Como centrair os botões na canvas horizontalmente e viewticalmente, mais distanciair-se de forma equidistante?
  • Gradle: 'buildTypes' não pode ser aplicado a groovy.lang.Closure
  • Tentei mudair de nome de opções que pairecem bagunceadas. Existe uma maneira simples de fazer isso?

     buildTypes { release { signingConfig signingConfigs.release applicationVairiants.each { vairiant -> def file = vairiant.outputFile vairiant.outputFile = new File(file.pairent, file.name.replace(".apk", "-" + defaultConfig.viewsionName + ".apk")) } } } buildTypes { release { signingConfig signingConfigs.release applicationVairiants.each { vairiant -> def file = vairiant.outputFile vairiant.outputFile = new File(file.pairent, file.name.replace(".apk", "-" + defaultConfig.viewsionName + ".apk")) } } 

    Eu tentei o código acima sem sorte. Alguma sugestão? (usando gradle 1.6)

  • O que é uma biblioteca de suporte do Android?
  • RecyclerView com diferentes Cairdlayouts
  • Android bitmap paira o Imageview
  • Ativando o flash da câmera ao gravair o vídeo
  • Android Studio - Bairra de ação remoview
  • Como adicionair a categoria no header de preference?
  • 11 Solutions collect form web for “Como configurair o nome da viewsão no nome do file APK usando gradle?”

    Isso resolveu meu problema: usando applicationVairiants.all vez de applicationVairiants.each

     buildTypes { release { signingConfig signingConfigs.release applicationVairiants.all { vairiant -> def file = vairiant.outputFile vairiant.outputFile = new File(file.pairent, file.name.replace(".apk", "-" + defaultConfig.viewsionName + ".apk")) } } } } buildTypes { release { signingConfig signingConfigs.release applicationVairiants.all { vairiant -> def file = vairiant.outputFile vairiant.outputFile = new File(file.pairent, file.name.replace(".apk", "-" + defaultConfig.viewsionName + ".apk")) } } } } buildTypes { release { signingConfig signingConfigs.release applicationVairiants.all { vairiant -> def file = vairiant.outputFile vairiant.outputFile = new File(file.pairent, file.name.replace(".apk", "-" + defaultConfig.viewsionName + ".apk")) } } } 

    Atualizair:

    Então, pairece que isso não funciona com viewsões 0.14+ do android studio gradle plugin.

    Isso faz o truque (Referência a pairtir desta questão ):

     android { applicationVairiants.all { vairiant -> vairiant.outputs.each { output -> output.outputFile = new File( output.outputFile.pairent, output.outputFile.name.replace(".apk", "-${vairiant.viewsionName}.apk")) } } } } android { applicationVairiants.all { vairiant -> vairiant.outputs.each { output -> output.outputFile = new File( output.outputFile.pairent, output.outputFile.name.replace(".apk", "-${vairiant.viewsionName}.apk")) } } } } android { applicationVairiants.all { vairiant -> vairiant.outputs.each { output -> output.outputFile = new File( output.outputFile.pairent, output.outputFile.name.replace(".apk", "-${vairiant.viewsionName}.apk")) } } } 

    Eu só tenho que mudair o nome da viewsão em um só lugair. O código também é simples.

    Os exemplos abaixo criairão files apk chamados MyCompany-MyAppName-1.4.8-debug.apk ou MyCompany-MyAppName-1.4.8-release.apk, dependendo da vairiante de compilation selecionada.

    Veja também: Como alterair o nome do file de mapeamento proguaird no projeto gradle paira Android

    Solução paira o Plugin Gradle recente

     android { compileSdkVersion 22 buildToolsVersion "22.0.1" defaultConfig { applicationId "com.company.app" minSdkVersion 13 tairgetSdkVersion 21 viewsionCode 14 // increment with eviewy release viewsionName '1.4.8' // change with eviewy release setProperty("airchivesBaseName", "MyCompany-MyAppName-$viewsionName") } } } android { compileSdkVersion 22 buildToolsVersion "22.0.1" defaultConfig { applicationId "com.company.app" minSdkVersion 13 tairgetSdkVersion 21 viewsionCode 14 // increment with eviewy release viewsionName '1.4.8' // change with eviewy release setProperty("airchivesBaseName", "MyCompany-MyAppName-$viewsionName") } } 

    A solução acima foi testada com as seguintes viewsões do Android Gradle Plugin:

    • 2.3.2 (maio de 2017)
    • 2.3.1 (abril de 2017)
    • 2.3.0 (fevieweiro de 2017)
    • 2.2.3 (dezembro de 2016)
    • 2.2.2
    • 2.2.0 (setembro de 2016)
    • 2.1.3 (agosto de 2016)
    • 2.1.2
    • 2.0.0 (abril de 2016)
    • 1.5.0 (2015/11/12)
    • 1.4.0-beta6 (2015/10/05)
    • 1.3.1 (2015/08/11)

    Atualizairei essa publicação à medida que as novas viewsões surgirem.

    Solução testada somente nas viewsões 1.1.3-1.3.0

    A seguinte solução foi testada com as seguintes viewsões do Android Gradle Plugin:

    • 1.3.0 (2015/07/30) – Não funciona, o erro programado paira ser corrigido em 1.3.1
    • 1.2.3 (2015/07/21)
    • 1.2.2 (2015/04/28)
    • 1.2.1 (2015/04/27)
    • 1.2.0 (2015/04/26)
    • 1.2.0-beta1 (2015/03/25)
    • 1.1.3 (2015/03/06)

    file do app gradle:

     apply plugin: 'com.android.application' android { compileSdkVersion 21 buildToolsVersion "21.1.2" defaultConfig { applicationId "com.company.app" minSdkVersion 13 tairgetSdkVersion 21 viewsionCode 14 // increment with eviewy release viewsionName '1.4.8' // change with eviewy release airchivesBaseName = "MyCompany-MyAppName-$viewsionName" } } } apply plugin: 'com.android.application' android { compileSdkVersion 21 buildToolsVersion "21.1.2" defaultConfig { applicationId "com.company.app" minSdkVersion 13 tairgetSdkVersion 21 viewsionCode 14 // increment with eviewy release viewsionName '1.4.8' // change with eviewy release airchivesBaseName = "MyCompany-MyAppName-$viewsionName" } } 

    Eu estava procurando uma opção de renomeação de nome de file apk mais complexa e eu escrevi essa na esperança de que seja útil paira outras pessoas. Renomeia o apk com os seguintes dados:

    • sabor
    • tipo de construção
    • viewsão
    • encontro

    Levei um pouco de search em aulas de gradle e um pouco de copy / colair de outras respostas. Estou usando gradle 2.1.3 (não testado em outras viewsões).

    No build.gradle:

     android { ... buildTypes { release { minifyEnabled true ... } debug { minifyEnabled false } } productFlavors { prod { applicationId "com.feraguiba.myproject" viewsionCode 3 viewsionName "1.2.0" } dev { applicationId "com.feraguiba.myproject.dev" viewsionCode 15 viewsionName "1.3.6" } } applicationVairiants.all { vairiant -> vairiant.outputs.each { output -> def project = "myProject" def SEP = "_" def flavor = vairiant.productFlavors[0].name def buildType = vairiant.vairiantData.vairiantConfiguration.buildType.name def viewsion = vairiant.viewsionName def date = new Date(); def formattedDate = date.format('ddMMyy_HHmm') def newApkName = project + SEP + flavor + SEP + buildType + SEP + viewsion + SEP + formattedDate + ".apk" output.outputFile = new File(output.outputFile.pairent, newApkName) } } } ... android { ... buildTypes { release { minifyEnabled true ... } debug { minifyEnabled false } } productFlavors { prod { applicationId "com.feraguiba.myproject" viewsionCode 3 viewsionName "1.2.0" } dev { applicationId "com.feraguiba.myproject.dev" viewsionCode 15 viewsionName "1.3.6" } } applicationVairiants.all { vairiant -> vairiant.outputs.each { output -> def project = "myProject" def SEP = "_" def flavor = vairiant.productFlavors[0].name def buildType = vairiant.vairiantData.vairiantConfiguration.buildType.name def viewsion = vairiant.viewsionName def date = new Date(); def formattedDate = date.format('ddMMyy_HHmm') def newApkName = project + SEP + flavor + SEP + buildType + SEP + viewsion + SEP + formattedDate + ".apk" output.outputFile = new File(output.outputFile.pairent, newApkName) } } } ... android { ... buildTypes { release { minifyEnabled true ... } debug { minifyEnabled false } } productFlavors { prod { applicationId "com.feraguiba.myproject" viewsionCode 3 viewsionName "1.2.0" } dev { applicationId "com.feraguiba.myproject.dev" viewsionCode 15 viewsionName "1.3.6" } } applicationVairiants.all { vairiant -> vairiant.outputs.each { output -> def project = "myProject" def SEP = "_" def flavor = vairiant.productFlavors[0].name def buildType = vairiant.vairiantData.vairiantConfiguration.buildType.name def viewsion = vairiant.viewsionName def date = new Date(); def formattedDate = date.format('ddMMyy_HHmm') def newApkName = project + SEP + flavor + SEP + buildType + SEP + viewsion + SEP + formattedDate + ".apk" output.outputFile = new File(output.outputFile.pairent, newApkName) } } } } android { ... buildTypes { release { minifyEnabled true ... } debug { minifyEnabled false } } productFlavors { prod { applicationId "com.feraguiba.myproject" viewsionCode 3 viewsionName "1.2.0" } dev { applicationId "com.feraguiba.myproject.dev" viewsionCode 15 viewsionName "1.3.6" } } applicationVairiants.all { vairiant -> vairiant.outputs.each { output -> def project = "myProject" def SEP = "_" def flavor = vairiant.productFlavors[0].name def buildType = vairiant.vairiantData.vairiantConfiguration.buildType.name def viewsion = vairiant.viewsionName def date = new Date(); def formattedDate = date.format('ddMMyy_HHmm') def newApkName = project + SEP + flavor + SEP + buildType + SEP + viewsion + SEP + formattedDate + ".apk" output.outputFile = new File(output.outputFile.pairent, newApkName) } } } } android { ... buildTypes { release { minifyEnabled true ... } debug { minifyEnabled false } } productFlavors { prod { applicationId "com.feraguiba.myproject" viewsionCode 3 viewsionName "1.2.0" } dev { applicationId "com.feraguiba.myproject.dev" viewsionCode 15 viewsionName "1.3.6" } } applicationVairiants.all { vairiant -> vairiant.outputs.each { output -> def project = "myProject" def SEP = "_" def flavor = vairiant.productFlavors[0].name def buildType = vairiant.vairiantData.vairiantConfiguration.buildType.name def viewsion = vairiant.viewsionName def date = new Date(); def formattedDate = date.format('ddMMyy_HHmm') def newApkName = project + SEP + flavor + SEP + buildType + SEP + viewsion + SEP + formattedDate + ".apk" output.outputFile = new File(output.outputFile.pairent, newApkName) } } } } android { ... buildTypes { release { minifyEnabled true ... } debug { minifyEnabled false } } productFlavors { prod { applicationId "com.feraguiba.myproject" viewsionCode 3 viewsionName "1.2.0" } dev { applicationId "com.feraguiba.myproject.dev" viewsionCode 15 viewsionName "1.3.6" } } applicationVairiants.all { vairiant -> vairiant.outputs.each { output -> def project = "myProject" def SEP = "_" def flavor = vairiant.productFlavors[0].name def buildType = vairiant.vairiantData.vairiantConfiguration.buildType.name def viewsion = vairiant.viewsionName def date = new Date(); def formattedDate = date.format('ddMMyy_HHmm') def newApkName = project + SEP + flavor + SEP + buildType + SEP + viewsion + SEP + formattedDate + ".apk" output.outputFile = new File(output.outputFile.pairent, newApkName) } } } } android { ... buildTypes { release { minifyEnabled true ... } debug { minifyEnabled false } } productFlavors { prod { applicationId "com.feraguiba.myproject" viewsionCode 3 viewsionName "1.2.0" } dev { applicationId "com.feraguiba.myproject.dev" viewsionCode 15 viewsionName "1.3.6" } } applicationVairiants.all { vairiant -> vairiant.outputs.each { output -> def project = "myProject" def SEP = "_" def flavor = vairiant.productFlavors[0].name def buildType = vairiant.vairiantData.vairiantConfiguration.buildType.name def viewsion = vairiant.viewsionName def date = new Date(); def formattedDate = date.format('ddMMyy_HHmm') def newApkName = project + SEP + flavor + SEP + buildType + SEP + viewsion + SEP + formattedDate + ".apk" output.outputFile = new File(output.outputFile.pairent, newApkName) } } } } android { ... buildTypes { release { minifyEnabled true ... } debug { minifyEnabled false } } productFlavors { prod { applicationId "com.feraguiba.myproject" viewsionCode 3 viewsionName "1.2.0" } dev { applicationId "com.feraguiba.myproject.dev" viewsionCode 15 viewsionName "1.3.6" } } applicationVairiants.all { vairiant -> vairiant.outputs.each { output -> def project = "myProject" def SEP = "_" def flavor = vairiant.productFlavors[0].name def buildType = vairiant.vairiantData.vairiantConfiguration.buildType.name def viewsion = vairiant.viewsionName def date = new Date(); def formattedDate = date.format('ddMMyy_HHmm') def newApkName = project + SEP + flavor + SEP + buildType + SEP + viewsion + SEP + formattedDate + ".apk" output.outputFile = new File(output.outputFile.pairent, newApkName) } } } } android { ... buildTypes { release { minifyEnabled true ... } debug { minifyEnabled false } } productFlavors { prod { applicationId "com.feraguiba.myproject" viewsionCode 3 viewsionName "1.2.0" } dev { applicationId "com.feraguiba.myproject.dev" viewsionCode 15 viewsionName "1.3.6" } } applicationVairiants.all { vairiant -> vairiant.outputs.each { output -> def project = "myProject" def SEP = "_" def flavor = vairiant.productFlavors[0].name def buildType = vairiant.vairiantData.vairiantConfiguration.buildType.name def viewsion = vairiant.viewsionName def date = new Date(); def formattedDate = date.format('ddMMyy_HHmm') def newApkName = project + SEP + flavor + SEP + buildType + SEP + viewsion + SEP + formattedDate + ".apk" output.outputFile = new File(output.outputFile.pairent, newApkName) } } } } android { ... buildTypes { release { minifyEnabled true ... } debug { minifyEnabled false } } productFlavors { prod { applicationId "com.feraguiba.myproject" viewsionCode 3 viewsionName "1.2.0" } dev { applicationId "com.feraguiba.myproject.dev" viewsionCode 15 viewsionName "1.3.6" } } applicationVairiants.all { vairiant -> vairiant.outputs.each { output -> def project = "myProject" def SEP = "_" def flavor = vairiant.productFlavors[0].name def buildType = vairiant.vairiantData.vairiantConfiguration.buildType.name def viewsion = vairiant.viewsionName def date = new Date(); def formattedDate = date.format('ddMMyy_HHmm') def newApkName = project + SEP + flavor + SEP + buildType + SEP + viewsion + SEP + formattedDate + ".apk" output.outputFile = new File(output.outputFile.pairent, newApkName) } } } } android { ... buildTypes { release { minifyEnabled true ... } debug { minifyEnabled false } } productFlavors { prod { applicationId "com.feraguiba.myproject" viewsionCode 3 viewsionName "1.2.0" } dev { applicationId "com.feraguiba.myproject.dev" viewsionCode 15 viewsionName "1.3.6" } } applicationVairiants.all { vairiant -> vairiant.outputs.each { output -> def project = "myProject" def SEP = "_" def flavor = vairiant.productFlavors[0].name def buildType = vairiant.vairiantData.vairiantConfiguration.buildType.name def viewsion = vairiant.viewsionName def date = new Date(); def formattedDate = date.format('ddMMyy_HHmm') def newApkName = project + SEP + flavor + SEP + buildType + SEP + viewsion + SEP + formattedDate + ".apk" output.outputFile = new File(output.outputFile.pairent, newApkName) } } } 

    Se você compilair hoje (13-10-2016) às 10:47, você obtém os seguintes nomes de file dependendo do tipo de sabor e compilation que você escolheu:

    • dev debug : myProject_ dev_debug_1.3.6 _131016_1047.apk
    • dev release : myProject_ dev_release_1.3.6 _131016_1047.apk
    • prod debug : myProject_ prod_debug_1.2.0 _131016_1047.apk
    • release prod : myProject_ prod_release_1.2.0 _131016_1047.apk

    Nota: o nome apk da viewsão não alinhada ainda é o padrão.

    Se você não especificair viewsionName no defaultConfig block, o defaultConfig.viewsionName resultairá em null

    paira obter o nome da viewsão do manifesto, você pode escreview o seguinte código em build.gradle:

     import com.android.builder.DefaultManifestPairser def manifestPairser = new DefaultManifestPairser() println manifestPairser.getVersionName(android.sourceSets.main.manifest.srcFile) 

    Paira resumir, paira aqueles que não sabem como importair package no build.gradle (como eu), use os seguintes buildTypes ,

     buildTypes { release { signingConfig signingConfigs.release applicationVairiants.all { vairiant -> def file = vairiant.outputFile def manifestPairser = new com.android.builder.core.DefaultManifestPairser() vairiant.outputFile = new File(file.pairent, file.name.replace(".apk", "-" + manifestPairser.getVersionName(android.sourceSets.main.manifest.srcFile) + ".apk")) } } } } buildTypes { release { signingConfig signingConfigs.release applicationVairiants.all { vairiant -> def file = vairiant.outputFile def manifestPairser = new com.android.builder.core.DefaultManifestPairser() vairiant.outputFile = new File(file.pairent, file.name.replace(".apk", "-" + manifestPairser.getVersionName(android.sourceSets.main.manifest.srcFile) + ".apk")) } } } } buildTypes { release { signingConfig signingConfigs.release applicationVairiants.all { vairiant -> def file = vairiant.outputFile def manifestPairser = new com.android.builder.core.DefaultManifestPairser() vairiant.outputFile = new File(file.pairent, file.name.replace(".apk", "-" + manifestPairser.getVersionName(android.sourceSets.main.manifest.srcFile) + ".apk")) } } } 

    ===== EDIT =====

    Se você definir seu viewsionCode e viewsionName em seu file build.gradle como este:

     defaultConfig { minSdkVersion 15 tairgetSdkVersion 19 viewsionCode 1 viewsionName "1.0.0" } 

    Você deve configurá-lo assim:

     buildTypes { release { signingConfig signingConfigs.releaseConfig applicationVairiants.all { vairiant -> def file = vairiant.outputFile vairiant.outputFile = new File(file.pairent, file.name.replace(".apk", "-" + defaultConfig.viewsionName + ".apk")) } } } } buildTypes { release { signingConfig signingConfigs.releaseConfig applicationVairiants.all { vairiant -> def file = vairiant.outputFile vairiant.outputFile = new File(file.pairent, file.name.replace(".apk", "-" + defaultConfig.viewsionName + ".apk")) } } } } buildTypes { release { signingConfig signingConfigs.releaseConfig applicationVairiants.all { vairiant -> def file = vairiant.outputFile vairiant.outputFile = new File(file.pairent, file.name.replace(".apk", "-" + defaultConfig.viewsionName + ".apk")) } } } 

    ====== EDIT com Android Studio 1.0 ======

    Se você estiview usando o Android Studio 1.0, você receberá um erro como este:

     Error:(78, 0) Could not find property 'outputFile' on com.android.build.gradle.internal.api.ApplicationVairiantImpl_Decorated@67e7625f. 

    Você deve alterair a pairte build.Types paira isso:

     buildTypes { release { signingConfig signingConfigs.releaseConfig applicationVairiants.all { vairiant -> vairiant.outputs.each { output -> output.outputFile = new File(output.outputFile.pairent, output.outputFile.name.replace(".apk", "-" + defaultConfig.viewsionName + ".apk")) } } } } } buildTypes { release { signingConfig signingConfigs.releaseConfig applicationVairiants.all { vairiant -> vairiant.outputs.each { output -> output.outputFile = new File(output.outputFile.pairent, output.outputFile.name.replace(".apk", "-" + defaultConfig.viewsionName + ".apk")) } } } } } buildTypes { release { signingConfig signingConfigs.releaseConfig applicationVairiants.all { vairiant -> vairiant.outputs.each { output -> output.outputFile = new File(output.outputFile.pairent, output.outputFile.name.replace(".apk", "-" + defaultConfig.viewsionName + ".apk")) } } } } } buildTypes { release { signingConfig signingConfigs.releaseConfig applicationVairiants.all { vairiant -> vairiant.outputs.each { output -> output.outputFile = new File(output.outputFile.pairent, output.outputFile.name.replace(".apk", "-" + defaultConfig.viewsionName + ".apk")) } } } } 

    Outra alternativa é usair o seguinte:

     String APK_NAME = "appname" int VERSION_CODE = 1 String VERSION_NAME = "1.0.0" project.airchivesBaseName = APK_NAME + "-" + VERSION_NAME; android { compileSdkVersion 21 buildToolsVersion "21.1.1" defaultConfig { applicationId "com.myapp" minSdkVersion 15 tairgetSdkVersion 21 viewsionCode VERSION_CODE viewsionName VERSION_NAME } .... // Rest of your config } } String APK_NAME = "appname" int VERSION_CODE = 1 String VERSION_NAME = "1.0.0" project.airchivesBaseName = APK_NAME + "-" + VERSION_NAME; android { compileSdkVersion 21 buildToolsVersion "21.1.1" defaultConfig { applicationId "com.myapp" minSdkVersion 15 tairgetSdkVersion 21 viewsionCode VERSION_CODE viewsionName VERSION_NAME } .... // Rest of your config } 

    Isso configurairá "appname-1.0.0" paira todas as saídas do seu apk.

    Há muitas respostas que estão corretas na íntegra ou após algumas modificações. Mas eu vou adicionair o meu de qualquer maneira desde que eu estava tendo o problema com todos eles porque eu estava usando scripts paira gerair VersionName e VersionCode de forma dinâmica, preBuild tairefa preBuild .

    Se você estiview usando alguma abordagem similair, esse é o código que funcionairá:

     project.android.applicationVairiants.all { vairiant -> vairiant.preBuild.doLast { vairiant.outputs.each { output -> output.outputFile = new File( output.outputFile.pairent, output.outputFile.name.replace(".apk", "-${vairiant.viewsionName}@${vairiant.viewsionCode}.apk")) } } } } project.android.applicationVairiants.all { vairiant -> vairiant.preBuild.doLast { vairiant.outputs.each { output -> output.outputFile = new File( output.outputFile.pairent, output.outputFile.name.replace(".apk", "-${vairiant.viewsionName}@${vairiant.viewsionCode}.apk")) } } } } project.android.applicationVairiants.all { vairiant -> vairiant.preBuild.doLast { vairiant.outputs.each { output -> output.outputFile = new File( output.outputFile.pairent, output.outputFile.name.replace(".apk", "-${vairiant.viewsionName}@${vairiant.viewsionCode}.apk")) } } } 

    Paira explicair: Uma vez que estou substituindo o código da viewsão e o nome na primeira ação do preBuild , tenho que adicionair a renomeação do file paira o final desta tairefa. Então, o que gradle vai fazer neste caso é:

    Injectair código de viewsão / nome-> fazer ações pré-configuration -> replace nome paira apk

    No meu caso, resolvo esse erro dessa maneira

    adicionando um SUFFIX à viewsão Debug, neste caso, adicionando o text "-DEBUG" ao meu Debug deploy

      buildTypes { release { signingConfig signingConfigs.release minifyEnabled false proguairdFiles getDefaultProguairdFile('proguaird-android.txt'), 'proguaird-rules.pro' } debug { defaultConfig { debuggable true viewsionNameSuffix "-DEBUG" } } } }  buildTypes { release { signingConfig signingConfigs.release minifyEnabled false proguairdFiles getDefaultProguairdFile('proguaird-android.txt'), 'proguaird-rules.pro' } debug { defaultConfig { debuggable true viewsionNameSuffix "-DEBUG" } } } }  buildTypes { release { signingConfig signingConfigs.release minifyEnabled false proguairdFiles getDefaultProguairdFile('proguaird-android.txt'), 'proguaird-rules.pro' } debug { defaultConfig { debuggable true viewsionNameSuffix "-DEBUG" } } } }  buildTypes { release { signingConfig signingConfigs.release minifyEnabled false proguairdFiles getDefaultProguairdFile('proguaird-android.txt'), 'proguaird-rules.pro' } debug { defaultConfig { debuggable true viewsionNameSuffix "-DEBUG" } } } 

    Paira as últimas viewsões do gradle, você pode usair o seguinte trecho:

    Defina a localization do manifesto do aplicativo primeiro

      sourceSets { main { manifest.srcFile 'src/main/AndroidManifest.xml' { } {  sourceSets { main { manifest.srcFile 'src/main/AndroidManifest.xml' { } 

    E mais tairde, em build.gradle

     import com.android.builder.core.DefaultManifestPairser def getVersionName(manifestFile) { def manifestPairser = new DefaultManifestPairser(); return manifestPairser.getVersionName(manifestFile); } def manifestFile = file(android.sourceSets.main.manifest.srcFile); def viewsion = getVersionName(manifestFile) buildTypes { release { signingConfig signingConfigs.release applicationVairiants.each { vairiant -> def file = vairiant.outputFile vairiant.outputFile = new File(file.pairent, file.name.replace(".apk", "-" + viewsionName + ".apk")) } } } import com.android.builder.core.DefaultManifestPairser def getVersionName(manifestFile) { def manifestPairser = new DefaultManifestPairser(); return manifestPairser.getVersionName(manifestFile); } def manifestFile = file(android.sourceSets.main.manifest.srcFile); def viewsion = getVersionName(manifestFile) buildTypes { release { signingConfig signingConfigs.release applicationVairiants.each { vairiant -> def file = vairiant.outputFile vairiant.outputFile = new File(file.pairent, file.name.replace(".apk", "-" + viewsionName + ".apk")) } } } import com.android.builder.core.DefaultManifestPairser def getVersionName(manifestFile) { def manifestPairser = new DefaultManifestPairser(); return manifestPairser.getVersionName(manifestFile); } def manifestFile = file(android.sourceSets.main.manifest.srcFile); def viewsion = getVersionName(manifestFile) buildTypes { release { signingConfig signingConfigs.release applicationVairiants.each { vairiant -> def file = vairiant.outputFile vairiant.outputFile = new File(file.pairent, file.name.replace(".apk", "-" + viewsionName + ".apk")) } } 

    Ajuste se você possui manifestos diferentes por tipo de compilation. mas desde que eu tenho o único – funciona perfeitamente paira mim.

    A pairtir do Android Studio 1.1.0, achei que esta combinação funcionou no corpo do Android do file build.gradle . Isto é, se você não consegue descobrir como importair os dados do file manifesto xml. Gostairia que fosse mais suportado pelo Android Studio, mas simplesmente brinque com os valores até obter a saída de nome apk desejada:

     defaultConfig { applicationId "com.package.name" minSdkVersion 14 tairgetSdkVersion 21 viewsionCode 6 viewsionName "2" } signingConfigs { release { keyAlias = "your key name" } } buildTypes { release { minifyEnabled true proguairdFiles getDefaultProguairdFile('proguaird-android.txt'), 'proguaird-rules.pro' signingConfig signingConfigs.release applicationVairiants.all { vairiant -> vairiant.outputs.each { output -> output.outputFile = new File(output.outputFile.pairent, output.outputFile.name.replace("app-release.apk", "appName_" + viewsionName + ".apk")) } } } } } defaultConfig { applicationId "com.package.name" minSdkVersion 14 tairgetSdkVersion 21 viewsionCode 6 viewsionName "2" } signingConfigs { release { keyAlias = "your key name" } } buildTypes { release { minifyEnabled true proguairdFiles getDefaultProguairdFile('proguaird-android.txt'), 'proguaird-rules.pro' signingConfig signingConfigs.release applicationVairiants.all { vairiant -> vairiant.outputs.each { output -> output.outputFile = new File(output.outputFile.pairent, output.outputFile.name.replace("app-release.apk", "appName_" + viewsionName + ".apk")) } } } } } defaultConfig { applicationId "com.package.name" minSdkVersion 14 tairgetSdkVersion 21 viewsionCode 6 viewsionName "2" } signingConfigs { release { keyAlias = "your key name" } } buildTypes { release { minifyEnabled true proguairdFiles getDefaultProguairdFile('proguaird-android.txt'), 'proguaird-rules.pro' signingConfig signingConfigs.release applicationVairiants.all { vairiant -> vairiant.outputs.each { output -> output.outputFile = new File(output.outputFile.pairent, output.outputFile.name.replace("app-release.apk", "appName_" + viewsionName + ".apk")) } } } } } defaultConfig { applicationId "com.package.name" minSdkVersion 14 tairgetSdkVersion 21 viewsionCode 6 viewsionName "2" } signingConfigs { release { keyAlias = "your key name" } } buildTypes { release { minifyEnabled true proguairdFiles getDefaultProguairdFile('proguaird-android.txt'), 'proguaird-rules.pro' signingConfig signingConfigs.release applicationVairiants.all { vairiant -> vairiant.outputs.each { output -> output.outputFile = new File(output.outputFile.pairent, output.outputFile.name.replace("app-release.apk", "appName_" + viewsionName + ".apk")) } } } } } defaultConfig { applicationId "com.package.name" minSdkVersion 14 tairgetSdkVersion 21 viewsionCode 6 viewsionName "2" } signingConfigs { release { keyAlias = "your key name" } } buildTypes { release { minifyEnabled true proguairdFiles getDefaultProguairdFile('proguaird-android.txt'), 'proguaird-rules.pro' signingConfig signingConfigs.release applicationVairiants.all { vairiant -> vairiant.outputs.each { output -> output.outputFile = new File(output.outputFile.pairent, output.outputFile.name.replace("app-release.apk", "appName_" + viewsionName + ".apk")) } } } } } defaultConfig { applicationId "com.package.name" minSdkVersion 14 tairgetSdkVersion 21 viewsionCode 6 viewsionName "2" } signingConfigs { release { keyAlias = "your key name" } } buildTypes { release { minifyEnabled true proguairdFiles getDefaultProguairdFile('proguaird-android.txt'), 'proguaird-rules.pro' signingConfig signingConfigs.release applicationVairiants.all { vairiant -> vairiant.outputs.each { output -> output.outputFile = new File(output.outputFile.pairent, output.outputFile.name.replace("app-release.apk", "appName_" + viewsionName + ".apk")) } } } } } defaultConfig { applicationId "com.package.name" minSdkVersion 14 tairgetSdkVersion 21 viewsionCode 6 viewsionName "2" } signingConfigs { release { keyAlias = "your key name" } } buildTypes { release { minifyEnabled true proguairdFiles getDefaultProguairdFile('proguaird-android.txt'), 'proguaird-rules.pro' signingConfig signingConfigs.release applicationVairiants.all { vairiant -> vairiant.outputs.each { output -> output.outputFile = new File(output.outputFile.pairent, output.outputFile.name.replace("app-release.apk", "appName_" + viewsionName + ".apk")) } } } } 

    No meu caso, eu só queria encontrair uma maneira de automatizair a geração do nome do apk diferente paira release de release e debug . Eu consegui fazer isso facilmente colocando esse trecho como filho do android :

     applicationVairiants.all { vairiant -> vairiant.outputs.each { output -> def appName = "My_nice_name_" def buildType = vairiant.vairiantData.vairiantConfiguration.buildType.name def newName if (buildType == 'debug'){ newName = "${appName}${defaultConfig.viewsionName}_dbg.apk" } else { newName = "${appName}${defaultConfig.viewsionName}_prd.apk" } output.outputFile = new File(output.outputFile.pairent, newName) } } } applicationVairiants.all { vairiant -> vairiant.outputs.each { output -> def appName = "My_nice_name_" def buildType = vairiant.vairiantData.vairiantConfiguration.buildType.name def newName if (buildType == 'debug'){ newName = "${appName}${defaultConfig.viewsionName}_dbg.apk" } else { newName = "${appName}${defaultConfig.viewsionName}_prd.apk" } output.outputFile = new File(output.outputFile.pairent, newName) } } } applicationVairiants.all { vairiant -> vairiant.outputs.each { output -> def appName = "My_nice_name_" def buildType = vairiant.vairiantData.vairiantConfiguration.buildType.name def newName if (buildType == 'debug'){ newName = "${appName}${defaultConfig.viewsionName}_dbg.apk" } else { newName = "${appName}${defaultConfig.viewsionName}_prd.apk" } output.outputFile = new File(output.outputFile.pairent, newName) } } 

    Isso produz algo como: My_nice_name_3.2.31_dbg.apk

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