设置属性

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中调用

build.gradle中设置buildConfigField("int", "TARGET_SDK_VERSION", "${TARGET_SDK_VERSION}")
依次为:参数类型,参数名,参数值

int targetSDKVersion = BuildConfig.TARGET_SDK_VERSION;

用ResourceBundle获取

ResourceBundle bundle = ResourceBundle.getBundle("gradle");//gradle为properties的文件名
String result = bundle.getString("test_key");//test_key是properties文件中的key值

用Properties 获取

Properties properties = new Properties();
InputStream is = this.getClassLoader().getResourceAsStream("gradle.properties");//path
properties.load(is);
String result= properties.getProperty("test_key");//test_key是properties文件中的key值

XML中调用

build.gradle中设置resValue("string", "VERSION_NAME", "${VERSION_NAME}")
依次为:参数类型,参数名,参数值

<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/VERSION_NAME"/>

gradle.properties使用的更多相关文章

  1. 配置gradle.properties

    在一些项目中会分拆app 和 lib , 这时候引用support的时候,一旦更改版本会出现需要同步更改两个地方的问题.这种情况,可以通过配置gradle.properties实现替换. 在项目编译过 ...

  2. gradle.properties

    gradle.properties # If this is set, then multiple APK files will be generated: One per native platfo ...

  3. build.gradle & gradle.properties

    一.build.gradle buildscript { ext { springBootVersion = '1.5.9.RELEASE' } repositories { maven { cred ...

  4. android gradle.properties

    gradle.properties 里面配置的东西,在gradle 文件里面可以直接引用. 例如: 在你工程根目录的gradle.properties 文件里面 可以这样配置: ## Project- ...

  5. AndroidStudio 中 gradle.properties 的中文值获取乱码问题

    0x01 现象 在gradle.properties中定义了全局变量,然后从 build.gradle 中设置 app_name: resValue "string", " ...

  6. Set "$USE_DEPRECATED_NDK=true" in gradle.properties to continue using the current NDK integration. 解决办法

    1.将 jni 文件夹名改为 cpp: 2.添加 CMakeLists.txt; 3.修改 build.gradle; externalNativeBuild { cmake { path " ...

  7. Gradle配置APK自动签名完整流程

    转载请注明出处:http://www.cnblogs.com/LT5505/p/6256683.html 一.生成签名 1.命令行生成签名,输入命令keytool -genkey -v -keysto ...

  8. [转]加速Android Studio/Gradle构建

    加速Android Studio/Gradle构建 android android studio gradle   已经使用Android Studio进行开发超过一年,随着项目的增大,依赖库的增多, ...

  9. gradle学习笔记

    一直想着花时间学习下gradle,今天有空.入门一下.参考:极客学院gradle使用指南,官方文档:gradle-2.12/docs/userguide/installation.html,以及百度阅 ...

随机推荐

  1. jstl的foreach标签

    jsp支持丰富的jstl标签语言(需要jar包支持),其中list循环(迭代)用的是<c:forEach></c:forEach>标签. 这个标签的作用就是迭代输出标签内部的内 ...

  2. 正则去除字符串中的html标签,但不去除<br>标签

    一.去除html标签 filterHTMLTag(msg) { var msg = msg.replace(/<\/?[^>]*>/g, ''); //去除HTML Tag msg ...

  3. 在vue 里使用腾讯ditu

    https://www.cnblogs.com/mrer/p/7144705.html

  4. (六)QDialog,QMessageBox,QFileDialog,QColorDialog颜色,QFontDialog字体

    QDialog 对话框: 1.模态对话框: QDialog dlg(this); // 显示模态对话框 exec ,后面的不可操作 dlg.exec(); // 阻塞 2.非模态对话框: QDialo ...

  5. (双指针) leetcode 485. Max Consecutive Ones

    Given a binary array, find the maximum number of consecutive 1s in this array. Example 1: Input: [1, ...

  6. 【linux】常用命令集锦&持续更新...

    滴:转载引用请注明哦[握爪]:https://www.cnblogs.com/zyrb/p/9709013.html  对深度学习训练及日常work中的常用linux命令进行整理. [一]screen ...

  7. (九) 主机增加打印(串口+ssh)

    目录 主机增加打印(串口+ssh) ssh 串口打印 title: 主机增加打印(串口+ssh) date: 2019/4/23 20:10:00 toc: true --- 主机增加打印(串口+ss ...

  8. 【Unity游戏开发】记一次解决 LuaFunction has been disposed 的bug的过程

    一.引子 RT,本篇博客记录的是马三的一次解决 LuaFunction has been disposed 的bug的全过程,事情还要从马三的自研框架 ColaFrameWork 说起.最近,马三在业 ...

  9. Python高级笔记(二) -- 深拷贝和浅拷贝

    1. 深拷贝 1.1 类型1 注意: d没有改变, 因为d所拷贝的数据没有改变, 而是c往后添加数据. 1.2 类型2: 元组 如果copy.copy拷贝的是元组是深拷贝! 不会进行浅拷贝, 仅仅是指 ...

  10. Python——爬取人口迁徙数据(以腾讯迁徙为例)

    说明: 1.迁徙量是腾讯修改后的数值,无法确认真实性. 2.代码运行期间,腾讯迁徙未设置IP屏蔽和浏览器检测,因此下段代码仅能保证发布近期有效. 3.代码功能:爬取指定一天的四十(此四十是根据自己的城 ...