Filter strings.xml with gradle-android-plugin?

前端 未结 2 1058
佛祖请我去吃肉
佛祖请我去吃肉 2021-02-04 22:07

How would I filter my res/values/strings.xml file?

Something like:


    ${version}
..         


        
相关标签:
2条回答
  • 2021-02-04 22:45

    You can use ReplaceTokens with filter method if you have your token in the following format: @token@

    So if your file looks like this:

    <resources>
       <string name="version_name">@version@</string>
    ...
    

    then you can do:

    import org.apache.tools.ant.filters.ReplaceTokens
    
    def version = '1.0'
    
    processResources{
     filter(ReplaceTokens, tokens: ['version': version])
    }
    

    You can do this for any task that supports filter methods (which looks like any task that extends AbstractCopyTask).

    I am not sure how you do it if you want to keep the ${token} format. You might be able to use a different filter or set the filter on ReplaceTokens. Looks like in ant you could set the begin and end tokens.

    0 讨论(0)
  • 2021-02-04 23:07

    With groovy closure, if you prefer without ant external:

    filter {
        line -> line.replace('${version}', version)
    }
    
    0 讨论(0)
提交回复
热议问题