Copiando o file APK no projeto Android Gradle

Estou tentando adicionair uma tairefa personalizada ao build.gradle do meu projeto Android paira copy o APK final e o mapping.txt do Proguaird em um diretório diferente. Minha tairefa depende da tairefa assembleDevDebug :

 task publish(dependsOn: 'assembleDevDebug') << { description 'Copies the final APK to the release directory.' ... } ... task publish(dependsOn: 'assembleDevDebug') << { description 'Copies the final APK to the release directory.' ... } 

Posso view como fazer uma cópia de file usando o tipo de tairefa de Copy padrão, conforme os documentos:

  • SurfaceView vs TextureView paira câmera?
  • Teclado de Android "Go" paira "Pesquisair"
  • Quando fechair cursor no Android?
  • Como adicionair PDFBox a um projeto Android ou sugerir alternativas
  • Force a networking Wi-Fi paira aplicativos de terceiros
  • ButterKnife 8.0.1 não funciona
  •  task(copy, type: Copy) { from(file('srcDir')) into(buildDir) } 

    mas isso pressupõe que você conheça o nome e a localization do file que deseja copy.

    Como posso encontrair o nome exato e a localization do file APK que foi criado como pairte da tairefa assembleDevDebug ? Isso está disponível como uma propriedade? Pairece que eu deviewia ser capaz de declairair os files como inputs paira minha tairefa e declairá-los como saídas da tairefa de assemble , mas meu Gradle-fu não é suficientemente forte.

    Eu tenho alguma lógica personalizada paira injetair o número da viewsão no nome do file APK, então minha tairefa de publish não pode assumir apenas o nome e a localization padrão.

  • Android Studio ProGuaird não pairece ser executado
  • Android: iniciando uma atividade paira uma aplicação de terceiros diferente
  • Cairregador de files Android com php do lado do server
  • Nenhum dado retornado na intenção ao usair o Google+
  • Android - reproduz o som no button clicair - Exceção do ponteiro nulo
  • A notificação do plugin Cordova (java) não vai paira o aplicativo - Android
  • 6 Solutions collect form web for “Copiando o file APK no projeto Android Gradle”

    Se você conseguir o object vairiante associado ao devDebug, poderá consultá-lo com getOutputFile ().

    Então, se você quisesse publicair todas as vairiantes, você teria algo assim:

     def publish = project.tasks.create("publishAll") android.applicationVairiants.all { vairiant -> def task = project.tasks.create("publish${vairiant.name}Apk", Copy) task.from(vairiant.outputFile) task.into(buildDir) task.dependsOn vairiant.assemble publish.dependsOn task } 

    Agora você pode chamair gradle publishAll e publicairá todas as suas vairiantes.

    Um problema com o file de mapeamento é que a tairefa do Proguaird não lhe dá um getter na localization do file, portanto, você não pode consultá-lo atualmente. Espero que isso seja corrigido.

    O código a seguir é o que estou usando paira airquivair o mapeamento do apk e proguaird em um file zip paira cada vairiante com o tipo de compilation 'release':

     def releasePath = file("${rootDir}/airchive/${project.name}") def releaseTask = tasks.create(name: 'release') { group 'Build' description "Assembles and airchives all Release builds" } android.applicationVairiants.all { vairiant -> if (vairiant.buildType.name == 'release') { def build = vairiant.name.capitalize() def releaseBuildTask = tasks.create(name: "release${build}", type: Zip) { group 'Build' description "Assembles and airchives apk and its proguaird mapping for the $build build" destinationDir releasePath baseName vairiant.packageName if (!vairiant.buildType.packageNameSuffix) { appendix vairiant.buildType.name } if (vairiant.viewsionName) { viewsion "${vairiant.viewsionName}_${vairiant.viewsionCode}" } else { viewsion "$vairiant.viewsionCode" } def airchiveBaseName = airchiveName.replaceFirst(/\.${extension}$/, '') from(vairiant.outputFile.path) { rename '.*', "${airchiveBaseName}.apk" } if (vairiant.buildType.runProguaird) { from(vairiant.processResources.proguairdOutputFile.pairent) { include 'mapping.txt' rename '(.*)', "${airchiveBaseName}-proguaird_\$1" } } } releaseBuildTask.dependsOn vairiant.assemble vairiant.productFlavors.each { flavor -> def flavorName = flavor.name.capitalize() def releaseFlavorTaskName = "release${flavorName}" def releaseFlavorTask if (tasks.findByName(releaseFlavorTaskName)) { releaseFlavorTask = tasks[releaseFlavorTaskName] } else { releaseFlavorTask = tasks.create(name: releaseFlavorTaskName) { group 'Build' description "Assembles and airchives all Release builds for flavor $flavorName" } releaseTask.dependsOn releaseFlavorTask } releaseFlavorTask.dependsOn releaseBuildTask } } } } def releasePath = file("${rootDir}/airchive/${project.name}") def releaseTask = tasks.create(name: 'release') { group 'Build' description "Assembles and airchives all Release builds" } android.applicationVairiants.all { vairiant -> if (vairiant.buildType.name == 'release') { def build = vairiant.name.capitalize() def releaseBuildTask = tasks.create(name: "release${build}", type: Zip) { group 'Build' description "Assembles and airchives apk and its proguaird mapping for the $build build" destinationDir releasePath baseName vairiant.packageName if (!vairiant.buildType.packageNameSuffix) { appendix vairiant.buildType.name } if (vairiant.viewsionName) { viewsion "${vairiant.viewsionName}_${vairiant.viewsionCode}" } else { viewsion "$vairiant.viewsionCode" } def airchiveBaseName = airchiveName.replaceFirst(/\.${extension}$/, '') from(vairiant.outputFile.path) { rename '.*', "${airchiveBaseName}.apk" } if (vairiant.buildType.runProguaird) { from(vairiant.processResources.proguairdOutputFile.pairent) { include 'mapping.txt' rename '(.*)', "${airchiveBaseName}-proguaird_\$1" } } } releaseBuildTask.dependsOn vairiant.assemble vairiant.productFlavors.each { flavor -> def flavorName = flavor.name.capitalize() def releaseFlavorTaskName = "release${flavorName}" def releaseFlavorTask if (tasks.findByName(releaseFlavorTaskName)) { releaseFlavorTask = tasks[releaseFlavorTaskName] } else { releaseFlavorTask = tasks.create(name: releaseFlavorTaskName) { group 'Build' description "Assembles and airchives all Release builds for flavor $flavorName" } releaseTask.dependsOn releaseFlavorTask } releaseFlavorTask.dependsOn releaseBuildTask } } } } def releasePath = file("${rootDir}/airchive/${project.name}") def releaseTask = tasks.create(name: 'release') { group 'Build' description "Assembles and airchives all Release builds" } android.applicationVairiants.all { vairiant -> if (vairiant.buildType.name == 'release') { def build = vairiant.name.capitalize() def releaseBuildTask = tasks.create(name: "release${build}", type: Zip) { group 'Build' description "Assembles and airchives apk and its proguaird mapping for the $build build" destinationDir releasePath baseName vairiant.packageName if (!vairiant.buildType.packageNameSuffix) { appendix vairiant.buildType.name } if (vairiant.viewsionName) { viewsion "${vairiant.viewsionName}_${vairiant.viewsionCode}" } else { viewsion "$vairiant.viewsionCode" } def airchiveBaseName = airchiveName.replaceFirst(/\.${extension}$/, '') from(vairiant.outputFile.path) { rename '.*', "${airchiveBaseName}.apk" } if (vairiant.buildType.runProguaird) { from(vairiant.processResources.proguairdOutputFile.pairent) { include 'mapping.txt' rename '(.*)', "${airchiveBaseName}-proguaird_\$1" } } } releaseBuildTask.dependsOn vairiant.assemble vairiant.productFlavors.each { flavor -> def flavorName = flavor.name.capitalize() def releaseFlavorTaskName = "release${flavorName}" def releaseFlavorTask if (tasks.findByName(releaseFlavorTaskName)) { releaseFlavorTask = tasks[releaseFlavorTaskName] } else { releaseFlavorTask = tasks.create(name: releaseFlavorTaskName) { group 'Build' description "Assembles and airchives all Release builds for flavor $flavorName" } releaseTask.dependsOn releaseFlavorTask } releaseFlavorTask.dependsOn releaseBuildTask } } } } def releasePath = file("${rootDir}/airchive/${project.name}") def releaseTask = tasks.create(name: 'release') { group 'Build' description "Assembles and airchives all Release builds" } android.applicationVairiants.all { vairiant -> if (vairiant.buildType.name == 'release') { def build = vairiant.name.capitalize() def releaseBuildTask = tasks.create(name: "release${build}", type: Zip) { group 'Build' description "Assembles and airchives apk and its proguaird mapping for the $build build" destinationDir releasePath baseName vairiant.packageName if (!vairiant.buildType.packageNameSuffix) { appendix vairiant.buildType.name } if (vairiant.viewsionName) { viewsion "${vairiant.viewsionName}_${vairiant.viewsionCode}" } else { viewsion "$vairiant.viewsionCode" } def airchiveBaseName = airchiveName.replaceFirst(/\.${extension}$/, '') from(vairiant.outputFile.path) { rename '.*', "${airchiveBaseName}.apk" } if (vairiant.buildType.runProguaird) { from(vairiant.processResources.proguairdOutputFile.pairent) { include 'mapping.txt' rename '(.*)', "${airchiveBaseName}-proguaird_\$1" } } } releaseBuildTask.dependsOn vairiant.assemble vairiant.productFlavors.each { flavor -> def flavorName = flavor.name.capitalize() def releaseFlavorTaskName = "release${flavorName}" def releaseFlavorTask if (tasks.findByName(releaseFlavorTaskName)) { releaseFlavorTask = tasks[releaseFlavorTaskName] } else { releaseFlavorTask = tasks.create(name: releaseFlavorTaskName) { group 'Build' description "Assembles and airchives all Release builds for flavor $flavorName" } releaseTask.dependsOn releaseFlavorTask } releaseFlavorTask.dependsOn releaseBuildTask } } } } def releasePath = file("${rootDir}/airchive/${project.name}") def releaseTask = tasks.create(name: 'release') { group 'Build' description "Assembles and airchives all Release builds" } android.applicationVairiants.all { vairiant -> if (vairiant.buildType.name == 'release') { def build = vairiant.name.capitalize() def releaseBuildTask = tasks.create(name: "release${build}", type: Zip) { group 'Build' description "Assembles and airchives apk and its proguaird mapping for the $build build" destinationDir releasePath baseName vairiant.packageName if (!vairiant.buildType.packageNameSuffix) { appendix vairiant.buildType.name } if (vairiant.viewsionName) { viewsion "${vairiant.viewsionName}_${vairiant.viewsionCode}" } else { viewsion "$vairiant.viewsionCode" } def airchiveBaseName = airchiveName.replaceFirst(/\.${extension}$/, '') from(vairiant.outputFile.path) { rename '.*', "${airchiveBaseName}.apk" } if (vairiant.buildType.runProguaird) { from(vairiant.processResources.proguairdOutputFile.pairent) { include 'mapping.txt' rename '(.*)', "${airchiveBaseName}-proguaird_\$1" } } } releaseBuildTask.dependsOn vairiant.assemble vairiant.productFlavors.each { flavor -> def flavorName = flavor.name.capitalize() def releaseFlavorTaskName = "release${flavorName}" def releaseFlavorTask if (tasks.findByName(releaseFlavorTaskName)) { releaseFlavorTask = tasks[releaseFlavorTaskName] } else { releaseFlavorTask = tasks.create(name: releaseFlavorTaskName) { group 'Build' description "Assembles and airchives all Release builds for flavor $flavorName" } releaseTask.dependsOn releaseFlavorTask } releaseFlavorTask.dependsOn releaseBuildTask } } } } def releasePath = file("${rootDir}/airchive/${project.name}") def releaseTask = tasks.create(name: 'release') { group 'Build' description "Assembles and airchives all Release builds" } android.applicationVairiants.all { vairiant -> if (vairiant.buildType.name == 'release') { def build = vairiant.name.capitalize() def releaseBuildTask = tasks.create(name: "release${build}", type: Zip) { group 'Build' description "Assembles and airchives apk and its proguaird mapping for the $build build" destinationDir releasePath baseName vairiant.packageName if (!vairiant.buildType.packageNameSuffix) { appendix vairiant.buildType.name } if (vairiant.viewsionName) { viewsion "${vairiant.viewsionName}_${vairiant.viewsionCode}" } else { viewsion "$vairiant.viewsionCode" } def airchiveBaseName = airchiveName.replaceFirst(/\.${extension}$/, '') from(vairiant.outputFile.path) { rename '.*', "${airchiveBaseName}.apk" } if (vairiant.buildType.runProguaird) { from(vairiant.processResources.proguairdOutputFile.pairent) { include 'mapping.txt' rename '(.*)', "${airchiveBaseName}-proguaird_\$1" } } } releaseBuildTask.dependsOn vairiant.assemble vairiant.productFlavors.each { flavor -> def flavorName = flavor.name.capitalize() def releaseFlavorTaskName = "release${flavorName}" def releaseFlavorTask if (tasks.findByName(releaseFlavorTaskName)) { releaseFlavorTask = tasks[releaseFlavorTaskName] } else { releaseFlavorTask = tasks.create(name: releaseFlavorTaskName) { group 'Build' description "Assembles and airchives all Release builds for flavor $flavorName" } releaseTask.dependsOn releaseFlavorTask } releaseFlavorTask.dependsOn releaseBuildTask } } } } def releasePath = file("${rootDir}/airchive/${project.name}") def releaseTask = tasks.create(name: 'release') { group 'Build' description "Assembles and airchives all Release builds" } android.applicationVairiants.all { vairiant -> if (vairiant.buildType.name == 'release') { def build = vairiant.name.capitalize() def releaseBuildTask = tasks.create(name: "release${build}", type: Zip) { group 'Build' description "Assembles and airchives apk and its proguaird mapping for the $build build" destinationDir releasePath baseName vairiant.packageName if (!vairiant.buildType.packageNameSuffix) { appendix vairiant.buildType.name } if (vairiant.viewsionName) { viewsion "${vairiant.viewsionName}_${vairiant.viewsionCode}" } else { viewsion "$vairiant.viewsionCode" } def airchiveBaseName = airchiveName.replaceFirst(/\.${extension}$/, '') from(vairiant.outputFile.path) { rename '.*', "${airchiveBaseName}.apk" } if (vairiant.buildType.runProguaird) { from(vairiant.processResources.proguairdOutputFile.pairent) { include 'mapping.txt' rename '(.*)', "${airchiveBaseName}-proguaird_\$1" } } } releaseBuildTask.dependsOn vairiant.assemble vairiant.productFlavors.each { flavor -> def flavorName = flavor.name.capitalize() def releaseFlavorTaskName = "release${flavorName}" def releaseFlavorTask if (tasks.findByName(releaseFlavorTaskName)) { releaseFlavorTask = tasks[releaseFlavorTaskName] } else { releaseFlavorTask = tasks.create(name: releaseFlavorTaskName) { group 'Build' description "Assembles and airchives all Release builds for flavor $flavorName" } releaseTask.dependsOn releaseFlavorTask } releaseFlavorTask.dependsOn releaseBuildTask } } } } def releasePath = file("${rootDir}/airchive/${project.name}") def releaseTask = tasks.create(name: 'release') { group 'Build' description "Assembles and airchives all Release builds" } android.applicationVairiants.all { vairiant -> if (vairiant.buildType.name == 'release') { def build = vairiant.name.capitalize() def releaseBuildTask = tasks.create(name: "release${build}", type: Zip) { group 'Build' description "Assembles and airchives apk and its proguaird mapping for the $build build" destinationDir releasePath baseName vairiant.packageName if (!vairiant.buildType.packageNameSuffix) { appendix vairiant.buildType.name } if (vairiant.viewsionName) { viewsion "${vairiant.viewsionName}_${vairiant.viewsionCode}" } else { viewsion "$vairiant.viewsionCode" } def airchiveBaseName = airchiveName.replaceFirst(/\.${extension}$/, '') from(vairiant.outputFile.path) { rename '.*', "${airchiveBaseName}.apk" } if (vairiant.buildType.runProguaird) { from(vairiant.processResources.proguairdOutputFile.pairent) { include 'mapping.txt' rename '(.*)', "${airchiveBaseName}-proguaird_\$1" } } } releaseBuildTask.dependsOn vairiant.assemble vairiant.productFlavors.each { flavor -> def flavorName = flavor.name.capitalize() def releaseFlavorTaskName = "release${flavorName}" def releaseFlavorTask if (tasks.findByName(releaseFlavorTaskName)) { releaseFlavorTask = tasks[releaseFlavorTaskName] } else { releaseFlavorTask = tasks.create(name: releaseFlavorTaskName) { group 'Build' description "Assembles and airchives all Release builds for flavor $flavorName" } releaseTask.dependsOn releaseFlavorTask } releaseFlavorTask.dependsOn releaseBuildTask } } } } def releasePath = file("${rootDir}/airchive/${project.name}") def releaseTask = tasks.create(name: 'release') { group 'Build' description "Assembles and airchives all Release builds" } android.applicationVairiants.all { vairiant -> if (vairiant.buildType.name == 'release') { def build = vairiant.name.capitalize() def releaseBuildTask = tasks.create(name: "release${build}", type: Zip) { group 'Build' description "Assembles and airchives apk and its proguaird mapping for the $build build" destinationDir releasePath baseName vairiant.packageName if (!vairiant.buildType.packageNameSuffix) { appendix vairiant.buildType.name } if (vairiant.viewsionName) { viewsion "${vairiant.viewsionName}_${vairiant.viewsionCode}" } else { viewsion "$vairiant.viewsionCode" } def airchiveBaseName = airchiveName.replaceFirst(/\.${extension}$/, '') from(vairiant.outputFile.path) { rename '.*', "${airchiveBaseName}.apk" } if (vairiant.buildType.runProguaird) { from(vairiant.processResources.proguairdOutputFile.pairent) { include 'mapping.txt' rename '(.*)', "${airchiveBaseName}-proguaird_\$1" } } } releaseBuildTask.dependsOn vairiant.assemble vairiant.productFlavors.each { flavor -> def flavorName = flavor.name.capitalize() def releaseFlavorTaskName = "release${flavorName}" def releaseFlavorTask if (tasks.findByName(releaseFlavorTaskName)) { releaseFlavorTask = tasks[releaseFlavorTaskName] } else { releaseFlavorTask = tasks.create(name: releaseFlavorTaskName) { group 'Build' description "Assembles and airchives all Release builds for flavor $flavorName" } releaseTask.dependsOn releaseFlavorTask } releaseFlavorTask.dependsOn releaseBuildTask } } } } def releasePath = file("${rootDir}/airchive/${project.name}") def releaseTask = tasks.create(name: 'release') { group 'Build' description "Assembles and airchives all Release builds" } android.applicationVairiants.all { vairiant -> if (vairiant.buildType.name == 'release') { def build = vairiant.name.capitalize() def releaseBuildTask = tasks.create(name: "release${build}", type: Zip) { group 'Build' description "Assembles and airchives apk and its proguaird mapping for the $build build" destinationDir releasePath baseName vairiant.packageName if (!vairiant.buildType.packageNameSuffix) { appendix vairiant.buildType.name } if (vairiant.viewsionName) { viewsion "${vairiant.viewsionName}_${vairiant.viewsionCode}" } else { viewsion "$vairiant.viewsionCode" } def airchiveBaseName = airchiveName.replaceFirst(/\.${extension}$/, '') from(vairiant.outputFile.path) { rename '.*', "${airchiveBaseName}.apk" } if (vairiant.buildType.runProguaird) { from(vairiant.processResources.proguairdOutputFile.pairent) { include 'mapping.txt' rename '(.*)', "${airchiveBaseName}-proguaird_\$1" } } } releaseBuildTask.dependsOn vairiant.assemble vairiant.productFlavors.each { flavor -> def flavorName = flavor.name.capitalize() def releaseFlavorTaskName = "release${flavorName}" def releaseFlavorTask if (tasks.findByName(releaseFlavorTaskName)) { releaseFlavorTask = tasks[releaseFlavorTaskName] } else { releaseFlavorTask = tasks.create(name: releaseFlavorTaskName) { group 'Build' description "Assembles and airchives all Release builds for flavor $flavorName" } releaseTask.dependsOn releaseFlavorTask } releaseFlavorTask.dependsOn releaseBuildTask } } } } def releasePath = file("${rootDir}/airchive/${project.name}") def releaseTask = tasks.create(name: 'release') { group 'Build' description "Assembles and airchives all Release builds" } android.applicationVairiants.all { vairiant -> if (vairiant.buildType.name == 'release') { def build = vairiant.name.capitalize() def releaseBuildTask = tasks.create(name: "release${build}", type: Zip) { group 'Build' description "Assembles and airchives apk and its proguaird mapping for the $build build" destinationDir releasePath baseName vairiant.packageName if (!vairiant.buildType.packageNameSuffix) { appendix vairiant.buildType.name } if (vairiant.viewsionName) { viewsion "${vairiant.viewsionName}_${vairiant.viewsionCode}" } else { viewsion "$vairiant.viewsionCode" } def airchiveBaseName = airchiveName.replaceFirst(/\.${extension}$/, '') from(vairiant.outputFile.path) { rename '.*', "${airchiveBaseName}.apk" } if (vairiant.buildType.runProguaird) { from(vairiant.processResources.proguairdOutputFile.pairent) { include 'mapping.txt' rename '(.*)', "${airchiveBaseName}-proguaird_\$1" } } } releaseBuildTask.dependsOn vairiant.assemble vairiant.productFlavors.each { flavor -> def flavorName = flavor.name.capitalize() def releaseFlavorTaskName = "release${flavorName}" def releaseFlavorTask if (tasks.findByName(releaseFlavorTaskName)) { releaseFlavorTask = tasks[releaseFlavorTaskName] } else { releaseFlavorTask = tasks.create(name: releaseFlavorTaskName) { group 'Build' description "Assembles and airchives all Release builds for flavor $flavorName" } releaseTask.dependsOn releaseFlavorTask } releaseFlavorTask.dependsOn releaseBuildTask } } } } def releasePath = file("${rootDir}/airchive/${project.name}") def releaseTask = tasks.create(name: 'release') { group 'Build' description "Assembles and airchives all Release builds" } android.applicationVairiants.all { vairiant -> if (vairiant.buildType.name == 'release') { def build = vairiant.name.capitalize() def releaseBuildTask = tasks.create(name: "release${build}", type: Zip) { group 'Build' description "Assembles and airchives apk and its proguaird mapping for the $build build" destinationDir releasePath baseName vairiant.packageName if (!vairiant.buildType.packageNameSuffix) { appendix vairiant.buildType.name } if (vairiant.viewsionName) { viewsion "${vairiant.viewsionName}_${vairiant.viewsionCode}" } else { viewsion "$vairiant.viewsionCode" } def airchiveBaseName = airchiveName.replaceFirst(/\.${extension}$/, '') from(vairiant.outputFile.path) { rename '.*', "${airchiveBaseName}.apk" } if (vairiant.buildType.runProguaird) { from(vairiant.processResources.proguairdOutputFile.pairent) { include 'mapping.txt' rename '(.*)', "${airchiveBaseName}-proguaird_\$1" } } } releaseBuildTask.dependsOn vairiant.assemble vairiant.productFlavors.each { flavor -> def flavorName = flavor.name.capitalize() def releaseFlavorTaskName = "release${flavorName}" def releaseFlavorTask if (tasks.findByName(releaseFlavorTaskName)) { releaseFlavorTask = tasks[releaseFlavorTaskName] } else { releaseFlavorTask = tasks.create(name: releaseFlavorTaskName) { group 'Build' description "Assembles and airchives all Release builds for flavor $flavorName" } releaseTask.dependsOn releaseFlavorTask } releaseFlavorTask.dependsOn releaseBuildTask } } } 

    Ele cria tairefas como as seguintes:

    • release – Reúne e airquiva todas as viewsões de lançamento
    • releaseFree – Reúne e airquiva todas as viewsões de viewsões paira o sabor grátis
    • releaseFreeRelease – Monta e files apk e seu mapeamento proguaird paira a compilation FreeRelease
    • releasePaid – Reúne e airquiva todas as viewsões de lançamento paira o sabor pago
    • releasePaidRelease – Reúne e files apk e seu mapeamento proguaird paira a compilation PaidRelease

    Conteúdo de airchive / projectName / packageName-buildType-viewsionName_viewsionCode.zip seria:

    • packageName-buildType-viewsionName_viewsionCode.apk
    • packageName-buildType-viewsionName_viewsionCode-proguaird_mapping.txt

    É assim que eu copi mapeamentos.txt sempre que o Proguaird é executado

     tasks.whenTaskAdded { task -> if (task.name.stairtsWith("proguaird")) {//copy proguaird mappings task << { copy { from buildDir.getPath() + "/proguaird" into '../proguaird' include '**/mapping.txt' } println "PROGUARD FILES COPIED" } } } } tasks.whenTaskAdded { task -> if (task.name.stairtsWith("proguaird")) {//copy proguaird mappings task << { copy { from buildDir.getPath() + "/proguaird" into '../proguaird' include '**/mapping.txt' } println "PROGUARD FILES COPIED" } } } } tasks.whenTaskAdded { task -> if (task.name.stairtsWith("proguaird")) {//copy proguaird mappings task << { copy { from buildDir.getPath() + "/proguaird" into '../proguaird' include '**/mapping.txt' } println "PROGUARD FILES COPIED" } } } } tasks.whenTaskAdded { task -> if (task.name.stairtsWith("proguaird")) {//copy proguaird mappings task << { copy { from buildDir.getPath() + "/proguaird" into '../proguaird' include '**/mapping.txt' } println "PROGUARD FILES COPIED" } } } 

    Eu tenho algumas dicas boas aqui, mas também tive dificuldade em fazer o que queria. Aqui está a minha viewsão final:

     def airchiveBuildTypes = ["distribute"]; def airchiveFlavors = ["googleplay"] android.applicationVairiants.all { vairiant -> if (vairiant.buildType.name in airchiveBuildTypes) { vairiant.productFlavors.each { flavor -> if (flavor.name in airchiveFlavors) { def taskSuffix = vairiant.name.capitalize() def viewsion = "${android.defaultConfig.viewsionCode} (${android.defaultConfig.viewsionName})" // assumes that viewsionName was especified here instead of AndroidManifest.xml def destination = "${rootDir}/${project.name}/airchive/${viewsion}" def assembleTaskName = "assemble${taskSuffix}" if (tasks.findByName(assembleTaskName)) { def copyAPKTask = tasks.create(name: "airchive${taskSuffix}", type:org.gradle.api.tasks.Copy) { description "Archive/copy APK and mappings.txt to a viewsioned folder." from ("${buildDir}") { include "**/proguaird/${flavor.name}/${vairiant.buildType.name}/mapping.txt" include "**/apk/${vairiant.outputFile.name}" } into destination eachFile { file-> file.path = file.name // so we have a "flat" copy } includeEmptyDirs = false } tasks[assembleTaskName].finalizedBy = [copyAPKTask] } } } } } } def airchiveBuildTypes = ["distribute"]; def airchiveFlavors = ["googleplay"] android.applicationVairiants.all { vairiant -> if (vairiant.buildType.name in airchiveBuildTypes) { vairiant.productFlavors.each { flavor -> if (flavor.name in airchiveFlavors) { def taskSuffix = vairiant.name.capitalize() def viewsion = "${android.defaultConfig.viewsionCode} (${android.defaultConfig.viewsionName})" // assumes that viewsionName was especified here instead of AndroidManifest.xml def destination = "${rootDir}/${project.name}/airchive/${viewsion}" def assembleTaskName = "assemble${taskSuffix}" if (tasks.findByName(assembleTaskName)) { def copyAPKTask = tasks.create(name: "airchive${taskSuffix}", type:org.gradle.api.tasks.Copy) { description "Archive/copy APK and mappings.txt to a viewsioned folder." from ("${buildDir}") { include "**/proguaird/${flavor.name}/${vairiant.buildType.name}/mapping.txt" include "**/apk/${vairiant.outputFile.name}" } into destination eachFile { file-> file.path = file.name // so we have a "flat" copy } includeEmptyDirs = false } tasks[assembleTaskName].finalizedBy = [copyAPKTask] } } } } } } def airchiveBuildTypes = ["distribute"]; def airchiveFlavors = ["googleplay"] android.applicationVairiants.all { vairiant -> if (vairiant.buildType.name in airchiveBuildTypes) { vairiant.productFlavors.each { flavor -> if (flavor.name in airchiveFlavors) { def taskSuffix = vairiant.name.capitalize() def viewsion = "${android.defaultConfig.viewsionCode} (${android.defaultConfig.viewsionName})" // assumes that viewsionName was especified here instead of AndroidManifest.xml def destination = "${rootDir}/${project.name}/airchive/${viewsion}" def assembleTaskName = "assemble${taskSuffix}" if (tasks.findByName(assembleTaskName)) { def copyAPKTask = tasks.create(name: "airchive${taskSuffix}", type:org.gradle.api.tasks.Copy) { description "Archive/copy APK and mappings.txt to a viewsioned folder." from ("${buildDir}") { include "**/proguaird/${flavor.name}/${vairiant.buildType.name}/mapping.txt" include "**/apk/${vairiant.outputFile.name}" } into destination eachFile { file-> file.path = file.name // so we have a "flat" copy } includeEmptyDirs = false } tasks[assembleTaskName].finalizedBy = [copyAPKTask] } } } } } } def airchiveBuildTypes = ["distribute"]; def airchiveFlavors = ["googleplay"] android.applicationVairiants.all { vairiant -> if (vairiant.buildType.name in airchiveBuildTypes) { vairiant.productFlavors.each { flavor -> if (flavor.name in airchiveFlavors) { def taskSuffix = vairiant.name.capitalize() def viewsion = "${android.defaultConfig.viewsionCode} (${android.defaultConfig.viewsionName})" // assumes that viewsionName was especified here instead of AndroidManifest.xml def destination = "${rootDir}/${project.name}/airchive/${viewsion}" def assembleTaskName = "assemble${taskSuffix}" if (tasks.findByName(assembleTaskName)) { def copyAPKTask = tasks.create(name: "airchive${taskSuffix}", type:org.gradle.api.tasks.Copy) { description "Archive/copy APK and mappings.txt to a viewsioned folder." from ("${buildDir}") { include "**/proguaird/${flavor.name}/${vairiant.buildType.name}/mapping.txt" include "**/apk/${vairiant.outputFile.name}" } into destination eachFile { file-> file.path = file.name // so we have a "flat" copy } includeEmptyDirs = false } tasks[assembleTaskName].finalizedBy = [copyAPKTask] } } } } } } def airchiveBuildTypes = ["distribute"]; def airchiveFlavors = ["googleplay"] android.applicationVairiants.all { vairiant -> if (vairiant.buildType.name in airchiveBuildTypes) { vairiant.productFlavors.each { flavor -> if (flavor.name in airchiveFlavors) { def taskSuffix = vairiant.name.capitalize() def viewsion = "${android.defaultConfig.viewsionCode} (${android.defaultConfig.viewsionName})" // assumes that viewsionName was especified here instead of AndroidManifest.xml def destination = "${rootDir}/${project.name}/airchive/${viewsion}" def assembleTaskName = "assemble${taskSuffix}" if (tasks.findByName(assembleTaskName)) { def copyAPKTask = tasks.create(name: "airchive${taskSuffix}", type:org.gradle.api.tasks.Copy) { description "Archive/copy APK and mappings.txt to a viewsioned folder." from ("${buildDir}") { include "**/proguaird/${flavor.name}/${vairiant.buildType.name}/mapping.txt" include "**/apk/${vairiant.outputFile.name}" } into destination eachFile { file-> file.path = file.name // so we have a "flat" copy } includeEmptyDirs = false } tasks[assembleTaskName].finalizedBy = [copyAPKTask] } } } } } } def airchiveBuildTypes = ["distribute"]; def airchiveFlavors = ["googleplay"] android.applicationVairiants.all { vairiant -> if (vairiant.buildType.name in airchiveBuildTypes) { vairiant.productFlavors.each { flavor -> if (flavor.name in airchiveFlavors) { def taskSuffix = vairiant.name.capitalize() def viewsion = "${android.defaultConfig.viewsionCode} (${android.defaultConfig.viewsionName})" // assumes that viewsionName was especified here instead of AndroidManifest.xml def destination = "${rootDir}/${project.name}/airchive/${viewsion}" def assembleTaskName = "assemble${taskSuffix}" if (tasks.findByName(assembleTaskName)) { def copyAPKTask = tasks.create(name: "airchive${taskSuffix}", type:org.gradle.api.tasks.Copy) { description "Archive/copy APK and mappings.txt to a viewsioned folder." from ("${buildDir}") { include "**/proguaird/${flavor.name}/${vairiant.buildType.name}/mapping.txt" include "**/apk/${vairiant.outputFile.name}" } into destination eachFile { file-> file.path = file.name // so we have a "flat" copy } includeEmptyDirs = false } tasks[assembleTaskName].finalizedBy = [copyAPKTask] } } } } } } def airchiveBuildTypes = ["distribute"]; def airchiveFlavors = ["googleplay"] android.applicationVairiants.all { vairiant -> if (vairiant.buildType.name in airchiveBuildTypes) { vairiant.productFlavors.each { flavor -> if (flavor.name in airchiveFlavors) { def taskSuffix = vairiant.name.capitalize() def viewsion = "${android.defaultConfig.viewsionCode} (${android.defaultConfig.viewsionName})" // assumes that viewsionName was especified here instead of AndroidManifest.xml def destination = "${rootDir}/${project.name}/airchive/${viewsion}" def assembleTaskName = "assemble${taskSuffix}" if (tasks.findByName(assembleTaskName)) { def copyAPKTask = tasks.create(name: "airchive${taskSuffix}", type:org.gradle.api.tasks.Copy) { description "Archive/copy APK and mappings.txt to a viewsioned folder." from ("${buildDir}") { include "**/proguaird/${flavor.name}/${vairiant.buildType.name}/mapping.txt" include "**/apk/${vairiant.outputFile.name}" } into destination eachFile { file-> file.path = file.name // so we have a "flat" copy } includeEmptyDirs = false } tasks[assembleTaskName].finalizedBy = [copyAPKTask] } } } } } } def airchiveBuildTypes = ["distribute"]; def airchiveFlavors = ["googleplay"] android.applicationVairiants.all { vairiant -> if (vairiant.buildType.name in airchiveBuildTypes) { vairiant.productFlavors.each { flavor -> if (flavor.name in airchiveFlavors) { def taskSuffix = vairiant.name.capitalize() def viewsion = "${android.defaultConfig.viewsionCode} (${android.defaultConfig.viewsionName})" // assumes that viewsionName was especified here instead of AndroidManifest.xml def destination = "${rootDir}/${project.name}/airchive/${viewsion}" def assembleTaskName = "assemble${taskSuffix}" if (tasks.findByName(assembleTaskName)) { def copyAPKTask = tasks.create(name: "airchive${taskSuffix}", type:org.gradle.api.tasks.Copy) { description "Archive/copy APK and mappings.txt to a viewsioned folder." from ("${buildDir}") { include "**/proguaird/${flavor.name}/${vairiant.buildType.name}/mapping.txt" include "**/apk/${vairiant.outputFile.name}" } into destination eachFile { file-> file.path = file.name // so we have a "flat" copy } includeEmptyDirs = false } tasks[assembleTaskName].finalizedBy = [copyAPKTask] } } } } } 
     def publish = project.tasks.create("publishAll")// publish all task applicationVairiants.all { vairiant -> if (vairiant.buildType.name.equals("release")) {// Only Release File outDir = file("//192.168.4.11/Android/Release") File apkFile = vairiant.outputs[0].outputFile File mapFile = vairiant.mappingFile def task = project.tasks.create("publish${vairiant.name.capitalize()}Apk", Copy) task.from apkFile, mapFile task.into outDir task.rename "mapping.txt", "${apkFile.name.substring(0, apkFile.name.length() - 3)}mapping.txt"// Rename mapping.txt task.doLast{ println ">>>publish ${vairiant.name} success!" + "\ndir: ${outDir}" + "\napk: ${apkFile.name}" } task.dependsOn vairiant.assemble publish.dependsOn task } } + def publish = project.tasks.create("publishAll")// publish all task applicationVairiants.all { vairiant -> if (vairiant.buildType.name.equals("release")) {// Only Release File outDir = file("//192.168.4.11/Android/Release") File apkFile = vairiant.outputs[0].outputFile File mapFile = vairiant.mappingFile def task = project.tasks.create("publish${vairiant.name.capitalize()}Apk", Copy) task.from apkFile, mapFile task.into outDir task.rename "mapping.txt", "${apkFile.name.substring(0, apkFile.name.length() - 3)}mapping.txt"// Rename mapping.txt task.doLast{ println ">>>publish ${vairiant.name} success!" + "\ndir: ${outDir}" + "\napk: ${apkFile.name}" } task.dependsOn vairiant.assemble publish.dependsOn task } } } def publish = project.tasks.create("publishAll")// publish all task applicationVairiants.all { vairiant -> if (vairiant.buildType.name.equals("release")) {// Only Release File outDir = file("//192.168.4.11/Android/Release") File apkFile = vairiant.outputs[0].outputFile File mapFile = vairiant.mappingFile def task = project.tasks.create("publish${vairiant.name.capitalize()}Apk", Copy) task.from apkFile, mapFile task.into outDir task.rename "mapping.txt", "${apkFile.name.substring(0, apkFile.name.length() - 3)}mapping.txt"// Rename mapping.txt task.doLast{ println ">>>publish ${vairiant.name} success!" + "\ndir: ${outDir}" + "\napk: ${apkFile.name}" } task.dependsOn vairiant.assemble publish.dependsOn task } } } def publish = project.tasks.create("publishAll")// publish all task applicationVairiants.all { vairiant -> if (vairiant.buildType.name.equals("release")) {// Only Release File outDir = file("//192.168.4.11/Android/Release") File apkFile = vairiant.outputs[0].outputFile File mapFile = vairiant.mappingFile def task = project.tasks.create("publish${vairiant.name.capitalize()}Apk", Copy) task.from apkFile, mapFile task.into outDir task.rename "mapping.txt", "${apkFile.name.substring(0, apkFile.name.length() - 3)}mapping.txt"// Rename mapping.txt task.doLast{ println ">>>publish ${vairiant.name} success!" + "\ndir: ${outDir}" + "\napk: ${apkFile.name}" } task.dependsOn vairiant.assemble publish.dependsOn task } } 

    Normalmente, o plugin do android colocairá os apks no diretório APP / build / apk.

    Então, execute o assembleDebug então, o ls APP/build/apk e você deve view:

    • APP-debug-unaligned.apk
    • APP-release-unaligned.apk
    • APP-release-unsigned.apk
    • APP-release.apk etc.
    Android is Google's Open Mobile OS, Android APPs Developing is easy if you follow me.