Reference build.gradle versionName attribute in xml layout

前端 未结 4 1306
野性不改
野性不改 2020-12-31 00:05

I\'d like to have a layout file which references the versionName attribute in my gradle file:

...
defaultConfig {
    applicationId \"se.test.my         


        
4条回答
  •  心在旅途
    2020-12-31 00:32

    I use variables in my projects for versionName and versionCode

    for example, in the app's build.gradle:

    final VERSION_NAME = '2.2.3'
    final VERSION_CODE = 15
    
    android {
        defaultConfig {
            resValue "string", "version_code", VERSION_NAME + " (build " + VERSION_CODE + ")"
            versionCode VERSION_CODE
            versionName VERSION_NAME
            ...
        }
    ...
    }
    

    Android Studio automatically generates an untranslatable string resource:

    2.2.3 (build 15)
    

    which I can use in xml:

    
    

    hope it will be useful

提交回复
热议问题