Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 552
Frank Avatar asked Jul 13 '15 15:07

Frank


People also ask

What is minify Android?

minify is an Android tool that will decrease the size of your application when you go to build it. It's extremely useful as it means smaller apk files! It detects any code or libraries that aren't being used and ignores them from your final apk.

What is R8 Android?

What is R8? R8 is an app shrinking tool that is used to reduce the size of your application. This tool present in Android Studio works with the rules of Proguard. R8 will convert your app's code into optimized Dalvik code.

What is ProGuard mapping?

A mapping file contains the original names and the obfuscated names of classes, fields, and methods. ProGuard can write out such a file while obfuscating an application or a library, with the option -printmapping . ReTrace requires the mapping file to restore obfuscated stack traces to more readable versions.


1 Answers

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"
                      }
                  }
              }
          }
       }
    }
}
like image 62
Frank Avatar answered Sep 24 '22 20:09

Frank