android - 我的 build.gradle 文件出现错误
问题描述
我的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'
}
我的 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
我尝试了其他一些关于在类中声明API_KEY
哪个被声明为 a的东西。我什至尝试将双引号与单引号一起使用,但它根本没有帮助。constant
Constant
解决方案
用这个:
buildConfigField "String", "API", "\"YOUR_SMS_API_KEY\""
推荐阅读
- sql-server - SQL 表中没有索引(既不是集群也不是非集群)
- api - Instagram API / Flickity 轮播
- bash - 无法对包含空格的环境变量中的路径执行 bash 命令
- java - 两台设备之间的离线 Sqlite 同步
- java - JavaFX | javafx.fxml.LoadException:缺少资源键
- regex - grep 与正则表达式匹配以三个小写字母开头的行
- python - 我怎样才能调用一个类并在这个类之外使用一个文件(.xlsx)?
- python - 为什么 TKinter 仅限于特定分辨率?
- python - python / networkx有向图中的单独边箭头
- javascript - 如何使用 Moment javascript 将日期 22/04/2020 转换为 Epoch 时间戳