[英]I am getting an error in my build.gradle file
My build.gradle
file looks like this:我的
build.gradle
文件如下所示:
apply plugin: 'com.android.application'
android {
compileSdkVersion 29
buildToolsVersion "29.0.2"
defaultConfig {
applicationId "com.tejas.otppassword"
minSdkVersion 19
targetSdkVersion 29
versionCode 1
versionName "1.0"
each{ type ->
type.buildConfigField 'String', 'API', SMS_API_KEY
}
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility = 1.8
targetCompatibility = 1.8
}
}
dependencies {
implementation 'com.squareup.okhttp3:okhttp:3.10.0'
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.2.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
implementation 'com.android.volley:volley:1.1.0'
}
The error in my Logcat looks like this:我的 Logcat 中的错误如下所示:
ERROR: Could not get unknown property 'SMS_API_KEY' for DefaultConfig_Decorated{name=main, dimension=null, minSdkVersion=DefaultApiVersion{mApiLevel=19, mCodename='null'}, targetSdkVersion=DefaultApiVersion{mApiLevel=29, mCodename='null'}, renderscriptTargetApi=null, renderscriptSupportModeEnabled=null, renderscriptSupportModeBlasEnabled=null, renderscriptNdkModeEnabled=null, versionCode=1, versionName=1.0, applicationId=com.tejas.otppassword, testApplicationId=null, testInstrumentationRunner=null, testInstrumentationRunnerArguments={}, testHandleProfiling=null, testFunctionalTest=null, signingConfig=null, resConfig=null, mBuildConfigFields={}, mResValues={}, mProguardFiles=[], mConsumerProguardFiles=[], mManifestPlaceholders={}, mWearAppUnbundled=null} of type com.android.build.gradle.internal.dsl.DefaultConfig.
Open File
I tried some other stuff regarding declaring the API_KEY
which is declared as a constant
in a Constant
class.我尝试了一些关于声明
API_KEY
的其他内容,该 API_KEY 在Constant
class 中声明为constant
。 I even tried to put double quote along with single but it didn't help at all.我什至尝试将双引号与单引号一起使用,但它根本没有帮助。
Use this:用这个:
buildConfigField "String", "API", "\"YOUR_SMS_API_KEY\""
buildConfigField("String", "BUILD_TIME", "\"${minutesSinceEpoch}\"")
Above line is from Android Official Documentation for Gradle Tips .以上行来自Gradle Tips 的 Android 官方文档。
You have to update your build.gradle
from:您必须从以下位置更新您的
build.gradle
:
each{ type ->
type.buildConfigField 'String', 'API', SMS_API_KEY
}
to:至:
each{ type ->
type.buildConfigField 'String', 'API', "\"SMS_API_KEY\""
}
Hope that works to you.希望对你有用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.