Frank
Frank

Reputation: 12298

Android auto copy Proguard mapping Android Studio

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?

Upvotes: 9

Views: 1076

Answers (1)

Frank
Frank

Reputation: 12298

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"
                      }
                  }
              }
          }
       }
    }
}

Upvotes: 9

Related Questions