错误:Gradle 同步失败:无法获取 DefaultConfig_Decolated 的未知属性“API_KEY”

Apo*_*lli 3 java android gradle android-studio build.gradle

错误:无法获取 DefaultConfig_Decolated{name=main、dimension=null、minSdkVersion=null、targetSdkVersion=null、renderscriptTargetApi=null、renderscriptSupportModeEnabled=null、renderscriptSupportModeBlasEnabled=null、renderscriptNdkModeEnabled=null、versionCode=null、versionName 的未知属性“API_KEY” =null、applicationId=null、testApplicationId=null、testInstrumentationRunner=null、testInstrumentationRunnerArguments={}、testHandleProfiling=null、testFunctionalTest=null、signingConfig=null、resConfig=null、mBuildConfigFields={}、mResValues={}、mProguardFiles=[] 、mConsumerProguardFiles=[]、mManifestPlaceholders={}、mWearAppUnbundled=null},类型为 com.android.build.gradle.internal.dsl.DefaultConfig。应用插件:'com.android.application'

android {
    compileSdkVersion 27
    buildToolsVersion '27.0.2'
    defaultConfig {
        buildConfigField("String", "API_KEY", API_KEY)        //error here
        buildConfigField("String", "ER_API_KEY", ER_API_KEY)
        applicationId "com.gpads.gautham.imagetotextanalysis"
        minSdkVersion 15
        targetSdkVersion 27
        versionCode 2
        versionName "2.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    // ... other values
}
Run Code Online (Sandbox Code Playgroud)

小智 6

将此 buildConfigField("String", "API_KEY", API_KEY) 更改为此

    buildConfigField "String", "API_KEY", "\" API_KEY\"" 
Run Code Online (Sandbox Code Playgroud)