设置属性

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. 收藏了8年的PHP优秀资源,都给你整理好了

    https://segmentfault.com/a/1190000018071558 最后更新于 2019.02.12 以下是我整理好的 PHP 资源,各位看官拿去用,不用再自己找了. 每周在 Gi ...

  2. Luogu4363 [九省联考2018]一双木棋chess 【状压DP】【进制转换】

    题目分析: 首先跑个暴力,求一下有多少种状态,发现只有18xxxx种,然后每个状态有10的转移,所以复杂度大约是200w,然后利用进制转换的技巧求一下每个状态的十进制码就行了. 代码: #includ ...

  3. SaltStack说明文档

    SaltStack说明文档 master安装 # 安装 yum -y install salt-master salt-minion salt-ssh # 启动 systemctl start sal ...

  4. CF1152 F. Neko Rules the Catniverse (dp)

    题意 一条长为 \(n\) 的数轴,可以从任意整点 \(\in [1, n]\) 出发,假设当前在 \(x\) ,下一步能到达的点 \(y\) 需要满足,\(y\) 从未到过,且 \(1 \le y ...

  5. 记录一次有意思的XSS过滤绕过2

    前几天在漏洞挖掘中遇到个xss,感觉绕过过程蛮有意思的,写篇文章记录下. 接下里是我对这个xss详细的分析和绕过 存在问题站点http://******/index/appInfo?appId=784 ...

  6. LeetCode--11_Container_With_Most_Water

    题目链接:点击这里 首先我们不考虑高度的话 最大的面积应该是l r 应该是最边上的值 ,我们要取最大 所以 要维护从左到右单调增,从右到左 单调增 这样我们才能保证 面积增加 public stati ...

  7. (转)学习HTML5 Canvas这一篇文章就够了

    作者:做人要厚道2013 原文:https://blog.csdn.net/u012468376/article/details/73350998

  8. cookie session token

    HTTP    HTTP是无状态(stateless)的网络协议.HTTP协议自身不对请求和响应之间的通信状态进行保存.也就是说HTTP协议对于发送过的请求或响应都不做持久化处理. 为了实现保持状态功 ...

  9. window.location.href 传参中文乱码问题!!!

    不是所有地方都会用Ajax  当你使用window.location.href 来传中文参数的时候 如何避免乱码问题 js 是这样写的    下面代码中  方式 封装编码  参数 username  ...

  10. 04-oracle中的视图

    1.创建视图 介绍: 视图(View)通过SELECT查询语句定义,它是从一个或多个表(或视图)导出的,用来导出视图的表称为基表(Base Table),导出的视图称为虚表.在数据库中,只存储视图的定 ...