您的当前位置:首页正文

gradle.properties使用

2021-01-20 来源:意榕旅游网
gradle.properties使⽤

设置属性

COMPILE_SDK_VERSION = 26BUILD_TOOLS_VERSION = 26.0.0MIN_SDK_VERSION = 19

TARGET_SDK_VERSION = 26VERSION_CODE = 1VERSION_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\ }

debug {

buildConfigField(\"int\ resValue(\"string\ } }}

Java中调⽤

build.gradle中设置buildConfigField(\"int\依次为:参数类型,参数名,参数值

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\");//pathproperties.load(is);

String result= properties.getProperty(\"test_key\");//test_key是properties⽂件中的key值

XML中调⽤

build.gradle中设置resValue(\"string\依次为:参数类型,参数名,参数值

android:id=\"@+id/textView\"

android:layout_width=\"wrap_content\" android:layout_height=\"wrap_content\"

android:text=\"@string/VERSION_NAME\"/>

因篇幅问题不能全部显示,请点此查看更多更全内容