Android Studio 如何获取gradle.properties文件中key值对应的value

本文介绍如何在build.gradle中设置buildTypes参数,并通过Java代码从gradle.properties文件中读取配置值。具体展示了如何使用resValue方法将属性值注入到资源文件,以及如何在代码中获取这些值。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1、build.gradle文件中添加

buildTypes{
	release{
		//params1 : string 
		//params2 : buildType R文件引用
		//params3 : KEY  gradle.properties文件中的Key
		resValue(“string” , "buildType" , "${KEY}")
	}
}

2 获取gradle.properties中key值java代码

   String result = getResources().getString(R.string.buildType);
   
   result 即gradle.properties文件中的Key对应的Value
Caused by: java.lang.RuntimeException: No value with key 'distributionUrl' specified in wrapper properties file '/root/workspace/usb-serial-for-android/gradle/wrapper/gradle-wrapper.properties'. at org.gradle.wrapper.WrapperExecutor.reportMissingProperty(WrapperExecutor.java:135) at org.gradle.wrapper.WrapperExecutor.readDistroUrl(WrapperExecutor.java:78) at org.gradle.wrapper.WrapperExecutor.prepareDistributionUri(WrapperExecutor.java:67) at org.gradle.wrapper.WrapperExecutor.<init>(WrapperExecutor.java:54) ... 2 more [root@localhost usb-serial-for-android]# ./gradlew :usbSerialExamples:assembleDebug --no-build-cache Exception in thread "main" java.lang.RuntimeException: Could not load wrapper properties from '/root/workspace/usb-serial-for-android/gradle/wrapper/gradle-wrapper.properties'. at org.gradle.wrapper.WrapperExecutor.<init>(WrapperExecutor.java:61) at org.gradle.wrapper.WrapperExecutor.forWrapperPropertiesFile(WrapperExecutor.java:45) at org.gradle.wrapper.GradleWrapperMain.main(GradleWrapperMain.java:62) Caused by: java.lang.RuntimeException: No value with key 'distributionUrl' specified in wrapper properties file '/root/workspace/usb-serial-for-android/gradle/wrapper/gradle-wrapper.properties'. at org.gradle.wrapper.WrapperExecutor.reportMissingProperty(WrapperExecutor.java:135) at org.gradle.wrapper.WrapperExecutor.readDistroUrl(WrapperExecutor.java:78) at org.gradle.wrapper.WrapperExecutor.prepareDistributionUri(WrapperExecutor.java:67) at org.gradle.wrapper.WrapperExecutor.<init>(WrapperExecutor.java:54) 因为我在gradle-wrapper.properties 文件中添加了-distributionUrl=file\:///root/gradle-7.4.2-bin.zip +distributionUrl=file\:///root/gradle-7.5.1-bin.zip 问题是什么怎么解决?
最新发布
05-14
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值