gradle.properties使用

設(shè)置屬性

COMPILE_SDK_VERSION = 26
BUILD_TOOLS_VERSION = 26.0.0
MIN_SDK_VERSION = 19
TARGET_SDK_VERSION = 26
VERSION_CODE = 1
VERSION_NAME = 1.0

build.gradle中使用

android {
    compileSdkVersion COMPILE_SDK_VERSION as int
    buildToolsVersion BUILD_TOOLS_VERSION
    defaultConfig {
        applicationId "com.xtao.simpledemo"
        minSdkVersion MIN_SDK_VERSION as int
        targetSdkVersion TARGET_SDK_VERSION as int
        versionCode VERSION_CODE as int
        versionName VERSION_NAME
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            buildConfigField("int", "TARGET_SDK_VERSION", "${TARGET_SDK_VERSION}")
        }
        debug {
            buildConfigField("int", "TARGET_SDK_VERSION", "${TARGET_SDK_VERSION}")
            resValue("string", "VERSION_NAME", "${VERSION_NAME}")
        }
    }
}

Java中調(diào)用

build.gradle中設(shè)置buildConfigField("int", "TARGET_SDK_VERSION", "${TARGET_SDK_VERSION}")
依次為:參數(shù)類(lèi)型,參數(shù)名,參數(shù)值

int targetSDKVersion = BuildConfig.TARGET_SDK_VERSION;

XML中調(diào)用

build.gradle中設(shè)置resValue("string", "VERSION_NAME", "${VERSION_NAME}")
依次為:參數(shù)類(lèi)型,參數(shù)名,參數(shù)值

<TextView
    android:id="@+id/textView"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/VERSION_NAME"/>
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • Spring Boot 參考指南 介紹 轉(zhuǎn)載自:https://www.gitbook.com/book/qbgb...
    毛宇鵬閱讀 47,253評(píng)論 6 342
  • Spring Cloud為開(kāi)發(fā)人員提供了快速構(gòu)建分布式系統(tǒng)中一些常見(jiàn)模式的工具(例如配置管理,服務(wù)發(fā)現(xiàn),斷路器,智...
    卡卡羅2017閱讀 136,502評(píng)論 19 139
  • 轉(zhuǎn)載注明出處:http://www.itdecent.cn/p/5255b100930e 0. 前言 完全由個(gè)人翻...
    王三的貓阿德閱讀 2,730評(píng)論 0 4
  • 1.介紹 如果你正在查閱build.gradle文件的所有可選項(xiàng),請(qǐng)點(diǎn)擊這里進(jìn)行查閱:DSL參考 1.1新構(gòu)建系統(tǒng)...
    Chuckiefan閱讀 12,355評(píng)論 8 72
  • 害怕這樣孤獨(dú)的夜晚,感覺(jué)整個(gè)人被黑夜牢牢包圍著,仿佛所有人都忘記了我的存在,這樣的夜晚,總會(huì)讓我想太多,然后悄悄流...
    半明媚半憂傷_5a4b閱讀 213評(píng)論 0 0

友情鏈接更多精彩內(nèi)容