How to change the proguard mapping file name in gradle for Android project

后端 未结 12 1676
灰色年华
灰色年华 2020-11-30 08:48

I have android project based on gradle and I want to change mapping.txt file name after it\'s generated for my build. How can it be done?

upd

How it can be d

12条回答
  •  北海茫月
    2020-11-30 09:14

    Use this command in your proguard-rules.pro file:

    -printmapping path/to/your/file/file_name.txt
    

    the file will be written in part {root}/path/to/your/file with file_name.txt name.

    If you want to have different setting for different flavors you can define many proguard-rules for them

    I found one more idea but I am not sure that it is right way.

    You can define your path in flavors:

    productFlavors {
        test1 {
            applicationId "com.android.application.test"
            project.ext."${name}Path" = 'path/one/mapp.txt'
        }
        test2 {
            project.ext."${name}Path" = 'path/two/mapp.txt'
        }
    }
    

    And as next you can define new task before $asseble{variant.name.capitalize()} task as is shown below:

    android.applicationVariants.all { variant ->
        def envFlavor = variant.productFlavors.get(0).name
    
        def modifyProguardPath = tasks.create(name: "modifyProguardFor${variant.name.capitalize()}", type: Exec) {
            def pathToMap = project."${envFlavor}Test1"
            doFirst {
                println "==== Edit start: $pathToMap ===="
            }
            doLast {
                println "==== Edit end: $pathToMap ===="
            }
            executable "${rootDir}/utils/test.bash"
            args pathToMap
        }
    
        project.tasks["assemble${variant.name.capitalize()}"].dependsOn(modifyProguardPath);
    }
    

    and in script ${root}/utils/test.bash - you can modify proguard-rules.pro.

    But I think that exist better solution.

提交回复
热议问题