gradle.properties使用
设置属性
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使用的更多相关文章
- 配置gradle.properties
在一些项目中会分拆app 和 lib , 这时候引用support的时候,一旦更改版本会出现需要同步更改两个地方的问题.这种情况,可以通过配置gradle.properties实现替换. 在项目编译过 ...
- gradle.properties
gradle.properties # If this is set, then multiple APK files will be generated: One per native platfo ...
- build.gradle & gradle.properties
一.build.gradle buildscript { ext { springBootVersion = '1.5.9.RELEASE' } repositories { maven { cred ...
- android gradle.properties
gradle.properties 里面配置的东西,在gradle 文件里面可以直接引用. 例如: 在你工程根目录的gradle.properties 文件里面 可以这样配置: ## Project- ...
- AndroidStudio 中 gradle.properties 的中文值获取乱码问题
0x01 现象 在gradle.properties中定义了全局变量,然后从 build.gradle 中设置 app_name: resValue "string", " ...
- 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 " ...
- Gradle配置APK自动签名完整流程
转载请注明出处:http://www.cnblogs.com/LT5505/p/6256683.html 一.生成签名 1.命令行生成签名,输入命令keytool -genkey -v -keysto ...
- [转]加速Android Studio/Gradle构建
加速Android Studio/Gradle构建 android android studio gradle 已经使用Android Studio进行开发超过一年,随着项目的增大,依赖库的增多, ...
- gradle学习笔记
一直想着花时间学习下gradle,今天有空.入门一下.参考:极客学院gradle使用指南,官方文档:gradle-2.12/docs/userguide/installation.html,以及百度阅 ...
随机推荐
- vue.js实战——props单向数据流
Vue2.x通过props传递数据是单向的了,也就是父组件数据变化时会传递给子组件,但是反过来不行. 业务中会经常遇到两种需要改变prop的情况, 一种是父组件传递初始值进来,子组件将它作为初始值保存 ...
- 【很好的分享】zookeeper系列
http://blog.csdn.net/tswisdom/article/details/41522069
- StringBuilder的常用方法
转自:https://www.cnblogs.com/jack-Leo/p/6684447.html 在程序开发过程中,我们常常碰到字符串连接的情况,方便和直接的方式是通过"+"符 ...
- JDK源代码学习-基础类
一.概述 1.Java,是一套语言规范,例如规定了变量如何定义.控制语句如何写等,提供基本的语法规范.JDK是java自带的一套调用组件,是对基本java语法规范的进一步封装,jdk中都是使用java ...
- Django相关问题
遇到models模型变动后无法用migrations生成改动后的表通过以下几个方面实现 1 python manage.py makemigrations yourapp(你改变的app) 2 p ...
- vue+weui+FormData+XMLHttpRequest 实现图片上传功能
首先是样式:https://weui.io/#uploader 在weui示例中可以看到是用以下方法进行选择图片 <input id="uploaderInput" clas ...
- 镜像站nginx
server { listen 80 default_server; charset utf-8; server_name monitor.autoai.com; access_log /srv/lo ...
- es定期删除数据
es定期删除数据 1.定期删除索引 使用sentinl报警后,会产生大量如下索引,虽然不占空间,但时间久了也不好,故写个脚本定期删除 脚本如下: 1 #!/bin/bash 2 #只保留5天内的日志索 ...
- C#利用 HttpWebRequest 类发送post请求,出现“套接字(协议/网络地址/端口)只允许使用一次”问题
声明:问题虽然已经被解决,但是并没有明白具体原理,欢迎大佬补充. 最近网站出现一个问题,在C#里面使用 HttpWebRequest 类去发送post请求,偶尔 会出现 “套接字(协议/网络地址/端 ...
- CTF--web 攻防世界web题 get_post
攻防世界web题 get_post https://adworld.xctf.org.cn/task/answer?type=web&number=3&grade=0&id=5 ...