9

Is there a way to auto-copy the Proguard mapping files to the (selected) target APK directory in Android Studio, every time a live build finishes?

Frank
  • 12,010
  • 8
  • 61
  • 78

1 Answers1

9

This solution will copy the generated mapping.txt to {targetDir}/mapping/ where {targetDir} is the target APK dir. (This solution will also add a date in the txt filename.)

Edit the build.gradle of your app module, update the android task:

android {

   ... // your usual stuff

   applicationVariants.all { variant ->
      variant.outputs.each { output ->
          if (variant.getBuildType().isMinifyEnabled()) {
              variant.assemble.doLast{
                  copy {
                      from variant.mappingFile
                      into output.outputFile.parent + "/mapping"
                      rename { String fileName ->
                          "mapping-${variant.name}-${new Date().format('yyyy_MM_dd')}.txt"
                      }
                  }
              }
          }
       }
    }
}
Frank
  • 12,010
  • 8
  • 61
  • 78