设置属性

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. tomcat server.xml结构

    所有xml文件使用的文件头 <?xml version='1.0' encoding='utf-8'?> 2 <Server port="8005" shutdo ...

  2. 树莓派3B+(三)

    上一篇中,我们配置好了基本的raspbain系统,接下来我们可以用xrdp或者vnc在Windows上远程连接树莓派. 一.安装xrdp xrdp和vnc是两种常见的远程桌面协议,可以进行可视化界面远 ...

  3. 数据分析三剑客之Matplotlib

    Matplotlib绘图和可视化 简介 我的前面两篇文章介绍了 Nimpy ,Pandas .今天来介绍一下Matplotlib. 简单来说,Matplotlib 是 Python 的一个绘图库.它包 ...

  4. python学习日记(面向对象——组合)

    组合指的是,在一个类中以另外一个类的对象作为数据属性,称为类的组合 圆环是由两个圆组成的,圆环的面积是外面圆的面积减去内部圆的面积.圆环的周长是内部圆的周长加上外部圆的周长.这个时候,我们就首先实现一 ...

  5. fast-ai lesson1 错误处理(CNN创建)

    报错信息: name 'ConvLearner' is not defined 在最新的fast ai包中,ConvLearner已经被create_cnn取代,所以替换为下列语句就好了: learn ...

  6. php 两个数组,若键相同,则值合并

    <?php $arr1 = array('9' => '4.08', '10' => '0.10', '11' => '4.08', '12' => '0.01'); $ ...

  7. noi.ac309 Mas的童年

    题目链接 题面 题目描述 \(Mas\)完成了一天的工作,走在回家的路上,看着路边的景色,他想起来自己的童年. 许许多多的记忆交错,丝丝缕缕的牵扯着\(Mas\). 在回忆的深处,\(Mas\)想起来 ...

  8. 利用java内部静态类实现懒汉式单例

    /** * @Description: 利用键值模式控制service * @Author: zhanglifeng * @Date: 2019年 04月 28日 14:41 **/ public c ...

  9. mysql 严格模式 Strict Mode说明(text 字段不能加默认或者 不能加null值得修改方法)

    mysql 严格模式 Strict Mode说明 1.开启与关闭Strict Mode方法找到mysql安装目录下的my.cnf(windows系统则是my.ini)文件 在sql_mode中加入ST ...

  10. 2018-2019-2 网络对抗技术 20165232 Exp2 后门原理与实践

    2018-2019-2 网络对抗技术 20165232 Exp2 后门原理与实践 1. 后门原理与实践实验说明及预备知识 一.实验说明 任务一:使用netcat获取主机操作Shell,cron启动 ( ...